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,353 results
amixer -c 0 set Master toggle | tail -1 | awk '{print $4}' | sed "s/[^0-9]//g" ; amixer -c 0 set Speaker toggle >/dev/null; amixer -c 0 set Front toggle >/dev/null
socat udp-listen:1611 system:'ssh remoteserver "socat stdio udp-connect:remotetarget:161"'
2013-07-02 15:08:14
User: kbo
Tags: ssh socat
0

Forward local UDP port to remotetarget via ssh.

for file in ./data/message-snapshots/*.jpg; do cp "$file" /data/digitalcandy/ml/images/; done
2014-06-14 17:26:21
User: ferdous
Functions: cp file
Tags: cp ARG_MAX
0

helpful when you see something like this:

zsh: argument list too long: cp

firefox "$(grep -i ^url=* file.url | cut -b 5-)"
2014-10-08 05:56:27
User: nachos117
0

This command will use grep to read the shortcut (which in the above examle is file.url), and filter out all but the only important line, which contains the website URL, and some extra characters that will need to be removes (for example, URL=http://example.com). The cut command is then used to get rid of the URL= at the beginning. The output is then piped into Firefox, which should interpret the it as a web URL to be opened. Of course, you can replace Firefox with any other broswer. Tested in bash and sh.

grep MemTotal: /proc/meminfo # display how much memory installed
2015-05-15 09:19:02
User: mpb
Functions: grep
0

This will display the system memory size in kb. If you want to see the value in mb, you can type:

grep MemTotal: /proc/meminfo | awk '{printf("MemTotal: %d MB\n",$2/1024)}'

xrandr --output [youroutput] --rotate [right|left|normal] -d [yourdisplay]
2009-02-05 18:28:43
User: michelem
0

You need the RANDR support enable, to enable it with an ATI card run:

aticonfig --set-pcs-str="DDX,EnableRandr12,TRUE"

To show your available output run:

xrandr -q -d [yourdisplay]
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}"