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,856 results
urpmi --auto-update --force # apply all pending updates (Mandriva Linux)
2009-03-28 14:59:26
User: mpb
0

Update a Mandriva Linux system with any pending updates.

This command needs to be run with root privilege.

Using the "--force" option answers "yes" to any interactive prompts

thus allowing the updates to be left unattended to completion.

NB if there is an update for glibc and/or a new kernel then the system

would need to be rebooted for these to take effect.

A prerequisite for running "urpmi --auto-update" is to have correctly defined

urpmi media sources (which can be done by visiting http://easyurpmi.zarb.org/).

If there are no new updates the the message "Packages are up to date" is shown.

function svnurl() { svn info $1 | egrep '^URL: (.*)' | sed s/URL\:\ //; }
2010-02-12 15:42:54
User: thebuckst0p
Functions: egrep info sed
0

Can be used in a working copy to output the URL (extracted from svn info), or as part of another function, as $(svnurl some/path). Saves a lot of time in my SVN workflow.

perl -ne '$w = length if (length > $w); END {print "$w\n"}' *.cpp
dpkg-query -l > 1.lst; sudo apt-get install -y build-essential; ./configure; make; sudo checkinstall -D make install; dpkg-query --list > 2.lst; diff 1.lst 2.lst | grep '^>' | awk '{print $3}' | xargs sudo apt-get remove -y --purge
2010-06-16 22:06:07
User: danlangford
0

on a dpkg managed system this PATTERN will help you generate .deb files from source AND remove all the dev libs you had to install. i hate cluttering up my machine with rouge packages and headers.

it would be pretty darn easy on rpm systems as well. i just dont have a rpm managed system to test on right now.

NOTE, you sharp ones will notice that it uninstalls the deb you just made! yeah, but the deb is still there to do with it what you want, like re install it. or you can just grep -v after the diff

command &!
top -p `pidof apache2 | awk '{gsub(/[ ]/,",");print}'`
find -iname \*.pdf -print0 | xargs -0 pdfgrep -i "my search text"
<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.

awk '/text to grep/{print $1}' "log" | sort -n | uniq -c | sort -rn | head -n 100
2014-07-09 08:48:06
User: kln0thing
Functions: awk head sort uniq
0

Original command: cat "log" | grep "text to grep" | awk '{print $1}' | sort -n | uniq -c | sort -rn | head -n 100

This is a waste of multiple cats and greps, esp when awk is being used

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
tshark -r data.pcap -zio,phs