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.

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

All commands from sorted by
Terminal - All commands - 12,342 results
mytop --prompt
2009-05-19 19:04:57
0

mytop is a top like monitor for displaying Mysql server statistic and performance. Part of mytop package ,tested on Debian.

find ./ -iname "*.djvu" -execdir perl -e [email protected]=`djvutxt \"$ARGV[0]\"\|grep -c Berlekamp`; chomp @s; print $s[0]; print " $ARGV[0]\n"' '{}' \;|sort -n
2010-04-07 11:15:26
Functions: find grep perl sort
0

Count the occurences of the word 'Berlekamp' in the DJVU files that are in the current directory, printing file names from the one having the least to the most occurences.

cat /proc/acpi/ac_adapter/ACAD/state
ls *.JPG | cut -d . -f 1 | xargs -L1 -i convert -resize 684 {}.JPG {}.jpg
cat tarfile.tar.gz | ssh server.com " cd /tmp; tar xvzf - directory/i/want"
2011-02-11 17:10:01
User: alf
Functions: cat ssh
Tags: ssh tar
0

This may be listed already but this command is useful to untar a specific directory to a different server.

df -h | grep -v ^none | ( read header ; echo "$header" ; sort -rn -k 5)
2011-03-16 14:25:45
User: purpleturtle
Functions: df echo grep read sort
Tags: sort headers df
0

Show disk space info, grepping out the uninteresting ones beginning with ^none while we're at it.

The main point of this submission is the way it maintains the header row with the command grouping, by removing it from the pipeline before it gets fed into the sort command. (I'm surprised sort doesn't have an option to skip a header row, actually..)

It took me a while to work out how to do this, I thought of it as I was drifting off to sleep last night!

mencoder vcd://2 -o sample.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
find /path/to/dir -iname "*.ext" -print0 | xargs -0 mplayer -really-quiet -cache 64 -vo dummy -ao dummy -identify 2>/dev/null | awk '/ID_LENGTH/{gsub(/ID_LENGTH=/,"")}{SUM += $1}END{ printf "%02d:%02d:%02d\n",SUM/3600,SUM%3600/60,SUM%60}'
2012-03-11 12:28:48
User: DarkSniper
Functions: awk find printf xargs
0

Improvement on Coderjoe's Solution. Gets rid of grep and cut (and implements them in awk) and specifies some different mplayer options that speed things up a bit.

cp -p `ls -l | awk '/Apr 14/ {print $NF}'` /usr/users/backup_dir
sudo shutdown -h now
xdpyinfo | grep dimensions | awk '{print $2}'
toilet -f big ReadMe
2009-04-22 05:48:13
User: eastwind
0

need toilet package , same goes for figlet

showfigfonts | less : give the list of font available for options

date -s "$(echo -e "HEAD / HTTP/1.0\n" | nc www.example.com 80 | sed -ne 's/^Date: \(.*\)$/\1/p')"
2010-01-08 20:05:00
User: tomhol
Functions: date
Tags: date
0

Good when firewalled and only in need of a reasonable accurate time.

Use a fast responding web server.

setopt shwordsplit
2010-03-08 20:52:55
User: Gentux
0

for exemple :

var="echo hello"; $var

this will display "hello" with bash

with zsh, by default, this will make an error :

"command not found : echo hello"

hwordsplit option permit zsh to act like bash on this point

curl -sL 'www.commandlinefu.com/commands/random' | awk -F'</?[^>]+>' '/"command"/{print $2}'
2010-08-13 11:42:42
User: putnamhill
Functions: awk
Tags: awk curl random
0

Splitting on tags in awk is a handy way to parse html.

rsync -avz --dry-run --include="only-include-this-filename" -f 'hide,! */' source/folder/ target/folder/
2011-03-16 16:10:42
User: cybertoast
Functions: rsync
Tags: rsync filter
0

Applying filter rules is what makes this a really useful command. It's usually a pain to figure out how to sync ONLY files matching a particular pattern, and often one reverts to goofy stuff like find .. -exec rsync ..

The filter hides all folders from the transfer, so that only the matching folders that store the filename are left for the sync.

nmap -sT -PN -vv <target ip>
2011-07-22 02:37:19
User: Richie086
0

Change the IP address from 127.0.0.1 to the target machines ip address. Even if the target has ICMP (ping) blocked, it will show you what ports are open on the target. Very handy for situations where you know the target is up and online but wont respond to pings.

cp -r path/to/file/tree $(mkdir -p new/path/here; echo new/path/here)
2012-04-27 16:18:11
User: wirespeed
Functions: cp echo mkdir
0

You need to cp, mv, scp, ..., some files around from one place to another, and after having laboriously typed out the source path, you remember that the destination directory doesn't yet exist, and so the command will fail. So rather than killing the command line and starting over, just interpolate the results of creating the directory and echo its name. You could DRY this with a for; do; done, but that may be more trouble than it's worth.

grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
curl simplesniff.com/ip
grep . filename >filename1
logout
virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
vim +"bufdo norm gg=G" +wa +qa FILES
2013-12-06 22:15:24
User: pjump
Functions: vim
0

The equivalent of opening each file in vim and doing

gg=G:wq . Bufdo makes it faster by obviating the need to start vim for each file separately.

for f in */*.ape; do avconv -i "$f" "${f%.ape}.flac"; done
2014-10-10 12:33:00
User: qdrizh
0

Converts all monkey audio files below currently directory to FLAC.

For only current directory, use `for f in *.ape; do avconv -i "$f" "${f%.ape}.flac"; done`

To remove APE files afterward, use `rm */*.ape`