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,847 results
iptables -L -n -v
mkpasswd() { head -c $(($1)) /dev/urandom | uuencode - | sed -n 's/.//;2s/\(.\{'$1'\}\).*/\1/p' ;}
2009-11-19 14:27:52
User: taliver
Functions: head sed uuencode
-3

This uses urandom to produce a random password. The random values are uuencoded to ensure only printable characters. This only works for a number of characters between 1 and 60.

for /f "delims==" %a in (' dir "%USERPROFILE%\*.sqlite" /s/b ') do echo vacuum;|"sqlite3.exe" "%a"
2010-01-18 20:56:00
User: vutcovici
Functions: dir echo
-3

This command defragment the SQLite databases found in the home folder of the current Windows user.

This is usefull to speed up Firefox startup.

The executable sqlite3.exe must be located in PATH or in the current folder.

In a script use:

for /f "delims==" %%a in (' dir "%USERPROFILE%\*.sqlite" /s/b ') do echo vacuum;|"sqlite3.exe" "%%a"
alias cstdin='echo "Ctrl-D when done." && gcc -Wall -o ~/.stdin.exe ~/.stdin.c && ~/.stdin.exe'
2009-11-19 16:38:51
User: taliver
Functions: alias gcc
-3

This is a quick hack to make a gcc caller. Since it runs with gcc instead of tcc, it's a bit more trustworthy as far as the final answers of things go.

man $(ls -1 /usr/share/man/man?/ | shuf -n1 | cut -d. -f1)
2010-08-20 23:36:10
User: dooblem
Functions: cut ls man
Tags: man sort shuf
-3

Another one.

Maybe not the quicker because of the sort command, but it will also look in other man sections.

updated with goodevilgenius 'shuf' idea

mkdir `date | sed 's/[: ]/_/g'`
2009-04-29 21:28:45
User: copremesis
Functions: mkdir sed
-4

use today's time stamp to make a unique directory for today or an hour ago ...

echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | head -n5 | tail -1 | cut -f2 -d-
gst123 -z **/*
2010-05-18 13:45:41
User: eolo999
Tags: music zsh gst123
-4

Depends on zsh and gst123 ( http://space.twc.de/~stefan/gst123.php )

cd in_your_music_root_folder and then issue the command

for i in $(tar -tf <file.tar.gz>); do rm $i; done;
2009-07-06 19:57:23
User: din7
Functions: rm tar
-4

Remove annoying improperly packaged files that untar into the incorrect directory.

Example, When you untar and it extracts hundreds of files into the current directory.... bleh.

apropos keyword
cat file1 ... fileN > combinedFile;
2010-04-17 01:00:04
User: GinoMan2440
Functions: cat
Tags: cat bash Linux
-4

the last person who posted used the most roundabout way to concatinate files, there's a reason there's a "conCATinate" command... Using this method, you also get to choose the order of the files, below another person just did *.txt > combined.txt which is fine but the order depends on the implementation of "cat" which is probably alphabetical order of filenames.

top -b -n 1 |grep httpd|wc -l
2010-07-25 08:40:03
User: dotanmazor
Functions: grep top wc
-4

Of course, the httpd can be replaced with any other process name

while sleep 1; do date; (netstat -a -n | grep 80) ; done
paste <(banner hello,\ ) <(banner world)
2011-11-21 06:38:16
User: kev
Functions: banner paste
Tags: banner
-4

# # ####### # # ####### # # ####### ###### # ######

# # # # # # # # # # # # # # # # #

# # # # # # # # # # # # # # # # #

####### ##### # # # # ### # # # # # ###### # # #

# # # # # # # ### # # # # # # # # # #

# # # # # # # # # # # # # # # # # #

# # ####### ####### ####### ####### # ## ## ####### # # ####### ######

sed -n '1!G;h;$p' techie.txt
find . -type f -exec md5sum {} \;
curl -s -O http://s3.amazonaws.com/alexa-static/top-1m.csv.zip ; unzip -q -o top-1m.csv.zip top-1m.csv ; head -1000 top-1m.csv | cut -d, -f2 | cut -d/ -f1 > topsites.txt
2010-11-01 01:25:53
User: chrismccoy
Functions: cut head
Tags: curl unzip cut
-4

this will dump a list of domains one per line into a text file

find . -name 'spam-*' |xargs rm;find . -name 'spam-*' -print0 | xargs -0 rm
2011-01-22 06:46:21
User: mancipar
Functions: find xargs
-4

root@wow/var/spool/clientmqueue # rm spam-*

/bin/rm: Argument list too long.

count=0;while IFS= read -r -d '' line; do echo "${line#* }"; ((++count==5)) && break; done < <(find . -type f -printf '%s %p\0' | sort -znr)
2013-03-19 17:19:26
User: sharfah
Functions: echo find read sort
Tags: sort find head,
-4

This command is more robust because it handles spaces, newlines and control characters in filenames. It uses printf, not ls, to determine file size.

xxcopy x:\folder1 y:\folder2 /s /h /tca /tcc /tcw /yy
lastfile () { find ${1:-.} -maxdepth 1 -type f -printf "%T+ %p\n" | sort -n | tail -n1 | sed 's/[^[:space:]]\+ //'; }
2011-10-17 16:08:02
User: bartonski
Functions: find sed sort tail
-4

Takes a directory name as an argument (defaults to current directory if no arguments are given). Prints the newest file in the directory.

dd if=/dev/sdX of=/root/sdX.bin bs=1M count=1
2009-02-06 17:45:59
User: dhing
Functions: dd
-4

This will copy the first 1MB of your /dev/sdX volume to your /root/sdX.bin file, where SDX is the name of the device you wish to copy the data from (Usually a hard disk)

NOTE: Make sure you capitalize the M in field for BS.

echo $SHELL
cp -a /etc /destination
ps ax > processes && cat processes | egrep "*.exe |*exe]" | awk '{ print $1 }' > pstokill && kill $(cat pstokill) && rm processes && rm pstokill
2011-02-26 16:13:58
User: sxiii
Functions: awk cat egrep kill ps rm
Tags: kill wine exe
-4

This command kills all wine instances and each EXE application working on a PC.

Here is command info:

1) ps ax > processes = save process list to file named "processes" (we save it because we don't wont egrep to be found in the future)

2) cat processes | egrep "*.exe |*exe]" = shows the file "processes" and after greps for each *.exe and *exe] in it

3) | awk '{ print $1 }' > pstokill = saves processes PID's to file "pstokill" using awk filter

4) kill $(cat pstokill) = kills each PID in file pstokill, which is shown by cat program

5) rm processes && rm pstokill = removes temporary files