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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



All commands from sorted by
Terminal - All commands - 12,418 results
echo "shutdown -h now" | sudo at now + 4 hours
2011-05-02 15:29:48
User: depesz
Functions: at echo sudo

Benefit is that it doesn't make you keep the terminal open.

curl --silent http://exsample.com/ | xmllint --html --format - | more
look mysql /etc/group
2009-04-24 18:20:20
Functions: look

Look search for lines in a file that beginning with a given string.

Same as $ grep ^n /etc/passwd

smbclient -N -gL \\SambaServer 2>&1 | grep -e "Disk|" | cut -d'|' -f2
reg add "HKLM\SOFTWARE\Microsoft\Microsoft Antimalware\Exclusions\Paths" /v "C:\temp\evil.exe" /t REG_DWORD /d 00000000
2013-09-20 01:32:05
User: viperbit

Add an entry to Microsoft Forefront's "Excluded file and locations". Replace C:\temp\evil.exe with desired folder to exclude. Requires administrative privileges.









cut -f2 file.txt | cut -d " " -f1
echo 'Host or [email protected]?:'; read newserver && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa ; ssh $newserver cat <~/.ssh/id_rsa.pub ">>" ~/.ssh/authorized_keys ; ssh $newserver
2010-05-07 06:24:53
User: alf
Functions: cat echo read ssh ssh-keygen
Tags: ssh ssh-keygen

Some servers don't have ssh-copy-id, this works in those cases.

It will ask for the destination server, this can be IP, hostname, or [email protected] if different from current user.

Ssh keygen will let you know if a pubkey already exists on your system and you can opt to not overwrite it.

ls -l /dev/disk/by-id | egrep ata-.*`hdparm -i /dev/sda | grep SerialNo | sed 's/.*SerialNo=//' | tr -d "\n"`.*sda$ | sed -e 's/.*ata-/ata-/' -e 's|[ ].*||' | tr -d "\n"
2013-01-07 10:20:25
Functions: egrep grep ls sed tr
Tags: Ubuntu

This was tested on Ubuntu 12.04 (Precise) LTS Server. It returns the name of the symlink within /dev/disk/by-id for the physical drive you specify. Change /dev/sda to the one you want, and replace ata- with scsi- or the appropriate type for your drive.

I used this to pre-configure grub-pc during a non-interactive install because I had to tell it which disk to install grub on, and physical disks don't have a UUID such as that blkid provides.

zsh$ M-v
2009-11-10 23:02:56
User: bucciarati

355 # from zsh-users

356 edit_command_line () {

357 # edit current line in $EDITOR

358 local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$


360 print -R - "$PREBUFFER$BUFFER" >$tmpfile

361 exec

362 ${VISUAL:-${EDITOR:-vi}} $tmpfile

363 zle kill-buffer

364 BUFFER=${"$(



367 command rm -f $tmpfile

368 zle redisplay

369 }

370 zle -N edit_command_line

cyanide(){ display "$(wget -q http://explosm.net/comics/random/ -O - | grep -Po 'http://www.explosm.net/db/files/Comics/*/[^"]+(png|jpg|jpeg)')"; }
2011-02-14 15:12:13
User: barbuk
Tags: comic cyanide

Random Cyanide and Happiness comics from explosm.net. I use this command http://www.commandlinefu.com/commands/view/3477/random-xkcd-comic and update it for explosm.net

--edit : modification for *.jpeg files + guest authors

ls | grep ".txt$" | xargs -i WHATEVER_COMMAND {}
bdf | awk '(NF<5){f=$1; next} (NF>5){f=$1} {print f, $2, $3, $NF}'
while true ; do du -sk testfile ; sleep 10 ; done
2009-08-14 11:39:52
User: Solaris
Functions: du sleep true

This command produces the output of "du -sk testfile" in every 10 seconds. You can change the command to be whatever you want.

for F in $(find ./ -name "*.tgz") ; do tar -tvzf $F ; done
2009-11-11 00:50:52
User: alchandia
Functions: find tar
Tags: tar

The magic is performed by the parameter -t

ls | sed 's,\(.*\),"\1",'
2010-08-17 14:27:27
User: randy909
Functions: ls sed

I had a file named " " (one space) and needed a way to see what the real filename was so I could remove it. sed to the rescue.

alias sshdo='ssh -q -t [email protected] -- cd $PWD \&\& sudo'
2010-10-20 22:33:22
User: darkfader
Functions: alias cd
Tags: sudo su ssh-agent

Run program as root by SSH key forwarding instead of sudoers.

Put this alias line in .bashrc or wherever you like. Alias arguments might need extra escaping.

You might wonder about security. But you'd block out root login as much as possible of course. In sshd_config you put this:

PermitRootLogin no

Match Address

  PermitRootLogin without-password

xinit $(which awesome) -- /usr/bin/Xephyr :5 -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
2012-11-03 00:54:33
User: hute37
Functions: which
Tags: awesome


xinit $(which gnome-awesome-session)

with cat /usr/local/bin/gnome-awesome-session:


exec gnome-session --session awesome "$@"

following: http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome

note: in ubuntu 12.10 a probable Xephyr recent bug rejects keybd option ...

fortune | cowsay $(ls/usr/share/cowsay | shuf -n1)
2014-10-23 10:09:44

To install on centos 6.2

for Centos auto accept:

yum install fortune* -y

yum install cowsay* -y

Removed the -f command as I dont know how, but it works without it.

Almost the same but one folder higher =).

mplayer -shuffle $HOME/music/* $HOME/Dropbox/Music/*/* $HOME/Dropbox/Music/*/*/* etc. >> /dev/null 2>&1
for f in *.png; do convert $f -resize 852x480 $f; done
2013-12-15 11:28:07
User: egeoffray

Resize all png in the current folder.

Warning: no copy. Make sure you have a copy of the originals

10,30,50 * * * * ping -q -c1 -w3 | grep '1 received' - || env DISPLAY=:0 xeyes
2012-02-06 09:40:11
User: knoppix5
Functions: env grep ping
Tags: ping host crontab

Every 20 minutes ping host with IP address If it's not 'alive' or not reachable, then display something eye-catching (here xeyes) on the desktop.

Hint for newbies: edit crontab with

crontab -e
./poweriso extract $USER/file.daa / -od $USER/file_extracted
2009-02-15 23:19:40
User: brettalton

.daa is a non-standard disk image format that can not be read by any other program. This is how you can extract the files though.

PowerISO binary for Linux: http://www.poweriso.com/poweriso-1.3.tar.gz

"This is a free utility for linux which can extract, list, and convert image files (including ISO, BIN, DAA, and other formats). Type " poweriso -? " for detailed usage information. File Size: 278KB"

clamscan -ir --bell ~user/
2009-05-21 13:09:31

Scan for viruses, recursively and print only infected files, with bell sound. Clamscan is part of clamav package. Tested on Debian.

curl http://whatismyip.org