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,491 results
<devcon/>, <dnsstat/>, <dsget>, <dsmod>, <enml>dloal>,/<html></>
2011-12-28 11:41:35
User: ajala19
Tags: cdma
0

the system will display device manager command line utility, dns statistics, v

grep -r <searchterm> .
2012-02-08 11:59:17
Functions: grep
Tags: grep directory
0

You don't need to use "*", it will fail if the working directory has too many fails due parameter extension, you can simply pass the working directory using ".".

for file in *.flac; do flac -cd "$file" | lame -h -b 320 - "${file%.flac}.mp3"; done
2012-03-23 08:05:17
User: samadhi
Functions: file
0

Converts flac files to mp3 with the same file names in the same directory.

(sp-sc sop://brokesopcast.com:3912/6002 3908 8908 &>/dev/null &); vlc http://localhost:8908/tv.asf
sudo find / -perm -2 ! -type l -ls
pdf2jpg(){ convert -density 400 -bordercolor white -border 0 -resize 992x1403 -quality 85 $1 ${1/%pdf/jpg} ; }
awk '{ print $9 }' access.log | sort | uniq -c | sort -nr | head -n 10
ls -1F | grep @$ | sed 's/@//' | column
2013-07-19 17:55:11
User: jlbknr
Functions: grep ls sed
Tags: ls symlinks
0

I use this with alias:

alias lsl="ls -1F | grep @$ | sed 's/@//' | column"

Limitation: This will also list files that happen to have an @ at the end of the filename.

cd ~/wallpapers;arr=( * );num_wallpapers=${#arr[@]};wallpaper=${arr[$(echo $RANDOM%$num_wallpapers|bc)]};feh --bg-fill $wallpaper
2013-12-30 01:56:24
User: Evidlo
Functions: cd echo
0

Generates a bash array and uses it to select a random image from ~/wallpapers.

du -sk * | awk '{print $1} END {print "[+z1<y]sy\nlyx\np"}' | dc
grep "FOUND" /var/log/squidclamav.log | awk '{print $5"-"$2"-"$3","$4","$11}' | sed -e 's/\,http.*url=/\,/g' | sed -e 's/&/\,/g' | sed -e 's/source=//g' |sed -e 's/user=//g' | sed -e 's/virus=//g' | sed -e 's/stream\:+//g' | sed -e 's/\+FOUND//g'
2009-02-27 13:28:18
User: nablas
Functions: awk grep sed
0

This command will list a CSV list of infected files detected by clamav through squidclamav redirector.

tail /var/log/emerge.log | awk -F: '{print strftime("%Y%m%d %X %Z", $1),$2}'
sudo hping3 -TV --tr-stop -n -2 -p 53 ns1.server.tld
2011-01-14 10:12:37
User: forcefsck
Functions: sudo
0

-T = traceroute

-V = verbose

--tr-stop = exit when target is reached

-n = don't do reverse lookups (faster)

-2 = udp

-p 53 = destination port 53 (dns), change to your needs

Useful when trying to debug a network with complex routing rules and/or multiple gateways.

ffmpeg -i input.flv -aq 2 output.mp3
2011-02-16 15:05:41
User: maedox
0

Gives stereo, 16bit, 44.1kHz (default in Ubuntu/Medibuntu ffmpeg).

-aq 2 = 220-250kbit/s VBR, lower number is better quality. 2 or 3 should be good for most people. If you want the best mp3 q you should remove -aq and use -ab 320k to get 320kbit/s, but that is probably overkill for most .flv videos.

nohup df -k | sort -rn 12
\<command>
2011-05-06 15:45:31
User: panlm
0

if you have a alias like this:

alias cp='cp -i'

# cp file1 file1.bak

equal to

# cp -i file1 file1.bak

(it will not overwrite file1.bak if it exist)

# \cp file1 file1.bak

equal to

# /bin/cp file1 file1.bak

(skip alias settings, it will overwrite file1.bak if it exist)

tshark -r data.pcap -zio,phs
xdg-mime default firefox.desktop x-scheme-handler/http
2011-12-28 16:36:27
User: natestar13
0

A universal way to configure your web browser. Note, you'll also need to set "x-scheme-handler/https" and "text/html" for https links and html files, respectively.

repoquery --whatrequires --installed --recursive packagename
2012-09-06 18:20:05
User: eddieb
Tags: yum
0

'yum deplist XXX' provides a list of packages that XXX depends on.

This command provides a list of packages that depend upon XXX (package reverse dependencies)

tr -d '\r' < <input> > <output>
lftp -c "pget -n 10 http://example.com/foo.bar"
nmon -f -T -^ -s 15 -c 12
2013-07-22 08:32:48
User: vidya99343
0

NMON Data collector , DQME

log on to appma569 as root

cd /tmp

nmon -f -T -^ -s 15 -c 12

du -ah | sort -hr | head -n50 | cat -n
cat -A
2009-02-06 02:37:51
User: mkc
Functions: cat
0

This is priceless for discovering otherwise invisible characters in files. Like, for example, that stray Control-M at the end of the initial hash bang line in your script, which causes it to generate a mysterious error even though it looks fine.

('od' is the last word, of course, but for many purposes it's much harder to read.)

mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1 -o output.avi input.flv
2009-09-21 11:56:55
User: ivalladt
0

Create subtitle file heading.ssa with just one entry for the entire video duration. Command line sets that entry's text on top of the video as text watermark. If text is an URL works nice for sending people back to your site from a YouTube clip. Output file is lossless encoded and suitable for further processing. Subtitle file can be a URL so it's saved remotely.