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,588 results
project=YOURPROJECTHERE; package=YOURPACKAGEHERE; osc signkey --extend $project; osc rebuildpac project package
2013-09-27 07:49:41
0

Edit the YOURPROJECTHERE and YOURPACKAGEHERE and you're done.

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
0

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.

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
0

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=http://100.100.100.100:3128"
2010-05-11 13:52:43
User: w00binda
0

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
0

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
0

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 "0.0.0.0"
sudo dpkg -i `ls -tr *.deb | tail -n4`
2011-10-09 14:20:11
User: _john
Functions: sudo tail
0

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
0

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
0

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>:
d%
2012-07-12 18:13:43
Tags: vim
0

Put the cursor on either curly braces ( {, } ). Then press d%

The d is delete command, and % is movement command that move the cursor to another matching parentheses (or curly braces in this case). This action will delete every character that was on the way of the movement (from the first curly braces to the second).

git status --porcelain | awk '{print $2}' | xargs git add
2012-09-05 18:07:26
User: brandizzi
Functions: awk xargs
0

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
0

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
0

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
0

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
0

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

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

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--"
lynx --dump "http://www.google.com.br" | egrep -o "http:.*"
2011-09-05 01:12:15
Functions: egrep
0

Get all URLs from website via Regular Expression... You must have lynx installed in your computer to execute the command.

--> lynx --dump "" | egrep -o ""

- Must substitute it for the website path that you want to extract the URLs

- Regular Expression that you wanna filter the website