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,605 results
alias s='screen -X screen'; s top; s vi; s man ls;
2009-02-05 13:47:14
User: jonty
Functions: alias man
18

If you are already running screen then you often want to start a command in a fresh window. You use this alias by typing 's whatever' from your command line and 'whatever' starts running in a new window. Good with interactive commands like info, vim, and nethack.

ps -ef | grep [f]oo | awk '{print $2}' | xargs kill -9
2009-02-05 13:43:01
User: eredicatorx
Functions: awk grep kill ps xargs
1

Kill all processes with foo in them. Similar to pkill but more complete and also works when there is no pkill command.

Works on almost every Linux/Unix platform I have tried.

alias 'ps?'='ps ax | grep '
mkdir /Volumes/sshdisk 2> /dev/null; sshfs user@server:/ /Volumes/sshdisk -oreconnect,volname=SSHDisk
2009-02-05 13:31:15
User: fzero
Functions: mkdir
1

To make it even more practical, make sure you can login to the ssh server using a keypair.

pgrep xterm
2009-02-05 13:29:30
User: leonardovaz
0

pgrep is an useful tool which looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. pkill can also be used with pgrep to send a kill signal to the program.

TZ=XYZ24 date
2009-02-05 13:27:14
User: jonty
1

Fool date by setting the timezone out by 24 hours and you get yesterday's date. Try TZ=XYZ-24 to get tomorrow's date. I live in TZ=GMT0BST so you might need to shift the number 24 by the hours in your timezone.

cd /this/directory; for f in *; do ln -s `pwd`/$f /that/directory; done
2009-02-05 13:21:16
User: jonty
Functions: cd ln
0

I find this handy for linking all the bin files in a package to /usr/bin or all the man files to /usr/share/man. You can replace * with */* to operate on all the files in subdirectories.

lspci -vv
2009-02-05 13:01:41
User: kumara
Functions: lspci
4

great for running off a bootable cd to identify hardware other os's can't detect

cat /proc/cpuinfo
nm --defined-only --print-file-name lib*so 2>/dev/null | grep ' pthread_create$'
strings libc-2.2.5.so | grep stat.h
diff -q dir1/ dir2/ | grep differ | awk '{ print "vimdiff " $2 " " $4 }'
2009-02-05 12:37:00
User: binaryslate
Functions: awk diff grep
1

We use this to quickly highlight differences and provide a quick way to cut and paste the command to view the files using the marvellous vimdiff

curl -O http://hosted.met-art.com/generated_gallery/full/061606AnnaUkrainePasha/met-art-free-sample-00[00-19].jpg
2009-02-05 12:35:07
User: kumara
4

-O switch creates local filename same as remote

curl [][] -o #1#2 makes local files unique inserting sequence values into #x placeholders

sequences can be alpha or numeric e.g [a-z] [1-25]

find /path/to/dir -type f |sed 's/^.*\///'|grep -o '\.[^.]*$'|sort -f|uniq -i
for jj in `seq -f "%02.0f" 1 12`; do rr=`ls *S04E$jj*.smi`; tt=`ls *S04E$jj*.avi`; mv "$rr" "${tt%.*}.smi"; done
2009-02-05 12:16:06
User: beila
Functions: mv
-1

Subtitles' file names contain S04E01, S04E02, ... S04E12 and end with ".smi".

Videos' file names contain S04E01, S04E02, ... S04E12 and end with ".avi".

You can change the patterns by changing `ls *S04E$jj*.smi` and `ls *S04E$jj*.avi` parts.

You can change the number of starting and ending file by changing `seq -f "%02.0f" 1 12` part.

perl -i -pe "s/old/new/g" *
2009-02-05 12:07:27
User: pandres
Functions: perl
-1

Replaces every ocurrence of 'old' for 'new' in all files specified. After the 'i' char you can put a '~' or whatever to create a backup file for each replaced with the name equal to the original plus character.

yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
python -m SimpleHTTPServer
tar -tvjf backup.tar.bz2 | sort -nrk 3 | head
ssh-keygen -R \[localhost\]:8022
2009-02-05 11:48:09
User: Sekenre
Functions: ssh ssh-keygen
6

Useful if you have to tunnel ssh through a local port and it complains of the host key being different. Much easier than manually editing the file.

ps -auwx|egrep hunger|grep -v grep| awk '{print "kill -9",$1}' > ~/fu.bar
alias rgrep="find . \( ! -name .svn -o -prune \) -type f -print0 | xargs -0 grep"
du -s * | sort -n | tail
screen -ls | grep main && urxvt -name screen -e screen -x main || urxvt -name screen -e screen -R -S main
2009-02-05 10:51:31
User: trey
Functions: grep screen
0

Open a terminal (urxvt in this case) to connect to a screen session (named "main") and create the screen session if necessary.

ping localip -c 1 -W 1 &> /dev/null && ssh localip || ssh globalip
2009-02-05 10:40:26
User: trey
Functions: ping ssh
1

Ping machine once, waiting 1 second for response until failing. Upon fail, ssh globally, otherwise ssh locally.