commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
hit BACKSPACE more than once to delete more words
for example if you did a:
ls -la /bin/ls
is equivalent to doing a
Credit goes to "eightmillion"
I use this command (PS1) to show a list bash prompt's special characters. I tested it against A flavor of Red Hat Linux and Mac OS X
Although Exim will purge frozen (undeliverable) messages over time, the command "exim -Mrm #id#" where #id# is a particular message ID will purge a message immediately. Being lazy, I don't want to type the command for each frozen message, so I wrote the one-liner to do it for me.
combines mkdir and cd
added quotes around $_, thanx to flatcap!
With counter format [001, 002, ..., 999] , nice with pictures or wallpapers collections.
Recursively rename .JPG to .jpg using standard find and mv. It's generally better to use a standard tool if doing so is not much more difficult.
In bash, by pressing ALT+n and then a character x, x will be printed n times
I know is not the same as the original command, but is correlated.
sed already has an option for editing files in place and making backup copies of the old file. -i will edit a file in place and if you give it an argument, it will make a backup file using that string as an extension.
how to finish command or script without any output
This should work on any unix platform running bash. Just type the program into cat and give it a ^D when you're done, at which time it will compile, run, and remove the program. Obviously, you can run it without the "rm a.out" if you'd like to keep the binary. If you want to keep the source, well, you might as well just write it in vi or emacs first then.
Quick and easy way to find out which php.ini file is being used. Especially useful if you just need to find the location of the file for editing purposes.
A really fun vim oneliner for auto documenting your option's parsing in your script.
# print the text embeded in the case that parse options from command line.
# the block is matched with the marker 'CommandParse' in comment, until 'esac'
# use vim for parsing:
# 1st grep the case block and copy in register @p + unindent in the buffer of the file itself
# 2nd filter lines which start with --opt or +opt and keep comment on hte following lines until an empty line
# 3rd discard changes in the buffer and quit
vim -n -es -c 'g/# CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %
-c 'g/^\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' \
-c 'q!' $0
Manpages, command summaries, and pretty much everything else usually have the information you're most likely to want at the beginning. Seeing just the last 40 or so lines of options from a command that has 100 is not super useful, and having to scroll up each time you want to glance at something is spastic.
Run this and then do something like
p do vi --help
and you'll get the first screen(-mostly-)full of vi's usage info and options list
to page down, and
to page up.
To see the current page again:
Also useful for situations like
p do aptitude search ~dsmorgasbord
#p sudo aptitude -r install libwickedawesome-perl-snoochieboochies
p sudo aptitude -r install libwickedawesome-perl-snoochieboochies snazztasticorama-dev-v0.∞
where you're using readline up-arrow, HOME, END, etc., to quickly recall commented commands.
For the unaware, that option to aptitude search will bring up all of the packages whose descriptions contain the string "smorgasbord". Depending on your distro, there could potentially be hundreds of them.
Displays a scrolling banner which loops until you hit Ctrl-C to terminate it.
Make sure you finish your banner message with a space so it will loop nicely.
If you have some drive imaging to do, you can boot into any liveCD and use a commodity machine. The drives will be written in parallel.
To improve efficiency, specify a larger block size in dd:
dd if=/dev/sda bs=64k | tee >(dd of=/dev/sdb bs=64k) | dd of=/dev/sdc bs=64k
To image more drives , insert them as additional arguments to tee:
dd if=/dev/sda | tee >(dd of=/dev/sdb) >(dd of=/dev/sdc) >(dd of=/dev/sdd) | dd of=/dev/sde