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.

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

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,162 results
git commit --allow-empty-message --message ""
2014-07-16 02:06:39
0

This is especially useful for adding changes to a temporary repo, such as a Gist. Avoid using this when collaborating with others.

pm2 start app.js
2014-11-07 23:15:12
User: strzel_a
0

I'm the author of PM2 and wrote this tool, and I'm please to share it here.

Github project link: https://github.com/Unitech/pm2

(acroread &);sleep 2;gdb /opt/Adobe/Reader8/Reader/intellinux/bin/acroread `pidof ld-linux.so.2`
echo 2+3 |bc
2009-07-04 22:03:41
User: Kaio
Functions: echo
0

Handy use of bc in the command line. No need to get 'into' the bc to perform calculations

perl -ne '$pkg=$1 if m/^Package: (.*)/; print "$1\t$pkg\n" if m/^Installed-Size: (.*)/;' < /var/lib/dpkg/status | sort -rn | less
2009-10-19 12:55:59
User: hfs
Functions: perl sort
0

List packages and their disk usage in decreasing order. This uses the "Installed-Size" from the package metadata. It may differ from the actual used space, because e.g. data files (think of databases) or log files may take additional space.

type <command>
find . -name "*.php" -exec grep -i -H "search pharse" {} \;
awk '{if ($1~/Sun|Mon|Tue|Wed|Thu|Fri|Sat/) {DATE=$2" "$3" "$4" "$5 } else {print DATE"|"$0}}' alterorcl.log
sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep udp && echo && sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep tcp
echo foobar | sed -r 's/(^.|.$)//g'
(sed 's/^/x*=/' file ; echo x) | bc
DATE=`date +"%H:%M" --date '-1 min'`; egrep "\ $DATE\:..\ " /var/log/dhcpd.log |awk '/DHCPREQUEST/ {split($3,t,":"); printf("%02d:%02d\n",t[1],t[2]);}' |uniq -c;
hexdump -C file
(date "+%d-%m-%Y %H:%M:%S";curl -s --interface lo:1 ifconfig.me| xargs -t geoiplookup 2>&1)|sed -e 's/geoiplookup/IP:/g' -e 's/GeoIP Country Edition/Country/g'|tr -s "\n" " "|sed 'a\ '
2013-10-07 15:28:55
User: guerito
Functions: date sed tr xargs
0

My first command :) I made this command to log public addresses of a virtual interface who connects random VPN servers around the world.

command_line 2>&1 | tee -a output_file
git log --graph --decorate --pretty=oneline --abbrev-commit
for f in input/*; do BN=$(basename "$f"); ffmpeg -i "$f" -vn "temp/$BN.flac"...
2015-03-01 02:48:19
Functions: basename
0

Full command:

for f in input/*; do BN=$(basename "$f"); ffmpeg -i "$f" -vn "temp/$BN.flac"; sox "temp/$BN.flac" "temp/$BN-cleaned.flac" noisered profile 0.3; ffmpeg -i "$f" -vcodec copy -an "temp/$BN-na.mp4"; ffmpeg -i "temp/$BN-na.mp4" -i "temp/$BN-cleaned.flac" "output/$BN"; done

This was over the 255 character limit and I didn't feel like deliberately obfuscating it.

1. Create 'input', 'output' and 'temp' directories.

2. Place the files that you want to remove the hiss/static/general noise from in the input directory.

3. Generate a noise reduction profile with sox using 'sox an_input_file.mp4 -n trim x y noiseprof profile', where x and y indicates a range in seconds that only the sound you want to eliminate is present in.

4. Run the command.

files=(/usr/share/cowsay/cows/*); cowsay -f `echo ${files[$((RANDOM%${#files}))]}` `fortune` | toilet -F gay -f term
2011-02-20 05:55:33
User: lkjoel
-1

This command will tell you your fortune, with a nice Ascii Art animal, and it is colorized

You need cowsay, toilet and fortune installed.

On Ubuntu this is:

sudo apt-get install cowsay toilet fortune

Debian:

aptitude install cowsay toilet fortune
#!/bin/bash find | grep -P -v "(class)|(zip)|(png)|(gz)|(gif)|(jpeg)|(jpg)" | xargs -I @ grep -H $1 @
2011-10-14 13:28:49
User: kirdie
Functions: find grep xargs
Tags: find grep
-1

calls grep on all non-binary files returned by find on its current working directory

if [[ $EUID -ne 0 ]]; then echo 'Root permissions required! Exiting.'; exit; fi
2011-11-19 23:06:52
User: lordtoran
Functions: echo
-1

This example code is intended to be used as a root permissions check in a script. It makes use of the $EUID (effective user ID) environment variable which is fully su- and sudo-safe.

cd /System/Library/LaunchDaemons; sudo launchctl load -w com.apple.metadata.mds.plist
for i in `cat /proc/mounts | awk '{print $2}' | grep ${CDIR} |sort -r` ; do umount $i; done
tar -cvf /path/dir.tar /path/dir* --exclude "/path/dir/name" --exclude "/path/dir/opt"
get-ipsw(){ curl -s -L http://phobos.apple.com/version | sed -rn "s|[\t ]*<string>(http://appldnld\.apple\.com\.edgesuite\.net/content\.info\.apple\.com/iPhone[0-9]?/[^/]*/$1$2_$3_[A-Z0-9a-z]*_Restore\.ipsw)</string>|\1|p" | uniq; }
2010-06-22 02:34:15
User: matthewbauer
Functions: get sed
-1

Usage:

get-ipsw device-name generation-string firmware-version

For example:

get-ipsw iPod 2,1 4.0

Different generation strings:

iPhone 3G: iPhone 1,2

iPhone 3GS: iPhone 2,1

iPod touch 2G: iPod 2,1

iPod touch 3G: iPod 3,1

This can be used with idevicerestore (I haven't tried it though).

http://github.com/posixninja/idevicerestore

Based on:

http://www.tuaw.com/2010/06/21/ios-4-0-firmware-release-expected-momentarily-quick-terminal-ti/

file <filename>
2011-11-19 23:39:29
User: lordtoran
Functions: file
-1

Some shell newbies don't know this very handy file management related command so I decided to include it here.

You need to have the "file" package installed.