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,360 results
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.

export DISPLAY=":0.0" && import -window root screenshot.png
2010-02-17 12:13:49
User: fraktil
Functions: export
-3

Like the given command, but combines _DISPLAY=":0.0"_ with _export DISPLAY_ to get _export DISPLAY=":0.0"_ and only imports if DISPLAY is set successfully.

awk '{total+=$0}END{print total}' file
find . -type f -exec ls -s {} \; | sort -n -r | head -5
python -c "import platform; print platform.node()"
paste -sd'+' file|bc -l
for i in $(seq 300) ; do ethtool -s eth0 autoneg on ; sleep 2 ; done
2010-10-31 18:15:54
User: christian773
Functions: seq sleep
-3

use this comand to see which switch port your network interface is using.

but remind, there is no network traffic for 10 minutes or how long you run the comand.

if you start the comand via ssh, port will come up again after the "for loop" has endet

echo "1+2+3+4" | bc
2011-02-24 03:08:00
User: twjolson
Functions: echo
-3

Works for any mathematical operation, even converting numbers from one base to another.

schtasks /delete /tn * /f
tac [FILE]
netstat -l -p --tcp | egrep -e 'www.*[0-9]{3,4}\/(apache2|httpd)' | awk '{print$7}'
curl -s -O http://s3.amazonaws.com/alexa-static/top-1m.csv.zip ; unzip -q -o top-1m.csv.zip top-1m.csv ; head -1000 top-1m.csv | cut -d, -f2 | cut -d/ -f1 > topsites.txt
2010-11-01 01:25:53
User: chrismccoy
Functions: cut head
Tags: curl unzip cut
-3

this will dump a list of domains one per line into a text file

pgrep -u username php5-fcgi | xargs kill -9
git-createrepo() { repos_path='/srv/git/'; mkdir $repos_path$1; cd $repos_path$1; git init --bare; echo "Repository location: ssh://$USER@`cat /etc/HOSTNAME``pwd`"; cd -; }
2013-05-09 21:44:24
User: batandwa
Functions: cd echo init mkdir
Tags: git
-3

Creates a git repository in a predefined location.

find /Users/jpn/.ievms/ -type f -print0| xargs -0 du -sh
2013-10-16 09:54:19
Functions: du find xargs
-3

When you do a ls -1 | xargs rm it wouldn't workd because those files have spaces. So you must use

find -print0 and xargs -0