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,493 results
su <username>
ssh HOST '(cd REPO_DIR && git diff --name-only HEAD | cpio -o -Hnewc --quiet)' | cpio -iduv --quiet -Hnewc
2014-02-01 18:40:31
User: ivan4th
Functions: cd cpio diff ssh
Tags: ssh git cpio
0

Copy changed files from remote git repository, _including binary ones_, staged and unstaged alike. Note that this command doesn't handle deleted files properly.

tar -axf fileNameHere.tgz
2014-02-01 16:14:22
User: toro
Functions: tar
Tags: tar
1

With -a you don't care about file type (bz2, gzip, etc.)

rsync -av -e "ssh -o MACs=hmac-ripemd160" --progress --partial user@remotehost://path/to/remote/stuff .
2014-02-01 00:46:38
User: RAKK
Functions: rsync
Tags: ssh rsync hmac
0

This command allows you to mirror folders or files with rsync using a secure SSH channel with a forced HMAC integrity algorithm. Use this if you are absolutely adamant about preserving data integrity while mirroring a set of files. --partial is for resumability.

watch -d "ls -l /proc/$!/fd"
2014-01-31 23:51:17
User: flatcap
Functions: watch
1

You're running a program that reads LOTS of files and takes a long time.

But it doesn't tell you about its progress.

First, run a command in the background, e.g.

find /usr/share/doc -type f -exec cat {} + > output_file.txt

Then run the watch command.

"watch -d" highlights the changes as they happen

In bash: $! is the process id (pid) of the last command run in the background.

You can change this to $(pidof my_command) to watch something in particular.

fping -ga 192.168.1.0/24 2> /dev/null
2014-01-31 19:19:19
User: netaxiz
Tags: nmap ping
2

Will report back IP address's of all hosts that are UP.

nmap -sS -O -v -oS - 192.168.2.0/24
ls | tr [:upper:] [:lower:] | grep -oP '\.[^\.]+$' | sort | uniq -c | sort
2014-01-30 11:37:27
User: icefyre
Functions: grep ls sort tr uniq
1

displays a list of all file extensions in current directory and how many files there are of each type of extension in ascending order (case insensitive)

find . -name "*.URL" | while read file ; do cat "$file" | sed 's/InternetShortcut/Desktop Entry/' | sed '/^\(URL\|\[\)/!d' > "$file".desktop && echo "Type=Link" >> "$file".desktop ; done
sed -n 's/.*\(\(\(^\| \)[0-9]\{1,3\}\.\)\{1\}\([0-9]\{1,3\}\.\)\{2\}[0-9]\{1,3\}\) .*/\1/gp'
2014-01-29 23:18:14
User: smkr
Functions: sed
Tags: sed ip address
0

looks for IPs at the beginning of the line or prefixed by a space

lsof -c diff -o -r1 | grep $file
2014-01-29 18:35:28
User: d0g
Functions: diff grep
1

When running a long `diff -r` over folders, this simulates a "verbose" mode where you can see where diff is in the tree.

Replace $file with the first part of the path being compared.

wmic product | findstr /I "name_of_app"
dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge
nmap -sn 192.168.1.0/24
echo -e 'alias exit='\''pwd > ~/.lastdir;exit'\''\n[ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)"' >> ~/.bash_aliases
2014-01-28 18:02:04
User: ichbins
Functions: cd echo
Tags: exit pwd
-1

this command will add the following two lines into the ~/.bash_aliases:

alias exit='pwd > ~/.lastdir;exit'

[ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)"

or redirect it to the ~/.bashrc if you like

Donno, I find it usefull. You may also define an alias for 'cd ~' like - alias cdh='cd ~'

ctrl-t
tar zxvf fileNameHere.tgz
2014-01-28 10:33:51
User: Jonas_E
Functions: tar
Tags: tar unpack
-2

tar command options:

-z : Uncompress the resulting archive with gzip command.

-x : Extract to disk from the archive.

-v : Produce verbose output i.e. show progress and file names while extracting files.

-f backup.tgz : Read the archive from the specified file called backup.tgz.

-C /tmp/data : Unpack/extract files in /tmp/data instead of the default current directory.

yum install php-tidy
while pgrep ^dd; do pkill -INFO dd; sleep 10; done
2014-01-28 03:09:25
User: sternebrau
Functions: sleep
Tags: dd progress
2

While a dd is running in one terminal, open another and enter the while loop. The sample output will be displayed in the window running the dd and the while loop will exit when the dd is complete. It's possible that a "sudo" will need to be inserted before "pkill", depending on your setup, for example:

while pgrep ^dd; do sudo pkill -INFO dd; sleep 10; done
nmap -sP 192.168.0.1-254
ping -b 192.168.0.255
2014-01-27 08:06:07
User: betsubetsu
Functions: ping
Tags: ping
0

-b option takes the broadcast address.

for i in {0..255} ; do (ping 192.168.1.$i -c 1 > /dev/null && echo "192.168.1.$i" & ) ; done
2014-01-26 18:31:34
User: bugmenot
Functions: echo ping
7

Pings all the hosts on 192.168.1.0/24 in parallel, so it is very fast. Alive host IP addresses are echoed to stdout as pings are responded to.

wget -q -O- http://bitinfocharts.com/markets/btc-e/btc-usd.html |grep -o -P 'lastTrade">([0-9]{1,})(.){0,1}[0-9]{0,}' |grep -o -P '(\d)+(\.){0,1}(\d)*' |head -n 1