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.


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:



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.




All commands from sorted by
Terminal - All commands - 11,951 results
project=YOURPROJECTHERE; package=YOURPACKAGEHERE; osc signkey --extend $project; osc rebuildpac project package
2013-09-27 07:49:41


This is pretty simple but every time I forget how to do it, so let's stick it here.

mogrify -resize 852x480 ./*.png
2013-12-24 12:42:06
User: evilsoup
Tags: ImageMagick

Requires ImageMagick to be installed; mogrify is the lesser-known sibling to convert -- it overwrites your original images, but allows you to work on batches of files without resorting to a loop.

dir=${PWD##*/}; rename "s/`ls -b1 | head -n1 | sed 's/.\{4\}$//'`/$dir/" -v *
2014-07-08 03:20:04
User: codycook
Functions: dir rename

I use this on Debian to rename files that exist in directories but do not have the year in the file name. The directory has the year but the files inside don't.

How I explain how this runs:

The dir variable grabs the name of the folder.

Using rename, substitute the name of the first file and remove the extension, then rename it to the directory name.

To test this before you run it, change -v to -vn.

slice="-rw-r--r-- "; ls -l | cut -c $(echo "$slice" | wc -c)-
sed 's/.*/ /'
2010-02-11 17:45:56
User: putnamhill
Functions: sed
Tags: sed

The first version printed:

tr: empty string2

The second version printed:

sed: -i may not be used with stdin

Maybe I misunderstood the orginal problem.

cobbler repo edit --name=Epel-i386 --environment="http_proxy="
2010-05-11 13:52:43
User: w00binda

This is the command to configure "cobbler reposync" to use a specific proxy setting to mirror locally the content of a specific remote repository.

find * ! -name abc -delete
imap <leader>r <C-r>=system('echo "$(($RANDOM % 100))"')<cr>
2010-10-24 00:37:44
User: voyeg3r

This mapping function is called RANDOM bash and enter a number between 1 and 100

yes 'clear;printf "`date`\n" | figlet -f starwars | boxes;sleep 1' | sh
2011-02-16 03:58:19
User: lkjoel
Functions: printf sleep yes

This is a different version from my original command: Console clock -- Beautiful (http://www.commandlinefu.com/commands/view/7902/console-clock-beautiful )

This one uses Boxes and Figlet.

To install the dependencies on Ubuntu, type in:

sudo apt-get install boxes figlet

To install the dependencies on Debian, type in:

aptitude install boxes figlet
netstat -an |grep ":80" |awk '{print $5}' | sed s/::ffff://g | cut -d: -f1 |sort |uniq -c |sort -n | tail -1000 | grep -v ""
sudo dpkg -i `ls -tr *.deb | tail -n4`
2011-10-09 14:20:11
User: _john
Functions: sudo tail

after kernel build with make deb-pkg, I like to install the 4 newest packages that exist in the directory. Beware: might be fewer for you....

sgdisk /dev/sda -R /dev/sdb && sgdisk -G /dev/sdb
2011-11-15 10:59:02
User: flip

copy GPT partition table from /dev/sda to /dev/sdb, using gptfdisk from http://sourceforge.net/projects/gptfdisk/. The -G command randomizes the UUIDS

find . -type f -print0 | xargs -0 chmod -v gu=rw
2012-03-22 03:08:53
User: Tobbera
Functions: chmod find xargs
Tags: chmod files

This command finds all files in a folder recursively and sets owner and group to read and write. Leaves all dirs intact. This command does takes care of file names with spaces as well.

sudo scp <file or folder> <name of pc 1>@<IP of pc 2>:
git status --porcelain | awk '{print $2}' | xargs git add
2012-09-05 18:07:26
User: brandizzi
Functions: awk xargs

Uses the --porcelain option, which is garanteed to be stable among git versions and configurations - also, is way easier to parse.

cat /var/lib/dpkg/info/*.md5sums|grep usr/sbin/sshd|sed 's,usr,/usr,'|md5sum -c
2013-03-12 11:20:48
User: Ztyx
Functions: cat grep md5sum sed

Replace "user/sbin/sshd" with the file you would like to check. If you are doing this due to intrusion, you obviously would want to check size, last modification date and md5 of the md5sum application itself. Also, note that "/var/lib/dpkg/info/*.md5sums" files might have been tampered with themselves. Neither to say, this is a useful command.

grep -E "(.*)(ERROR)(.*)(FAULT)(.*)" log.txt
2013-05-01 15:45:52
User: pioniere
Functions: grep

If you know any two (or more) words are occurring on multiple lines in a file, using a regular expression such as this will help you find them quickly.

find ./ -type f -print0 | xargs -0 md5sum
find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'
2013-09-28 15:44:32
User: bugmenot
Functions: find sed

Shows the OS X applications downloaded from App Store. Doesn't include manually added apps.

FOR %I IN (*.mp4) DO \Tools\ffmpeg\bin\ffmpeg.exe -i "%I" "%~nI.mpeg"
sed -n "/^.\{73,\}/p" < /path/to/file
2014-03-20 12:31:57
User: flatcap
Functions: sed

Filter out lines of input that contain 72, or fewer, characters.

"sed -n" : don't print lines by default

"/^.\{73,\}/" : find lines that start with 73 (or more) characters

"p" : print them

nmap -sP 192.168.1.*
2014-07-08 08:39:14
User: narven

you need to have nmap installed

sudo apt-get install nmap -y

sudo yum install nmap -y

su -c "truecrypt --non-interactive truecrypt-file cryptshare -p PASSWORD"
2009-05-22 21:11:29
User: tatwright
Functions: su

This is useful for use in scripts.

Note that this will leak your password to ps, so this shouldn't be used on shared machines. Use key files for this

printf '%*s\n' 20 | tr ' ' '#'
slice(){ cut -c$((${#1}+1))-; }; ls -l | slice "-rw-r--r--"