8 ms·
The Art of Command Line
- chrisweekly 4y agoPlease, can anyone provide guidance for making Win10 CLI UX tolerable? After more than 2 decades on macOS, very comfortable w/ customized zsh in iTerm, I'm now unavoidably working in Windows and hating it. Sad to discover my vague perception of Windows as a 2nd-class citizen (or 3rd-world country) is all too accurate. Running git-bash in Terminal, surfacing any meaningful git status in my $PS1 incurs multisecond latency. Surely there's a better way. Right?
- jon_adler 4y agoI prefer macOS however my work machine is Win10. To improve matters, I use Cmder for my terminal with WSL2/Ubuntu. It isn’t perfect however it isn’t awful either.
- chrisweekly 4y agoThanks for your reply.
- sillyapple 4y agoFor a good PowerShell experience I use https://starship.rs/ https://starship.rs/ which includes git info. I use the new windows terminal with the font/colors/etc set just so. For a package manager I like using https://scoop.sh/ https://scoop.sh/ and for anything missing there chocolatey usually has it. Good luck, there's more good stuff out there but it's hard to find.
- chrisweekly 4y agoCool, thanks. I might give starship a try.
- asicsp 4y agoPrevious significant discussions: * https://news.ycombinator.com/item?id=19988548 https://news.ycombinator.com/item?id=19988548 (597 points | May 23, 2019 | 169 comments) * https://news.ycombinator.com/item?id=9720813 https://news.ycombinator.com/item?id=9720813 (466 points | June 15, 2015 | 133 comments)
- euroderf 4y agoFWIW.. I've not seen any post like this ever use the term "permathread". They Live!
- bluejellybean 4y agoI say this as someone who has been heavily using the command line for the last decade, even if you "know" how to use a CLI decently well, go read this if you haven't. From only a couple minutes of reading I found not one, but two new tidbits that I never even considered looking up. This information will completely change my daily levels of frustration when using a CLI. Very, very high ROI link.
- jrib 4y agoWhat were the two tidbits for you? Some notable ones for me: * curl cheat.sh/command will give a brief "cheat sheet" with common examples of how to use a shell command. * `sort -h` can sort the output of `du -h` * https://www.gnu.org/software/datamash/ https://www.gnu.org/software/datamash/ * https://catonmat.net/ldd-arbitrary-code-execution https://catonmat.net/ldd-arbitrary-code-execution
- dspillett 4y ago> `sort -h` can sort the output of `du -h` Not read the article yet, but this is something that is new to me but probably shouldn't be. Hopefully I'll remember it next time it might be useful! Also scanning the sort documentation for other bits I'd not remembered/known, I notice --parallel=n – I'd just assumed sort was single-threaded, where it is not only capable of multicore sorting but does so by default. Useful to know when deciding when to do things concurrently by other means.
- deafpolygon 4y agoNice write-up. Useful information even if you've been on the CLI for centuries.
- teddyh 4y ago> Use grep . * to quickly examine the contents of all files in a directory I prefer to use grep '' * since grep . * omits empty lines.
- teddyh 4y ago> tail -f (or even better, less +F), While “less +F” is useful, it will also eat all of your memory if left running.
- Calzifer 4y agoThe less variant is good if you only want to follow for a short time or check for new output once since it can be enabled/disabled in less itself with 'F' and Ctrl+c and then you can again scroll and search in less. And regards tail. I think most users want tail -F instead of tail -f in most cases. Lowercase f follows the file descriptor while uppercase F follows the file name. So with -f you can still follow a file if it is moved or deleted (but I can't imagine many cases where you want to follow a deleted file and someone continues writing to the deleted file). With -F you can follow a file which does not exist yet (and will start following when it's created) or when a logfile is rotated continue following the new logfile.
- vaughan 4y agoIt's interesting how dev tools went from text-based 80s to GUI 90s and then back to text-based. As well as the terminal, think about Markdown vs WYSIWIG, Visual Studio/XCode vs Ruby on Rails, YAML config files vs XML with visual editor, etc. Terminal is good because its unconstrained. But most of the time I would prefer a GUI interface. We just need to blend the two approaches better and always have a terminal fallback.
- bitwize 4y agoThis is because as Linux started taking over the server space, it brought with it a culture of "stone knives and bearskins" tooling from old-school Unix -- and most applications these days are web applications. One of the major disappointments of recent years is seeing Microsoft backpedal from promoting Windows as the premier development platform and embracing (to extend or extinguish?) Linux with its command lije bullshit. Windows in the late 90s was an entire environment based on composable components, linked together via discoverable interfaces. It had a software composition story far superior to Unix pipes. We should be able to build entire web and cloud infrastructures by wiring components together visually, and using visual inspection tools to debug problems as they happen in the pipeline. Not monkey about with YAML and JSON.
- bradrn 4y ago> Windows in the late 90s was an entire environment based on composable components, linked together via discoverable interfaces. It had a software composition story far superior to Unix pipes. I’ve never heard anything about this (probably because it was before my time); could you elaborate?
- muststopmyths 4y agoSounds like COM. Comparing a programming framework to pipes seems a bit over the top though. I don't know anyone who'd seriously advocate building a large application solely from small programs piping their output to other small programs. I've already complained previously about the new Microsoft though, so I have sympathy with the underlying sentiment :)
- k3vinw 4y agoI’ve been using the command line for almost 3 decades. This is really great! I found it covers basically everything I ever had to care about. Strikes a good balance in level of detail. Well done!
- yekm 4y agoNice and short collection of useful commands. I am really surprised that there is only one very brief mention of GNU parallel.
- d4rkp4ttern 4y agoWorking at the Command Line is a superpower especially when combined with auto-suggestions from tools such as zsh + oh-my-zsh. I would be completely lost if I didn’t have the auto suggestions as my “second brain” ! One problem though — to run a variant of an existing previous command, I find myself editing super long command lines, I.e bring up a previous command by accepting the auto-suggestion, then Ctl-b thru it and make an edit to run a new variant. This made me wonder: is there some tool that presents a TUI type of 2-dimensional interface that lets me navigate through the various options using arrow keys etc ?
- rascul 4y agoHave you looked at hstr? https://github.com/dvorka/hstr https://github.com/dvorka/hstr
- d4rkp4ttern 4y agoWow thanks for this suggestion. Reminds me why I love HN :)
- weeeeelp 4y agohey that's pretty cool! just installed and works nicely on zsh
- vaughan 4y agoSo cool!
- evulhotdog 4y agoI can’t directly answer your question, but in iTerm2, I am able to option+click to where I want to put the cursor, and it will put your cursor exactly there. This allows you to edit annoying long command with more ease and (kind of) a GUI feature in a sense.
- nequo 4y agoNot the TUI you are asking for but TIL about Ctrl-X Ctrl-E from this link which starts up your text editor to edit the command.
- jmclnx 4y ago> Learn basic Bash In a way, true, but if you want to work in the corporate world, should be "learn ksh". Very little difference between them, and will force you to write portable scripts. Using bashisms will make things a bit harder for you. Most proprietary software companies like to buy uses ksh. I support a few of them now where I work, all uses ksh.
- nequo 4y ago> Most proprietary software companies like to buy uses ksh. I support a few of them now where I work, all uses ksh. Why ksh over bash? Is this because they are not running Debian/Ubuntu/Fedora/RHEL?
- computerfriend 4y ago> Most proprietary software companies like to buy uses ksh. I support a few of them now where I work, all uses ksh. I've never known companies to buy large software products written in a shell language, but on top of that haver rarely if ever come across ksh in a professional setting. I can imagine this being the case in some industry niche, but don't think "most" is appropriate.
- layer8 4y ago> Most proprietary software companies like to buy What does this refer to?
- jmclnx 4y agoFor one, many SAP scripts I have seen uses ksh on their servers. That is because they want to be compatible between Linux and commercial UNIX.
- AndyKluger 4y agoI look forward to reading this, but > Bash is powerful and always available As someone who often works with Alpine Linux, this is an annoyingly popular myth.
- gazby 4y agoAs someone who often works with Bash, Alpine Linux is an annoyingly popular distribution.
- Calzifer 4y agoSince the list mentions grep -o (--only-matching) and regex. Here is my preferred trick to extract a specific part of a line and circumvent the lack of capture groups in grep. Imagine you have a line containing prefix 1234 suffix and want to only grep the number but need to match prefix and/or suffix to not grep another unwanted number. Can be solved with grep --only-matching --perl-regexp 'prefix \K\d+(?= suffix)' The magic is '\K' which kind of resets the 'matched buffer'. [1] So anything before \K is matched but not outputted with -o (or without -o anything before \K would not be highlighted). And for the suffix: (?=) is a positive lookahead [2] which checks if, in this case, ' suffix' is found after the number but also does not include it in the 'matched buffer'. So the output for echo "prefix 1234 suffix" | grep --only-matching --perl-regexp 'prefix \K\d+(?= suffix)' is only 1234 PS: instead of \K the prefix could also be wrapped in a positive lookbehind (?<=prefix ) [1] https://perldoc.perl.org/perlrebackslash#%5CK https://perldoc.perl.org/perlrebackslash#%5CK [2] https://www.rexegg.com/regex-lookarounds.html https://www.rexegg.com/regex-lookarounds.html
- tatref 4y agoIsn't simpler to use perl? Perl -pe 's/.(capture this)./$1/' That way, you can capture multiple groups, and change the format in the output. You can also do simple calculations if you capture numbers
- tryauuum 4y agofor me no, anything perl-related is not simple I also tried putting this question in GPT3: > Isn't simpler to use perl? > It is simpler to use Perl, but it is not as efficient as using C or C++.
- jraph 4y agoNice one, I'll try to counter this garbage GPT3 answer: - I don't think the regex engine in Perl is implemented in Perl. It's probably implemented in C/C++, like grep. libpcre is in C anyway. - Even if grep is/were more efficient, You might have consumed more time and energy thinking, typing and running "grep --only-matching --perl-regexp 'prefix \K\d+(?= suffix)'" than the suggested perl solution - I might have consumed even more energy typing this reply. My computer is there, waiting for me typing, doing not much.
- henrik_w 4y agoIn connection with history, you can use !$ for the last argument, but you can also use escape-dot. I use that quite a bit (and escape-dot is slightly easier to type than !$). Also worth pointing out that you can modify the command in the history list before running it, by typing !xxx:p (adding :p instead of !xxx that just re-runs the command). Then I use arrow-up and then modify it before running it. https://henrikwarne.com/2018/08/11/my-favorite-command-line-shortcuts/ https://henrikwarne.com/2018/08/11/my-favorite-command-line-...
- tryauuum 4y agovimdiff can be quite cool when combined with <() bash feature (which presents command output as file). e.g. see color difference of installed packages on local and remote server vimdiff <( dpkg -l | grep -w ii | awk '{print $2}' | sort -V ) <( ssh REMOTE_SERVER dpkg -l | grep -w ii | awk '{print $2}' | sort -V )
- NikkiA 4y agoI find the suggestion of using `apropos` somewhat weird, since `man -k` has been functionally identical, easier to type, and easier to remember (for me at least) in the 45 years I've been using unix systems. And I think I've only come across one esoteric system (which was some unix on a PDP) that differed in any way between the two.
- MonkeyClub 4y agoI think the idea behind preferring `apropos` instead of `man -k` is that you can get to `apropos` with `apr<TAB>`, while the other invocation is longer (and for sloppy typists, the dash may prove problematic).