Live data from Hacker News

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

reddit.com

101–110 of 216 posts

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

#101
post #97

du -sh ./D* 872K ./Desktop 78M ./Documents 3.2G ./Downloads

I would add | sort -h here

if you don't have "sort -h" (mine doesn't do it), you can also use "du -m", which gives file sizes in megabytes -- pretty reasonable. (then "sort -n")

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

#102

Earlier quoted context omitted.

Either that or rename jpg png /path/to/some/file.jpg

I didn't know you could do that with rename. I would have done rename 's/jpg/png/g' /path/to/some/file.jpg

These are actually two different "rename" commands. bgaluszka's version is usually found on Fedora/RHEL/etc. systems coming from the util-linux package, while your version is usually found on Debian/Ubuntu/etc. systems coming from the Perl package.

I prefer the regex one, of course, especially since it takes proper Perl regexes :)

You have to be careful of this though and probably avoid using this command in shell scripts.

edit: You can just stick Debian's rename at $HOME/bin/rename.pl and call it a day; this command is useful in the terminal since it's less typing than a for loop.

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

#103

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…

You will be pleased to know that there is a site full of little gems like this: http://www.commandlinefu.com/commands/browse/sort-by-votes Most of my time savers that I've never thought of were found there.

python -m SimpleHTTPServer

Love this one.

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

#104
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 -

> screen

Unless you only use GPL software, there's no reason to not use tmux these days. Well, maybe if you're on HP-UX or something.

http://tmux.sourceforge.net/

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

#105
post #57

My method to learn Linux/OSX command line. Step 1: Think "I wish I could do X." Step 2: Google/duckduckgo "How to do X in bash" Step 3: Delight that a simple solution already exists. This method is successful in 95% of all cases.

This post and probably your comment will be in the results , gotta love that.

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

#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 to this file (file will be scrambled without sponge).

It has others, very useful tools, but I won't spoil them all.

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

#107
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 -

http://www.vim.org/scripts/script.php?script_id=1723 vimpager. Set vim as your pager. I love reading man pages in syntax-colored vim glory.

Wow! I knew about less.sh (aka vim less), but this seems even more powerful. Installing now!

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

#108
post #66

Earlier quoted context omitted.

The OP's example is diffing listings of the two directories whereas your command is asking diff to directly work on the directories themselves.

Which means for example you could get that listing in any format, so you could for example spot changes in permissions or ownership if you included it in the listing.

I stand enlightened.

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

#109
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 -

Did you know that Ctrl-s will search forwards through the history too? You'll have to switch flow control off first.

Fantastic. I've always wanted to know what I'm going to do next.

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

#110
post #52
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.

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.
Post reply on HN