Live data from Hacker News

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

reddit.com

111–120 of 216 posts

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

#111
post #76
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.

I'm baffled all the time by the lack of clear examples on many manpages.

yes, bring back the VAX/VMS help system with the helpful examples at the end, was awesome last time I used it.

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

#112
post #24

That reddit thread is delightful, because it is full of wonderful commands that I didn't know, or rarely use, or had forgotten. But it's also terrifying, because it exposes how many people will post questions before using man.

I was taken aback by one commenter whose command he wished he'd known for years was man, newly discovered by him. "All those years of googling, wasted."

What happened that it's possible for someone to not know that it exists?

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

#113

This is useful for finding and killing a process. ps -A | grep some text in program name upon getting the pid kill -9 pid

also check killall programname

Be careful with killall -- BSD and Linux killall does what you say, but SysV killall kills every program on the machine.

Most of us probably won't be executing killall on any HPUX or IRIX boxes, but it's still good to know the difference ;)

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

#114
post #98

For me, it was using 'cd' without argument. (It takes you back to your ~). Also, learning the various options of grep (-v, -i, -A, -B) made its use really more powerful.

A useful one I somehow missed early on is

  cd -
to change back to whichever directory you were just in. Every once in a while most of us find ourselves facing someone's "how could you not know that?" look.

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

#115
post #83
post #36

Earlier quoted context omitted.

I don't really know a lot about this stuff, but my understanding is that Perl was more or less replaced sed and awk.

I code in Perl at my day job, and I still use awk and grep. Sometimes it's quicker to do it in awk than perl, especially when you're doing it in command line and have to figure out quotes. awk -F, '{print $3}' foo | xargs -I{} echo 'command -x -y -z {}' perl -e 'open F, " ) { my($a,$b,$c,@rest) =split /,/; system("command -x -y -z $c"); }' I think I could do the split into an array and then take the third element, bu…

Instead of opening the file "foo" by hand, you can use Perl's "awk mode" thusly:

   perl -lane 'system("command -x -y -z $F[2]")' foo

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

#116
post #24

That reddit thread is delightful, because it is full of wonderful commands that I didn't know, or rarely use, or had forgotten. But it's also terrifying, because it exposes how many people will post questions before using man.

I was taken aback by one commenter whose command he wished he'd known for years was man, newly discovered by him. "All those years of googling, wasted." What happened that it's possible for someone to not know that it exists?

You can learn a lot by searching the web, so many folks don't learn something new by reading the first chapter of any intro to Unix (or the shell) book anymore. It's still surprising though.

If you search for help with command line utils you are almost guaranteed to get some results that are man pages online, so the person who said that probably has read man pages without realizing it, and without the convenience of the man program.

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

#117
post #46

Not really a command but this: mv /path/to/some/file.{jpg,png} Has been a huge timesaver. It's the same as mv /path/to/some/file.jpg /path/to/some/file.png But saves you the typing/copy pasting the path for the second argument. Can also be used with cp etc.

Brace expansion is bad ass.

http://www.gnu.org/software/bash/manual/bashref.html#Brace-E...

And it's even better in zsh.

http://zsh.sourceforge.net/Doc/Release/Expansion.html#Brace-...

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

#118
post #3

100% agree with CTRL-R. It changed my life. Others that I love: screen, pdsh, perl -pi -e 's/find/replace/g' *.txt redis-cli's new ability to have piped in data be the last argument of a command. vim -o file1.txt file2.txt file3.txt (opening multiple files with vim) Using vim instead of less as a pager: cat file.txt | vim -

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.

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

#119
post #106

!$ (short for !!:$) Passes last argument on the command line. In general, the whole paragraph on HISTORY EXPANSION in the bash manual is a must read. A few ones from the moreutils package: - vipe : manually edit the data in the middle of a pipe. - vidir : treat a directory and its files as a text file. Does renames and deletions. - sponge : when you're doing modification on a file in a pipe, and want the output to be…

alt-. or (ESC .) does something similar, but can be pressed repeatedly to keep going back further in history in case the argument you want isn't on the most recent command.

!! is short for the previous command, but you can do !-2$ to get the last argument from the 2nd last command, or !cp$ to get the last argument from the most recent cp command. Or !cp:2 to get the 2nd argument to the most recent cp command. !# refers to the current command being entered (in zsh, don't know about bash).

Basically I second Aissen's recommendation to read up on history expansion. Super useful.

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

#120

watch for not having to repeatdly type a comnand, usually for an sw app stat for checking when a files been accessed tee piping to a log file with tee, while still seeing normal stdout on screen

Thank you! No more while true + sleep loops for me.
Post reply on HN