Live data from Hacker News

What's the one Linux command you wish you knew years ago?

reddit.com

121–130 of 216 posts

Re: What's the one Linux command you wish you knew years ago?

#121

It's not a command but it is still useful. When you are typing a long command and you realize that you need to do other command or set of commands first, usually you type ctrl + c to cancel it. By default it does not save in the history. If you put # (comment the command) in front of the command (you can do it quickly with Ctrl + a #) and then you can use Ctrl + r to get it back. I'm sure there are other ways to save…

For those using zsh hit alt-q to stash the current command. After you run the next command your stashed line will be brought back for you.

alt-h behaves similarly but runs `man `, so if you have this:

    $ rsync -
and need to check the options, hit alt-h and the man page for rsync comes up. When you exit you'll be back at:

    $ rsync -

Re: What's the one Linux command you wish you knew years ago?

#122

It's not a command but it is still useful. When you are typing a long command and you realize that you need to do other command or set of commands first, usually you type ctrl + c to cancel it. By default it does not save in the history. If you put # (comment the command) in front of the command (you can do it quickly with Ctrl + a #) and then you can use Ctrl + r to get it back. I'm sure there are other ways to save…

I just put a random character instead of # to get "command not found".

# seems safer... what if you're typing a mv command on a BSD machine that also has GNU binutils and the random character you hit is a "g"? Bad news.

Re: What's the one Linux command you wish you knew years ago?

#123

The "^[." (esc-.) keybinding. In zsh it maps to insert-last-word which allows you to do this: echo hi > /tmp/blah.txt ls -l There's a bunch of complementary commands to go with it too.

Is this only in zsh? I've been recommending this and not marking it explicitly as a zsh thing.

alt-. works too. In the shell ESC is the same as alt-. The difference being that with alt- you hold alt and press , then release them both. with ESC you press escape, release, and then press and release .

Re: What's the one Linux command you wish you knew years ago?

#125
post #99
post #45

Earlier quoted context omitted.

disown is great. However, I don't know if it's possible to start up a new shell, then bring back that process to the foreground. 'jobs' will return no entries, and fg doesn't take a PID parameter. Any ideas? It would be brilliant if that were possible with bash alone.

disown -h will (reportedly) keep it under job control.

True, but doesn't help if you've quit the shell & want to re-attach to the process after logging back in again :(

Re: What's the one Linux command you wish you knew years ago?

#126

Earlier quoted context omitted.

sed -i does the same thing as perl -pi. Though I've not encountered a system that doesn't have both.

Does sed allow in-place file replacement, or do you need to redirect to a different file then cp/mv it over the original? I haven't used it in many years, but sed didn't used to allow this.

sed -i 's/old/new/g' file

Re: What's the one Linux command you wish you knew years ago?

#127
post #110
post #52

Earlier quoted context omitted.

Many comments seem to be shell- and bash-related. Perhaps the thread exposes how difficult to read the bash manpage is. On my system, the bash 4.1 manpage is 41026 words long, or about 80 pages. Manpages are most useful to me when they are short and to-the-point so I can find what I am looking for before I lose interest in skimming through an 80 page book.

'info bash' is much better than 'man bash', give it a try.

On my system, the info documentation for bash 3.1, not including indices, is 53610 words, or 105 pages. The content is identical to that in the manpage. In addition, you have to read it in a clunky, unintuitive, and un-Unixy browser. Far from short and to-the-point, I nearly lost interest just trying to figure out how to coax info to send its output to stdout so I could pipe the 105 page book to wc. The info documentation is not in any way I can measure better than the manpage. Both the info documentation (and I use that term loosely) and the manpage are more noise than signal.

Re: What's the one Linux command you wish you knew years ago?

#129

Actually the new top comment blew me away. I'm in the 20 year veteran category and was also oblivious. Quoted: disown - bash built in. You know how you always start that mega long rsync in an ssh session from your laptop and then realize you have to go offline halfway through? You forgot to start it in screen or nohup, didn't you? You can pause it (ctrl+z), background it (bg), and then disown it so it is protected fr…

'man bash' is pretty amazing the first time you actually read through it.

Re: What's the one Linux command you wish you knew years ago?

#130
post #45

Actually the new top comment blew me away. I'm in the 20 year veteran category and was also oblivious. Quoted: disown - bash built in. You know how you always start that mega long rsync in an ssh session from your laptop and then realize you have to go offline halfway through? You forgot to start it in screen or nohup, didn't you? You can pause it (ctrl+z), background it (bg), and then disown it so it is protected fr…

disown is great. However, I don't know if it's possible to start up a new shell, then bring back that process to the foreground. 'jobs' will return no entries, and fg doesn't take a PID parameter. Any ideas? It would be brilliant if that were possible with bash alone.

Screen is the only real answer, I've ever found.
Post reply on HN