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,158 results
read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-wait
uname -p
qdbus org.kde.krunner_lock /MainApplication quit; qdbus org.kde.plasma-overlay /MainApplication quit
while true;do clear;echo -n Current\ `grep voltage /proc/acpi/battery/BAT0/state | awk '{print $2" "$3" "$4}'`;for i in `seq 1 5`;do sleep 1;echo -n .;done;done
tr -cs A-Za-z '\n' | sort | uniq -ci
2010-10-20 04:12:58
Functions: sort tr uniq
Tags: sort uniq tr
0

Gives the same results as the command by putnamhill using nine less characters.

finger | grep $(whoami) | head -n1 | awk '{print $2 " " $3}'
2011-01-07 16:54:11
User: mogoh
Functions: awk finger grep head
0

finger - gets logged in users

grep $(whoami) - greps only the current user (if there are more logged in)

head -n1 - just one line

awk '{print $2 " " $3}' - second and third word, seperated with a space (the users name)

OT: My first commandlinefu-command :)

for i in $(find . -type f); do mv "$i" "$(echo $i|tr A-Z a-z)"; done
gpg -e --default-recipient-self <SENSITIVE_FILE> && shred -zu "$_"
2011-07-24 05:51:47
User: h3xx
Functions: gpg shred
Tags: GPG shred
0

Make sure the file contents can't be retrieved if anyone gets ahold of your physical hard drive.

With hard drive partition:

gpg --default-recipient-self -o /path/to/encrypted_backup.gpg -e /dev/sdb1 && shred -z /dev/sdb1

WARNING/disclaimer: Be sure you... F&%k it--just don't try this.

mplayer -shuffle $HOME/music/* $HOME/music/*/* $HOME/music/*/*/* etc.
ls -l | sort +4n for ascending order or ls -l | sort +4nr for descending order
> file.txt
2012-08-24 06:51:13
User: arkanjo
0

Using only this, has the same.

(tested in linux, HP-UX and AIX)

python -m SimpleHTTPServer 8000 &; sudo localtunnel -k ~/.ssh/id_rsa.pub 8000
2012-10-30 17:52:14
User: dzup
Functions: python sudo
0

you need ruby gems and localtunnel, further instruction on their website

for ubuntu precise, just intall ...

sudo apt-get install ruby ruby1.8-dev rubygems1.8 libopenssl-ruby

sudo gem install localtunnel

ssh-keygen -t rsa

python -m SimpleHTTPServer 8000

sudo localtunnel -k ~/.ssh/id_rsa.pub 8000

strace -ttvfo /tmp/logfile -s 1024 program
2013-07-06 08:19:29
User: ryanchapman
Functions: strace
Tags: Linux strace
0

How to figure out what a program is doing.

-tt detailed timestamps

-f also strace any child processes

-v be very verbose, even with common structures

-o write output to file

-s N capture up to N characters of strings, rather than abbreviating with ...

curl icanhazip.com
echo "Dave" | grep -o "bob" | sed 's/D/f/'; echo ${PIPESTATUS[1]};
2014-06-21 04:00:53
User: davethomas11
Functions: echo grep sed
Tags: PIPESTATUS
0

Using the $PIPESTATUS array you can get the results of a command in a sequence of commands piped together. The command above returns the result of grep -o "bob", which is exit result of 1 since no match was made.

tar pzcvf /result_path/result.tar.gz /target_path/target_folder
2009-11-10 11:17:00
User: CafeNinja
Functions: tar
0

The command as given would create the file "/result_path/result.tar.gz" with the contents of the target folder including permissions and sub- folder structure.

chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s 'aix user'
cat /proc/acpi/battery/BAT0/state
echo "text" | od -t x1
2010-07-14 14:53:25
User: max_allan
Functions: echo od
Tags: perl hex ascii
0

Just use "od" and it can also dump in decimal or octal.

(use -t x1 and not just -x or it confuses the byte order)

There is a load of other formatting options, I'm not sure if you can turn off the address at the start of the line.

awk '( $1 == "MemTotal:" ) { print $2/1048576 }' /proc/meminfo
ls -r | ?{-not $_.psiscontainer} | group extension | select name, count, @{n='average'; e={($_.group | measure -a length).average}} | ft -a @{n='Extension'; e={$_.name}}, count, @{n='Average Size (KB)'; e={$_.average/1kb}; f='{0:N2}'}
2012-03-13 17:58:10
User: brianpeiris
Functions: ls
Tags: PowerShell
0

Here's an annotated version of the command, using full-names instead of aliases. It is exactly equivalent to the short-hand version.

# Recursively list all the files in the current directory.

Get-ChildItem -Recurse |

# Filter out the sub-directories themselves.

Where-Object { return -not $_.PsIsContainer; } |

# Group the resulting files by their extensions.

Group-Object Extension |

# Pluck the Name and Count properties of each group and define

# a custom expression that calculates the average of the sizes

# of the files in that group.

# The back-tick is a line-continuation character.

Select-Object `

Name,

Count,

@{

Name = 'Average';

Expression = {

# Average the Length (sizes) of the files in the current group.

return ($_.Group | Measure-Object -Average Length).Average;

}

} |

# Format the results in a tabular view, automatically adjusted to

# widths of the values in the columns.

Format-Table -AutoSize `

@{

# Rename the Name property to something more sensible.

Name = 'Extension';

Expression = { return $_.Name; }

},

Count,

@{

# Format the Average property to display KB instead of bytes

# and use a formatting string to show it rounded to two decimals.

Name = 'Average Size (KB)';

# The "1KB" is a built-in constant which is equal to 1024.

Expression = { return $_.Average / 1KB };

FormatString = '{0:N2}'

}

for wrd in `cat file2` ; do sed -i .bk "/^$wrd/d" file1; done
2012-04-30 06:08:12
User: divyamistry
Functions: sed
0

Given that file1 has bunch of lines (i.e. TSV file with first column as row titles), and file2 has bunch of words (i.e. row titles that are in file1), this command takes every word from file2, and removes every line in file1 that starts with that word.

for ((i=65;i<91;i++)); do printf "\\$(printf '%03o' $i) "; done
edit-notime () { FILE=$1; TMP=`mktemp /tmp/file-XXXXXX`; cp -p $FILE $TMP; $EDITOR $TMP; touch -r $FILE $TMP; cp -p $TMP $FILE; rm -f $TMP; }
2012-10-31 00:54:19
User: jecxjoopenid
Functions: cp rm touch
0

Copies file to a temporary location, edit and set to real file's time stamp then copy back. Assumes access to /tmp and has $EDITOR, but can be replaced with better values.

ffmpeg -i input.mkv -vcodec copy -acodec copy -absf aac_adtstoasc output.m4v