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.


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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,360 results
ls -t1 | head -n1 | xargs tail -f
find / -type f -size +512000 | xargs ls -lh | awk '{ print $5 " " $6$7 ": " $9 }'
2010-05-12 17:21:12
User: johnss
Functions: awk find ls xargs
0

This is an updated version that some one provided me via another "find" command to find files over a certain size. Keep in mind you may have to mess around with the print values depending on your system to get the correct output you want. This was tested on FC and Cent based servers. (thanks to berta for the update)

wmic process list IO
2010-08-20 11:05:34
User: glaudiston
0

there's some options, see more details in :

wmic /?

wmic process /?

wmic process list /?

pi 62999 | tr 0-9 del\ l\!owrH
2011-07-29 22:47:53
User: maurol
Functions: tr
Tags: bash pi
0

Pi also says hello world!

python -c 'import string, random; print "".join(random.choice(string.letters+string.digits) for x in range(6))'
awk -F: '$3 > 999 { print $1 }' /etc/passwd
2011-12-30 14:47:10
User: rockenrola
Functions: awk
Tags: awk uid passwd
0

To distinguish normal users from system users. Specify an UID, to list all all users with UID bigger than that in /etc/passwd.

show_code() { pygmentize $1 | less -N }
2012-05-12 09:18:33
User: Flow
Functions: less
0

Uses pygments ( http://pygments.org/ ) to highlight the source code and a less pipe to scroll and show line numbers of the code.

find . | while read line; do test `stat -c %u $line` -eq 1003 && chown android:android $line && echo $line; done
watch -d=c -n3 'lsof -itcp -iudp -c php'
2013-03-14 01:24:50
User: AskApache
Functions: watch
Tags: lsof PHP watch
0

Shows files and processes of the command php

sudo apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-keys [key to get here]
2013-07-23 08:29:40
User: phattmatt
Functions: get sudo
0

If you are an unlucky soul behind a corporate firewall you will likely find that downloading gpg keys is blocked. This is because the hkp protocol uses port 11371 by default to transfer the key.

By adding "hkp://" to the beginning of the hostname and ":80" to the end you are asking gpg to try using port 80 to connect (less likely to be blocked by a firewall). This relies on the remote server answering to requests over port 80.

icacls directory_or_file /remove:g group_or_user
for i in *.svg; do convert "$i" "${i%.svg}.png" & done
2014-03-26 15:03:54
User: robinro
0

convert all *.svg to png _in parallel_

this speeds up the conversion for many files, but might also not be feasible for a large number of files

find . -type f -iname '*.flac' | while read i; do mv -- "$i" "$i.tmp"; gst-launch filesrc location="$i.tmp" ! flacdec ! flacenc quality=8 ! filesink location="${i%.tmp}"; rm -- "$i.tmp"; done
2014-07-10 19:21:22
User: qdrizh
Functions: find mv read rm
0

Sometimes I get FLAC files that RhythmBox can't play but VLC can. So I re-encode them using GStreamer at highest compression.

grep 'font-family:[^;]*' <input file.svg> | sed 's/.*font-family:\([^;]*\).*/\1/g' | sort | uniq
2014-11-03 20:38:08
User: caiosba
Functions: grep sed sort
Tags: fonts svg
0

List all fonts used by an SVG file. Useful to find out which fonts you need to have installed in order to open/edit an SVG file appropriately.

sftp -s "sudo /usr/lib/sftp-server" [email protected]
2009-03-29 07:02:58
User: mrtheplague
Functions: sftp
0

This requires that your sudo not prompt for a password, as sftp cannot allocate the terminal necessary to ask.

find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
ord () { seq 1 127 | while read i; do echo `chr $i` $i; done | grep "^$1 " | cut -c '3-' }
2009-10-16 21:54:01
User: infinull
Functions: cut echo grep read seq
0

uses the previous "chr" function and uses it to create the inverse function "ord" by brute force.

It's slow, It's inelegant, but it works.

I thought I needed ord/chr to do a cartesian cipher in shell script a whie ago, but eventualy I realized I could get fancy with tr and do the same thing...

rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }
2010-05-13 09:28:56
User: sata
Functions: grep ls rm xargs
0
rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }

Add this to your .bashrc file.

Then whenever you need to remove all files/directories but one from present working directory. Run:

rm-but <important-file-or-directory>

Notes:

1. This doesn't affect the hidden files.

2. Argument is actually as string. And all files/directories having this string in there name are left untouched.

perltidy foo.pl
2010-07-19 11:51:47
User: bartonski
0

By default, perltidy will create a file with the extension '.tdy'.

lsof -i :[port number]
F=index.html; for i in *; do [[ $i = $F ]] && continue; echo "<li><a href='$i'>$i</a>"; done >$F
perl -MExtUtils::Installed -E 'say for ExtUtils::Installed->new()->modules()'
2011-11-16 17:26:47
User: kimmel
Functions: perl
Tags: perl oneliner
0

Lists all the modules that were installed the "proper way". It also uses Perl 5.10(or higher)'s say command for less typing.

xsltproc --stringparam name value <xsl_stylesheet> <xml_document>
2012-11-09 15:54:46
User: seb1245
Tags: xml XSLT
0

The XML document can be transformed to text, XML, HTML or anything else. The --stringparam option allows to set XSL variables externally.

FILE='mp3.list';LNNO=`wc -l $FILE|cut -d' ' -f 1`;LIST=( `cat $FILE` );for((;;)) do SEED=$((RANDOM % $LNNO));RNNO=$(python -c "print int('`openssl rand -rand ${LIST[$SEED]} 8 -hex 2>/dev/null`', 16) % $LNNO");mplayer ${LIST[$RNNO]};sleep 2s; done
icacls directory_or_file /grant user_or_group:(oi)(ci)(m,dc)