Live data from Hacker News

Ask HN: What are your favorite one-liner shell commands you use?

news.ycombinator.com

11–20 of 44 posts

Re: Ask HN: What are your favorite one-liner shell commands you use?

#11

Not really a shell one liner, but ctrl+r (a readline command to do an incremental search backwards through history) is something that has been present on every shell I've used for decades without realising it, One day I decided to take the time to read all the magic readline commands because I wanted a way to quickly edit the N-th argument of a command with lots of arguments, and there were way too many of them. Ther…

`cd -` is great for when you just want to nip out of your current directory for a second and then come straight back - especially as I'm pretty sure that most of us never think about pushd/popd until after we've moved to the other directory with cd :)

Re: Ask HN: What are your favorite one-liner shell commands you use?

#13

Not really a shell one liner, but ctrl+r (a readline command to do an incremental search backwards through history) is something that has been present on every shell I've used for decades without realising it, One day I decided to take the time to read all the magic readline commands because I wanted a way to quickly edit the N-th argument of a command with lots of arguments, and there were way too many of them. Ther…

`cd -` is great for when you just want to nip out of your current directory for a second and then come straight back - especially as I'm pretty sure that most of us never think about pushd/popd until after we've moved to the other directory with cd :)

Semi-related: if I want to do a little side quest, maybe pop over to another repo or git worktree for a quick look, I'll drop into a subshell just by running bash before cd-ing. Then I just exit that shell (alias q=exit) when I want to return back to the original dir and context.

Re: Ask HN: What are your favorite one-liner shell commands you use?

#14
I have a super neat one but it's on my work machine. Not strictly a one-liner but definitely a CLI QoL improvement. It allows me to type a partial command, for e.g. up to where a file path might be, hit a hotkey to invoke (e.g.) fzf, and finally have fzf's output inserted where my cursor was in the command. Uses some vars that readline exposes. I haven't taken it beyond inserting paths yet, but you could imagine you could do a lot with inserting arbitrary output into a command you are midway through typing. I'll reply to this when I have it on hand.

Re: Ask HN: What are your favorite one-liner shell commands you use?

#15

Earlier quoted context omitted.

`cd -` is great for when you just want to nip out of your current directory for a second and then come straight back - especially as I'm pretty sure that most of us never think about pushd/popd until after we've moved to the other directory with cd :)

Semi-related: if I want to do a little side quest, maybe pop over to another repo or git worktree for a quick look, I'll drop into a subshell just by running bash before cd-ing. Then I just exit that shell (alias q=exit) when I want to return back to the original dir and context.

You know that you can just press at the bash prompt to quit it as well? (In fact will quit out of most command line programs as it's the End Of Transmission character)

Re: Ask HN: What are your favorite one-liner shell commands you use?

#17
Defined this in whatever init script the shell uses so that I get a long listing of files (first alias below) and long listing of files sorted from oldest to newest (second alias below):

alias ll=“ls -l”

alias lln=“ls -lrt”

Apart from this, I have a few aliases defined to get the size of specific folders and their subfolders (using ‘du -h’ for human readable sizes). The aliases are named like “duh”, “dut” and so on.

Re: Ask HN: What are your favorite one-liner shell commands you use?

#19
1) Whenever building anything;

2>&1 | tee build.log | grep

2) Do everything within GNU Screen window with CTRL-A + Shift-H to log all output to logfile i.e. "screenlog.".

Both lifesavers when working with multiple systems and codebases.

3) Always use "set -o vi" with bash so that i can use vi/vim keybindings across everything.

Post reply on HN