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,927 results
find ~/random_jpegs/folder -name "*.jpg" -exec rdjpgcom {} \;
2009-02-09 02:58:13
User: Williebee
Functions: find
0

depends on libjpeg-progs

But how to display path to found comments?

df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)"
2009-02-09 01:54:05
User: bones7456
Functions: df grep
-1

show physical disk using, except tmpfs, gvfs, and so on.

split -b 1k file ; cat x* > file
2009-02-08 23:10:18
User: abcde
Functions: cat file split
2

`split -b 1k file` splits files into 1k chunks. Rejoin them with `cat x* > file`.

for i in $(seq 1 50) ; do echo Iteration $i ; done
2009-02-08 23:03:31
User: abcde
Functions: echo seq
8

Optionally, one can use {1..50} instead of seq. E.g. for i in {1..50} ; do echo Iteration $i ; done

sed -n '10,20p' <filename>
2009-02-08 22:34:04
User: ergut
Functions: sed
54

Similarly, if you want to print from 10 to the end of line you can use: sed -n '10,$p' filename

This is especially useful if you are dealing with a large file. Sometimes you just want to extract a sample without opening the entire file.

Credit goes to wbx & robert at the comments section of http://www.commandlinefu.com/commands/view/348/get-line1000-from-text.#comment

ls -l | egrep ^d
2009-02-08 22:21:55
User: ergut
Functions: egrep ls
3

This command would be useful when it is desirable to list only the directories. 'egrep' chooses only the lines that begin with 'd'.

while [ ! -f /tmp/stop ]; do ssh -o ExitOnForwardFailure=yes -R 2222:localhost:22 target "while nc -zv localhost 2222; do sleep 5; done"; sleep 5;done
diff <(ssh nx915000 "rpm -qa") <(ssh nx915001 "rpm -qa")
echo -n m{1..5}.cluster.net | xargs -d' ' -n1 -P5 -I{} ssh {} 'uptime'
wget -qO - "http://www.tarball.com/tarball.gz" | tar zxvf -
perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')"
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
2009-02-08 10:10:00
User: morpheus
Functions: dd ssh
177

This will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.

cd //
head -1000 < lines.txt | tail -1
cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bash
cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bash
while [ 1 ]; do date; ls -l /path/to/dir; sleep 1; done
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /file/of/ip/addresses
rak "what you're searching for" dir/path
( while read File; do mogrify -resize 1024 -quality 96 $File; done ) < filelist
2009-02-08 02:48:26
User: Corsair
Functions: read
-1

Imagemagick library is used. If image format is not JPEG, the "quality" option should not be issued.

for File in *.jpg; do mogrify -resize 1024 -quality 96 $File; done
ldconfig -p | grep <somenewlib.so>
2009-02-07 23:15:38
User: al3x
Functions: grep ldconfig
0

Allows to check if shared library could be dynamically loaded

ldd <executable binary>
2009-02-07 23:13:40
User: al3x
Functions: ldd
2

provides list of shared libraries required by executable

rpm -qlp <package.rpm>
2009-02-07 23:11:59
User: al3x
Functions: rpm
0

allows to check inside rpm file w/o installing it

ls -al /proc/<PID>/fd
2009-02-07 22:57:03
User: al3x
Functions: ls
1

Useful for examining hostile processes (backdoors,proxies)