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,587 results
mysql -s -e "show processlist" |awk '{print $1}'
season=1; for file in $(ls) ; do dir=$(echo $file | sed 's/.*S0$season\(E[0-9]\{2\}\).*/\1/'); mkdir $dir ; mv $file $dir; done
2009-05-27 03:30:58
User: lonecat
Functions: echo file mkdir mv sed
-1

It happened to me that I got a season of a tv-show which had all files under the same folder like /home/blah/tv_show/season1/file{1,2,3,4,5,...}.avi

But I like to have them like this:

/home/blah/tv_show/season1/e{1,2,3,4,5,...}/file{1,2,3,4,5,...}.avi

So I can have both the srt and the avi on one folder without cluttering much. This command organizes everything assuming that the filename contains Exx where xx is the number of the episode.

You may need to set:

IFS=$'\n'

if your filenames have spaces.

type -all command
svn log fileName|cut -d" " -f 1|grep -e "^r[0-9]\{1,\}$"|awk {'sub(/^r/,"",$1);print "svn cat fileName@"$1" > /tmp/fileName.r"$1'}|sh
2009-05-27 02:11:58
User: fizz
Functions: awk cut grep
Tags: bash svn awk grep
2

exported files will get a .r23 extension (where 23 is the revision number)

last -n 20
2009-05-26 22:09:09
User: jipipayo
Functions: last
1

change 20 by the number of sessions you want to know (20 it's fair enough)

skill -KILL -t ttyS0
2009-05-26 21:47:33
User: jipipayo
Functions: skill
-1

when sometimes do a "w" or "who" command and see an orphan console session from time ago, you could kill with this command.

where ttyS0 its the console to kill.

lsof -nP +p 24073 | grep -i listen | awk '{print $1,$2,$7,$8,$9}'
kill_daemon() { echo "Daemon?"; read dm; kill -15 $(netstat -atulpe | grep $dm | cut -d '/' -f1 | awk '{print $9}') }; alias kd='kill_daemon
2009-05-26 20:39:56
User: P17
-5

Just find out the daemon with $ netstat -atulpe. Then type in his name and he gets the SIGTERM.

cal -y | tr '\n' '|' | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /$(date +%m | sed s/^0//)" | tr '|' '\n'
ip route show dev eth0 | awk '{print $7}'
2009-05-26 20:29:54
User: P17
Functions: awk route
Tags: IP
2
ip address show | grep eth0 | sed '1d' | awk '{print $2}'

does the same, but shows network-prefix.

tar -zcvpf backup_`date +"%Y%m%d_%H%M%S"`.tar.gz `find <target> -atime +5` 2> /dev/null | xargs rm -fr ;
2009-05-26 17:15:52
User: angleto
Functions: rm tar xargs
Tags: backup
7

create an archive of files with access time older than 5 days, and remove original files.

netstat -4tnape
readlink -f /proc/<pid>/cmdline
2009-05-26 10:09:03
User: naseer
Functions: readlink
-1

Uses the pid to get the full path of the process. Useful when you do not which command got picked from the path

netstat -taupe
2009-05-25 12:46:38
User: farwarx
Functions: netstat
-8

Affiche des infos detaillees sur vos connexions reseaux.

Port en ?coute, protocole, paquets, adresses, ustilisateur, PID etc...

mplayer -vo caca foo.avi
2009-05-25 09:29:24
User: farwarx
-11

Permet de lire une video dans une console, meme sans interface graphique.

Interet limite, mais a connaitre au cas ou.

mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1)
sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
2009-05-25 05:37:44
User: mohan43u
Functions: echo sed xargs
10
echo "http%3A%2F%2Fwww.google.com" | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e

http://www.google.com

Works under bash on linux. just alter the '-e' option to its corresponding equivalence in your system to execute escape characters correctly.

mplayer -af scaletempo -speed 1.5 file.avi
2009-05-24 08:06:28
User: elementa13
2

Pitch-correct play speed with mplayer. You can also use [] and {} keys to change play speed on-the-fly.

ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy target_audio.mp3
2009-05-23 23:52:51
User: dcabanis
4

rips the audio and video stream of a movie. The two streams are stored separately.

ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv
2009-05-23 23:47:41
User: dcabanis
4

This assumes that there is a 10.2 sec delay between the video and the audio (delayed).

To extract the original video into a audio and video composites look at the command on extracting audio and video from a movie

ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv mytarget.flv
2009-05-23 23:39:46
User: dcabanis
2

Takes an mpeg video and coverts it to a youtube compatible flv file.

The -r 25 sets the frame rate for PAL, for NTSC use 29.97

ffmpeg -i source.flv -vn acodec copy destination.mp3
2009-05-23 23:34:32
User: dcabanis
2

-vn removes tha video content, the copy option tells ffmpeg to use the same codec for generating the output

lame -h -V 6 track9.wav track9.mp3
2009-05-23 23:27:20
User: dcabanis
-1

The quality ranges between 0 to 9, with the smaller number indicates a higher quality file but bigger too.

mplayer -fs cdda://9 -ao pcm:file=track9.wav
2009-05-23 23:23:45
User: dcabanis
3

Using mplayer to extract audio file from a CD

diff -uw <(fmt -1 {file1, file2})
2009-05-23 03:11:08
User: sunny256
Functions: diff fmt
Tags: bash diff
3

It can be hard to spot differences in reformatted files, because of all the diff noise created by word wrapped lines. This command removes all the noise and performs a word-by-word diff. To ignore empty lines, add -B to the diff command. Also, if this is something you do often, you might want to check out the wdiff(1) program.