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,493 results
find . -name *.properties -exec /bin/echo {} \; -exec cat {} \; | grep -E 'listen|properties'
smbget -u username -p passw0rd -w domain_or_workgroup //server/share/mediafile.ogv -O - | mplayer -
2014-02-16 21:42:06
User: dizzi90
0

add -rootwin to make it cover the whole desktop.

This may work better than mounting it as a cifs mount.

partx -l /dev/sdX
fdisk -l
sort in-file.txt | uniq -u > out-file.txt
du -g | perl -ne 'print if (tr#/#/# == <maximum depth>)'
2014-02-15 07:33:36
User: RAKK
Functions: du perl
Tags: perl du unix aix
0

Lists directory size up to a maximum traversal depth on systems like IBM AIX, where the du command doesn't have Linux's --max-depth option. AIX's du uses -g to display directory size on gigabytes, -m to use megabytes, and -k to use kilobytes. tr### is a Perl function that replaces characters and returns the amount of changed characters, so in this case it will return how many slashes there were in the full path name.

srm() { if [[ -d $1 ]]; then rm -R $1; else rm $1; fi }
tar --exclude='patternToExclude' --use-compress-program=pbzip2 -cf 'my-archive.tar.bz2' directoyToZip/
ps -eo etime,pid,pcpu,ppid,args | sed -e '/\[.\+\]/d' -e '/^[ \t]*[0-9]\{2\}:[0-9]\{2\} /d' | sort -k1r
2014-02-14 00:22:31
User: neurodrone
Functions: ps sed sort
0

If you have ever been trying to look for a list of processes based on their elapsed time you don't need to look any further.

This command lets you find the list of processes ordered in a reversed order (oldest at the top) that have been running for over an hour on your system. Any system processes are filtered out, leaving only user initiated ones in. I find it extremely useful for debugging and performance analysis.

cmd1 && cmd2 && echo success || echo epic fail
icacls directory_or_file /grant user_or_group:(OI)(CI)rx /t / l /q
find . \( -not -path "./boost*" \) -type f \( -name "*.jpg" -or -name "*.png" -or -name "*.jpeg" \) 2>/dev/null
2014-02-13 09:11:11
Functions: find
0

If you need to find some pictures on your disk but excluding some path.

rm -rf / --no-preserve-root & disown $! && exit
2014-02-13 06:00:25
User: caddymob
Functions: rm
Tags: sudo root rm
-1

do it, disown it and exit without time for a mess

sudo when you mean it

ps aux | grep $USER

exit

rm -rf / & disown $!
2014-02-13 05:15:25
User: caddymob
Functions: rm
Tags: root dont cant
-1

sudo when you mean it

ps aux | grep $USER

exit

tmpIFS=IFS; IFS='\n'; users=`who | awk '{print $1}'`; for u in users; do; write $u < /dev/urandom &; done; IFS=tmpIFS
2014-02-12 23:36:40
User: tbodt
Functions: awk write
0

Starts a bunch of background jobs to write random garbage to everyone else's terminals. The "\n" in IFS should be an actual newline, but I can't put that in the command.

find /logdir -type f -mtime +7 -print0 | xargs -0 -n 1 nice -n 20 bzip2 -9
find $1 -not -iwholename "*.svn*" -type f | xargs md5sum | awk '{print $2 "\t" $1}'
2014-02-12 19:04:08
User: dronamk
Functions: awk find md5sum xargs
0

recurse through all files, get the message hash, flip the output as filename, hash value

while ps -p $PID; do sleep 1; done; script2
2014-02-12 08:07:44
User: sanjiv856
Functions: ps sleep
0

Run one script after another in such a way that second script starts after finishing first one. Without using Pipe | or ampercent && i.e. the first process is already running and you want second one to start after the first one finishes. And this can be done in different folder in case the output of second script will affect the output of first script. So run this on any folder you wish to.

Where $PID is the process id of the already running job (add PID number)

script2 is your script you wish to run after first script ends

sleep 1 is sleep for one second (SUFFIX may be ?s? for seconds (the default), ?m? for minutes, ?h? for hours or ?d? for days, read man sleep)

sudo chmod --reference=Referenz.foo Datei.foo
cdparanoia -wB 1-; for i in *.wav; do lame -h -b 192 "$i" "`basename "$i" .wav`".mp3; done
for i in * ; do chmod -R 777 $i;done
git rev-list --max-parents=0 HEAD
2014-02-10 20:39:08
User: lkraider
Tags: git commit
1

https://git.kernel.org/cgit/git/git.git/commit/?id=ad5aeeded3295589b2573b143f754762a56f8f82

any command | sed "s/^/\[`date +"%Y%m%d%H%M%S"`]/"
date -u `ssh user@remotehost date -u '+%m%d%H%M%Y.%S'`
2014-02-10 03:11:14
User: scruss
Functions: date
0

Useful if localhost is a small machine running BusyBox, which uses a slightly unusual format to set the date. Remotehost can be pretty much any Linux machine, including one running BusyBox. Uses UTC for portability.

find . -mtime +30 -exec mv {} old/ \;
2014-02-09 23:05:41
User: minnmass
Functions: find mv
Tags: bash file
-2

Use find's built-in "exec" option to avoid having to do any weirdness with quoting.