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,181 results
(cd SRC; find . -type d -exec mkdir TARGET/{} ";"; find . -type f -exec mv {} TARGET/{} ";")
2009-08-17 12:35:48
User: karel1980
Functions: cd find mkdir mv
0

Using a GUI file managers you can merge directories (cut and paste). This command roughly does the same (it doesn't ask for confirmation (no problem for me) and it doesn't clean up the empty SRC directories (no problem, trivial).

probably does the same:

cp -l SRC TARGET; rm -rf SRC
ps aux | grep [c]ommandname
SELECT relname, reltuples, pg_relation_size(relname) FROM pg_class r JOIN pg_namespace n ON (relnamespace = n.oid) WHERE relkind = 'r' AND n.nspname = 'public' ORDER BY relname;
2009-08-17 11:46:34
User: alvinx
1

Postgresql specific SQL

- to show count of ALL tables including relation-size (pg_relation_size = used space on filesystem)

- might need a VACUUM ANALYZE before showing all counts correctly !

$ vim ... :help 42
2009-08-17 11:37:02
User: alvinx
Functions: vim
11

inside vim try:

:help 42

to get the meaning of life, the universe and everything !

awk < file.name '{ system("resolveip -s " $1) }'
2009-08-17 08:09:39
Functions: awk
1

Given a file of FQDN, this simple command resolves the IP addresses of those Useful for log files or anything else that outputs domain names.

alien -r -c file.deb
2009-08-17 05:53:15
4

converts between Red Hat rpm, Debian deb, Stampede slp, Slackware tgz, and Solaris pkg file formats ... It also supports LSB packages.

rpm -ivh 'http://www.website.com/path/to/desired_software_package.rpm'
`ls`
2009-08-17 03:56:05
User: matthewbauer
Tags: wildcard
0

This is exactly the same as a wildcard - good for times when wildcards are disabled and when you want have a wildcard of a directory that is not your current ({`ls /path/to/dir`}). Does not work on older versions of Bash though.

for f in *;do case "$(echo $f|sed "s/.*\.\([a-z\.]*\)/\1/g")" in zip)unzip -qqo $f&&rm $f;;tar.gz|tar.bz2)tar xf $f&&rm $f;;rar)unrar e -o+ -r -y $f&&rm $f;;7z)7z e -qqo $f;;esac;done
2009-08-17 03:50:50
User: matthewbauer
-2

This will unarchive the entire working directory. Good for torrents (I don't know why they put each file into a seperate archive).

diff <(cd /path-1; find . -type f -print | egrep -i '\.m4a$|\.mp3$') <(cd /path-2; find . f -print | egrep -i '\.m4a$|\.mp3$')
2009-08-17 00:49:31
User: drewk
Functions: cd diff egrep find
3

diff is designed to compare two files. You can also compare directories. In this form, bash uses 'process substitution' in place of a file as an input to diff. Each input to diff can be filtered as you choose. I use find and egrep to select the files to compare.

file -i * | grep -c 'text/plain'
file -i * | grep 'text/plain' | wc -l
2009-08-16 21:22:46
User: voyeg3r
Functions: file grep wc
0

get files without extensions, get ASCII and utf-8 as "text/plain"

date -j -v +1000000000S -f %m%d%Y mmddYYYY
date -j -v +1000000000S -f %m%d%Y mmddyyyy
:for i in range(1,255) | .put='192.168.0.'.i | endfor
:%s/^/\=line('.').' '
2009-08-16 17:48:03
User: voyeg3r
0

Use this command to insert line numbers in source files, .' ' control how spaces you insert after number.

date -d12/31/1970+1000000000sec
:g/^\s*$/,/\S/-j|s/.*//
2009-08-16 10:01:15
User: clone
2

This command will squeeze all consequent blank lines (including those with only space and tab charactes) to one. It will also empty the resulting line (remove the "|s/.*//" part if you don't need that).

FFPID=$(pidof firefox-bin) && lsof -p $FFPID | awk '{ if($7>0) print ($7/1024/1024)" MB -- "$9; }' | grep ".mozilla" | sort -rn
2009-08-16 08:58:22
User: josue
Functions: awk grep pidof sort
6

Check which files are opened by Firefox then sort by largest size (in MB). You can see all files opened by just replacing grep to "/". Useful if you'd like to debug and check which extensions or files are taking too much memory resources in Firefox.

vi ~/.crontab && crontab ~/.crontab
2009-08-16 08:09:15
User: micha
Functions: crontab vi
-6

this lets you edit a crontab file (which may be used as a backup as well) and insert this into your crontab. this way is especially handy, when multiple users are working on one account (e.g. root)

ntop
x86info
2009-08-16 02:19:39
-2

specific information about your intel CPUs in your system and their features