these are great ones! But here is mine that I recently learned: sort -h compare human readable numbers (e.g., 2K 1G)
Canonical example: du -h | sort -h
You can't do sort foo > foo because you'll be left with a blank file.
81–90 of 216 posts
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.
Edit: This works rather well:
function cmdfu() {
curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext" --silent | sed "s/\(^#.*\)/\x1b[32m\1\x1b[0m/g"
}
From http://www.commandlinefu.com/commands/view/3086/search-comma..., it uses the commandlinefu API: http://www.commandlinefu.com/site/apiEarlier quoted context omitted.
every developer should know sed and awk. it is amazing how many devs write cumbersome scripts or little programs to handle tasks that are built for sed and awk. my ~/bin folder has ~50 different little scripts that handle all sorts of small tasks.
I don't really know a lot about this stuff, but my understanding is that Perl was more or less replaced sed and awk.
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, but I'm just trying to do an elementary example. When you want to do more things to this argument you necessarily have to grow this, and at one point I got to the point where I started having to escape quotes. That's rather difficult to read when you're just trying to do something quick in the command line and you mismatch a pair.
Earlier quoted context omitted.
How would you make the bash manpage short and to the point, considering the complexity that it implements?
While it doesn't fix the issue, zsh's man page is divided into different sections, which at least alleviates it.
This is how I learned unix shell back around 2000ish. Aside of giving an excellent insight into zsh, it also gives many good hints and notes about unix shells in general.
emacs --daemon (or after you start emacs, M-x server-start). This starts up the emacs server, so that it preserves your open files, and you can start new emacs instances immediately with emacsclient. (I actually symlink emacsclient to vi since it loads as fast as vi, which was one of the weakest points of emacs for me.) Very useful if you are using a remote box (like a vps) as your dev environment.
export ALTERNATE_EDITOR=''
alias e='emacsclient -t'
Now $ e file.txt
will fire up emacsclient to connect to a running emacs daemon. If there is no emacs daemon running it will start one for you and then connect to it.You can
export VISUAL="emacsclient -t"
export EDITOR='emacsclient -t'
for good measure if you like.Earlier quoted context omitted.
You'll want to quote .java so the shell doesn't interpret it as a glob, and find doesn't use GNU style flags. You can also pass wc the filenames directly like this: wc -l $(find . -name '*.java')
That has different semantics (it prints one line per file) and can have line length limitations. This has the same semantics as the parent's version, but without line length issues. find . -name \*.java -exec cat {} + | wc -l
find . -name \*.java -print0 | xargs -0 cat | wc -l
Edit: Dammit. Others have already posted this exact version further below. :-(
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.
Either that or rename jpg png /path/to/some/file.jpg
rename 's/jpg/png/g' /path/to/some/file.jpgEarlier quoted context omitted.
Canonical example: du -h | sort -h
Sort to the same output file: sort -o foo.txt foo.txt You can't do sort foo > foo because you'll be left with a blank file.
Although sort(1) handles this for you as you mention, the general problem in the shell of wanting to overwrite your input file with the output file, but not being able to redirect to it for the reason you mention, is solved with sponge. Rather than:
$ grep "foo" bar.txt >baz.txt; mv baz.txt bar.txt
instead:
$ grep "foo" bar.txt | sponge bar.txt
Earlier quoted context omitted.
Just diff the two directories. $ ls a b a: 1 2 3 4 b: 1 2 3 # Yours: $ diff -u Maybe I'm missing something?
The OP's example is diffing listings of the two directories whereas your command is asking diff to directly work on the directories themselves.