Hide

What's this?

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/

Get involved!

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.

Hide

Stay in the loop…

Follow the Tweets.

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,617 results
gst-launch v4l2src ! aasink
2009-02-18 22:17:53
User: rubenrua
-1

Use gstreamer to capture v4l2:///dev/video0 and show ascii art video in display.

cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh ; cat >> .ssh/authorized_keys"
2009-02-18 22:13:04
User: jsiren
Functions: cat ssh
5

Enter your ssh public key in the remote end for future key-based authentication. Just type your password one last time. The next time you should be able to login with the public key. If you don't have a key, generate one with ssh-keygen.

Requires Bourne-compatible shell in the remote end.

while true; do /bin/true; done
2009-02-18 22:08:18
User: deepc0re
-3

Loads your CPU, run a instance for each CPU/CORE.

rsync -avz -e ssh username@hostname:/path/to/remote/dir/ /path/to/local/dir/
perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/'
cat /dev/urandom > /dev/dsp
2009-02-18 21:40:29
User: joem86
Functions: cat
4

This command will generate white noise through your speakers (assuming you have sound enabled). It's good for staying focused, privacy, coping with tinnitus, etc. I use it to test that the sound works.

(cd /Applications/Firefox.app/Contents/MacOS; ./firefox-bin -p default --no-remote)
watch -n 1 df
2009-02-18 21:34:06
User: joem86
Functions: watch
5

While copying a large file that may take up a good chunk of your hard drive, start the copy and run this command concurrently. It will print out the disk information every second. It's pretty handy when you have a large copy with nothing to monitor the progress.

for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done
2009-02-18 21:29:28
User: mulad
Functions: mv
5

This will convert filenames from uppercase to lowercase. I find this useful after downloading images from my digital camera. This works for English, but other languages may need something slightly more complex like this:

for i in *; do mv "$i" "$(echo $i|tr [:upper:] [:lower:])"; done

Also, the quote marks aren't necessary if your filenames don't contain spaces.

tar -jcvf /folder/file.tar.bz2 --same-owner --same-permissions /folder/
ipconfig /flushdns
ssh user@host 'mysqldump dbname | gzip' > /path/to/backups/db-backup-`date +%Y-%m-%d`.sql.gz
2009-02-18 21:12:53
User: root
Functions: ssh
Tags: mysql
17

I have this on a daily cronjob to backup the commandlinefu.com database from NearlyFreeSpeech.net (awesome hosts by the way) to my local drive. Note that (on my Ubuntu system at least) you need to escape the % signs on the crontab.

ls |while read line ; do mpg321 -w "$line.wav" "$line" ; done
psg() { if [ -z "$2" ]; then psargs="aux"; greparg="$1"; else psargs="$1"; greparg="$2"; fi; ps $psargs | grep -i "$(echo $greparg | sed -e 's/^\(.\)/[\1]/')\|^$(ps $psargs | head -1)" ; }
2009-02-18 20:57:17
User: DEinspanjer
Functions: grep ps
0

My variant on this common function. Some highlights:

Allows you to override the default ps args of "aux"

Uses bracket trick to omit the grep process itself without having to use a second grep

Always prints the correct header row of ps output

Limitations: Ugly ps error output if you forget to quote your multi word grep argument

df -P
2009-02-18 20:53:31
User: AmadeusZull
Functions: df
3

It is a pain grep-ing/sed-ing/awk-ing plain old df. POSIX it!

cp /really/long/path/and/file/name{,-`date -I`}
2009-02-18 20:35:47
User: ozymandias
Functions: cp
4

The expansion {,} in bash will repeat the given string once for each item seperated by commas. The given command will result in the following being run:

cp /really/long/path/and/file/name /really/long/path/and/file/name-`date -I`

These can be embedded as needed, ex: rm file{1,2,3{1,2,3}} would delete the files file1, file2, file31, file32, file32, and no other files.

for (( i = 10; i > 0; i-- )); do echo "$i"; sleep 1; done
2009-02-18 20:31:46
User: mestr
Functions: echo sleep
4

Countdown from 10 or whatever you want:)

trap "echo \"$0 process $$ killed on $(date).\" | tee ${0##*/}_$$_termination.log; echo 'Active processes at the time were logged to ${0##*/}_$$_termination.log'; ps u >> ${0##*/}_$$_termination.log; exit " HUP INT QUIT ABRT TERM STOP
2009-02-18 20:13:29
User: DEinspanjer
Functions: trap
1

trap is the bash builtin that allows you to execute commands when the current script receives a particular signal.

Uses $0 for the script name, $$ for the script PID, tee to output to STDOUT as well as a log file and ps to log other running processes.

TZ=Indian/Maldives date
2009-02-18 20:12:55
User: berta
5

available timezone can be found in /usr/share/zoneinfo. Other examples:

TZ=Europe/Paris date; TZ=Australia/Sydney date; TZ=America/New_York date

this is based on zoneinfo files on macosx. Your mileage my vary on other unix dialects

tar zcpf backup.tgz --exclude=/proc --exclude=backup.tgz /
2009-02-18 19:31:27
User: starchox
Functions: tar
2

You can exclude more system folders or individual files which are not necessary for the backup and can be recreated after the restore procedure, like /lost+found, /mnt, /media, /tmp, /usr ...

Restoring the above backup procedure is as simple as becoming root and typing:

tar zxpf backup.tgz -C /

You can extract any file or directory out of the backup.tgz file for recovery, for instance, if you have a corrupt or mis-configured fstab file, you could simply issue the command:

tar zxpf backup.tgz /ect/fstab -C /

Other options:

v add verbose option to see files processed

A far safer solution is to restore the desired files under a different directory, and then compare, move, or update the files to their original locations afterward.

rm ./-filename
2009-02-18 18:36:25
User: starchox
Functions: rm
5

Using the redundant ./ directory information prevents the dash from occurring at the beginning of the filename, and being interpreted as an option of the rm command.

Also works using:

rm -- -filename
mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "use psa; select accounts.password from accounts INNER JOIN sys_users ON accounts.id=sys_users.account_id WHERE sys_users.login='xxxx';"
2009-02-18 17:26:41
User: darkon1365
0

This will print to the screen password for the user specified in "sys_users.login='xxxx';. This is for Plesk servers only.

''=~('(?{'.('_/@.*@'^'/])@^`').'"'.('"/_/@]/--!.:@</:[@(:/:^'^'[@*]`>@@@@@^`[@_(`@_]_|').',$/})')
vimdiff /path/to/file scp://remotehost//path/to/file
cat /dev/mem > /dev/audio