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,611 results
find . -name '*.txt' | grep -v '\.lzma$' | xargs -n 1 lzma -f -v -3
rm **/*.htm
2010-11-25 17:28:55
Functions: rm
Tags: find rm
-2

expands through shell and not find

but may hits the limit of max argument size for rm

(thus: for f in **/*.htm;do rm $f;done

but then I prefer the find command ;)

for i in $(ls /the/path); do du -hs /the/path/$i; done
watch w
for domain in `cat list_of_domains.txt`; do echo $domain; whois $domain >> output.txt; done
2010-02-15 17:13:45
User: pathcl
Functions: echo whois
-2

Outputs multiple whois from a plain text file.

vim -p file1 file2 [...]
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail
2009-03-30 15:49:54
User: empulse
Functions: awk cat cut grep sort uniq
-2

Searches /var/log/secure for smtp connections then lists these by number of connections made and hosts.

tcpdump -n -v tcp or udp or icmp and not port 22
cat file1.txt | uniq > file2.txt
wget -O - 'https://USERNAMEHERE:PASSWORDHERE@mail.google.com/mail/feed/atom' --no-check-certificate
2010-09-26 14:47:13
User: PLA
Functions: wget
-3

I use this command in my Conky script to display the number of messages in my Gmail inbox and to list the from: and subject: fields.

lspv
2012-09-13 15:20:06
User: kaushalmehra
Tags: hard disk
-3

The lspv command displays the information about the physical volume if the specific

physical volume name is specified. If you do not add flags to the lspv command, by default

all the available physical volumes are printed along with the following information:

* Physical disk name.

* Physical volume identifiers (PVIDs).

* The volume group, if any, that the physical volume belongs to or the label,if any,

locked with the lkdev command.

* The state of the volume group.

Active-When the volume group is varied on.

Concurrent-When the volume group is varied on in the concurrent mode.

Locked-When the physical volume is locked with the lkdev command.

****************************************************************************************

In the example, the iw406 system has two hard disks.

Phy disk name Phy vol identfrs (PVIDs) volume group State of Volumne group

hdisk0 00f6267c8a99c7b6 rootvg active

hdisk1 00f6267cb3746d01 appinstvg active

hdisk0 is mounted on volume group rootvg. hdisk1 is mounted on volume group appinstvg

find . -depth -type d -empty -exec rmdir -v {} \;
require 'time';backup_dir = '/path';Dir.glob(backup_dir+"/*.sql").each{ |f| filetime = Time.parse(`mdls -name kMDItemContentCreationDate -raw #{f}`);monthago = Time.now - (30 * 60 * 60 * 24);`rm #{f}` if filetime < monthago }
grep -Pv '^\S*(#|$)'
nohup VBoxHeadless -p 3052 -startvm ServidorProducao &
timelimit -t100 somecommand
2010-09-27 08:44:37
User: CodSpirit
-3

I found this in Ubuntu repos, and consider it better than timeout.

/foo
2013-10-09 08:40:06
User: knoppix5
Tags: man search
-3

Will highlight search term i.e. "foo" across entire man page (scroll up or down to see)

/term_to_search_for+Enter

That is how to find things ;)

/Enter

(slash+empty string+Enter) will jump to the next occurence of previous searched item.

echo $EPOCH|awk '{print strftime("%c",$1)}'
tar zxvf package.tar.gz --strip 1
2010-05-18 21:01:23
User: voyeg3r
Functions: tar
-3

if I need get olnly script.sh from "folder/script.sh"

i=0; while [ $i -lt 100 ]; do echo "test, ttest, tttest-${i}" >> kk.file; i=`expr $i + 1`; done
2012-09-13 21:46:18
User: kaushalmehra
Functions: echo
-3

while commandt

do

command

command

...

done

{commandt is executed and its exit status tested.}

for i in 1 2 3

> do

> echo $i

> done

ls | wc -l
2013-01-22 03:35:35
User: Sebasg
Functions: ls wc
-3

ls -1 shows one file per line (update: -1 was not really needed)

wc -l counts the lines received from the previous command

find . -type f -exec grep StringToFind \{\} --with-filename \;|sed -e '/svn/d'|sed -e '/~/d'
2009-03-31 18:09:31
User: f241vc15
Functions: find grep sed
-3

Look for a string in one of your codes, excluding the files with svn and ~ (temp/back up files). This can be useful when you're looking for a particular string in one of your source codes for example, inside a directory which is under version control (e.g. svn), removing all the annoying files with ~ (tilde) from the search. you can even change the command after -exec to delete (rm) or view (cat) files found by 'find' for example

df | grep -w /media/KINGSTON | awk {'print $1'}
2011-01-20 09:07:19
Functions: awk df grep
-3

most usefull when creating batch scripts using several usb drives and some commands like mkntfs needs a device name

the -w option for grep is here to filter lines when you have multiple drives with the same volume label. Without this option, the grep command will return

/media/KINGSTON

/media/KINGSTON_

/media/KINGSTON__

xml2asc < inputfile > outputfile
2011-02-23 12:22:18
User: forcefsck
-3

For reverse, there's asc2xml

asc2xml < entitiesfile > utf8file

They come as a part of the html-xml-utils debian package.

PS. Tried to submit sample data, but the site autoconverted the non ascii to html entities. So a bit of imagination is needed.