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.


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

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,372 results
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub && ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
2009-10-26 17:52:41
Functions: ssh ssh-keygen
Tags: ssh bash
4

Get your server's fingerprints to give to users to verify when they ssh in. Publickey locations may vary by distro. Fingerprints should be provided out-of-band.

curl http://www.whatismyip.org/
flip -u $FILE
2009-10-26 17:33:26
Tags: flip
0

conversely, you can type

flip -m

to convert the file back to MS line endings.

tr -d '\r\n' < input_file.txt > output_file.txt
2009-10-26 16:12:21
User: nadavkav
Functions: tr
3

Remove CR LF (CRLF) from a text file. use man:tr to get more info about removing other characters from a file. and even character to character replacements.

curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
getdji (){local url sedcmd;url='http://finance.yahoo.com/q?d=t&s=^DJI';sedcmd='/(DJI:.*)/,/Day.*/!d;s/^ *//g;';sedcmd="$sedcmd/Change:/s/Down / -/;/Change:/s/Up / +/;";sedcmd="$sedcmd/Open:/s//& /";lynx -dump "$url" | sed "$sedcmd"; }
w3m http://amit-agarwal.co.in/mystuff/getip_txt.php will return the ip in text format.
w3m miip.cl | grep ip
2009-10-26 01:40:37
User: Cont3mpo
Functions: grep
-2

See external ip with w3m, simple and fast.

On a web site from Chile (spanish).

lynx --dump "http://checkip.dyndns.org"
sudo mount -t vfat /dev/sdb1 /mnt/sdb1
git ls-files | while read i; do git blame $i | sed -e 's/^[^(]*(//' -e 's/^\([^[:digit:]]*\)[[:space:]]\+[[:digit:]].*/\1/'; done | sort | uniq -ic | sort -nr
2009-10-25 09:40:01
User: pipping
Functions: read sed sort uniq
Tags: statistics git
-1

You'll run into trouble if you have files w/ missing newlines at the end. I tried to use

PAGER='sed \$q' git blame

and even

PAGER='sed \$q' git -p blame

to force a newline at the end, but as soon as the output is redirected, git seems to ignore the pager.

sed -n '/test/{/error\|critical\|warning/d;p}' somefile
2009-10-25 09:07:00
User: pipping
Functions: sed
2

That's what the sed command should've been, sorry.

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
git ls-files | xargs -n1 -d'\n' -i git-blame {} | perl -n -e '/\s\((.*?)\s[0-9]{4}/ && print "$1\n"' | sort -f | uniq -c -w3 | sort -r
2009-10-25 01:44:03
User: askedrelic
Functions: perl sort uniq xargs
Tags: statistics git
4

Figures out total line contribution per author for an entire GIT repo. Includes binary files, which kind of mess up the true count.

If crashes or takes too long, mess with the ls-file option at the start:

git ls-files -x "*pdf" -x "*psd" -x "*tif" to remove really random binary files

git ls-files "*.py" "*.html" "*.css" to only include specific file types

Based off my original SVN version: http://www.commandlinefu.com/commands/view/2787/prints-total-line-count-contribution-per-user-for-an-svn-repository

ssh -g -L 8080:localhost:80 root@$HOST
2009-10-24 20:56:00
User: kayowas
Functions: ssh
-2

Forward connections to $HOSTNAME:8080 out to $HOST:80

nethogs -p eth0
2009-10-24 19:43:31
23

Nethogs is a useful tool for monitor bandwidth consumption by pid. Tested on Debian an CentOs

Convert Windows/DOS Text Files to Uni
sed -n /start_pattern/,/stop_pattern/p file.txt
truncate -s0 file
2009-10-24 16:31:03
User: pipping
18

The downside of output redirection is that you need permissions. So something like

> file

won't play nicely w/ sudo. You'd need to do something like

bash -c '> file'

instead, you could go w/

sudo truncate -s0 file
declare -F | sed 's/^declare -f //'
sed '/test/{/error\|critical\|warning/d}' somefile
2009-10-24 15:59:59
User: pipping
Functions: sed
3

If you wanted to do all in one command, you could go w/ sed instead

grep test somefile | grep -v -e error -e critical -e warning
2009-10-24 15:58:11
User: pipping
Functions: grep test
2

You can use -e to pass multiple patterns.

pwgen --alt-phonics --capitalize 9 10
2009-10-24 08:36:36
User: CafeNinja
Tags: Linux terminal
8

Produces secure passwords that satisfy most rules for secure passwords and can be customized for correct output as needed. See "man pwgen" for details.

genpass(){local i x y z h;h=${1:-8};x=({a..z} {A..Z} {0..9});for ((i=0;i<$h;i++));do y=${x[$((RANDOM%${#x[@]}))]};z=$z$y;done;echo $z ;}
2009-10-24 04:32:31
User: twfcc
1

make password randomly, default 8 chars, using bash3.X only, no external program.

genpass() { local h x y;h=${1:-8};x=( {a..z} {A..Z} {0..9} );y=$(echo ${x[@]} | tr ' ' '\n' | shuf -n$h | xargs);echo -e "${y// /}"; }
2009-10-24 04:05:42
User: twfcc
Functions: echo tr
-1

make password randomly, default 8 char