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,860 results
find . -empty -type f -execdir rm -f {} +
2010-11-17 14:15:47
User: maffo7
Functions: find rm
-1

This command will remove only files, not directories: if you wish to remove both directories and files, just remove '-type f' from command above

curl -s http://www.drudgereport.com | sed -n '/<! MAIN HEADLINE>/,/<!-- Main headlines links END --->/p' | grep -oP "(?<=>)[^<].*[^>](?=<)"
gmake runtestsingle testsingle=udtime
2009-02-13 16:53:26
User: piyo
-1

Given a GNU Make file version 3.81 with the following entries:

.PHONY: runtest

runtest: $(ARCHNAME) $(TESTAUTOEXES)

@for i in $(TESTAUTOEXES) ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

.PHONY: runtestsingle

runtestsingle: $(ARCHNAME)/test/auto_$(testsingle).exe $(ARCHNAME)

@for i in $< ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

(ARCHNAME is something like ix86-linux-gnu)

Instead of typing gmake runtest to run all the tests, you can run one specific test with the example command.

The sample output is from compiling a C++ program using Boost::Test testing framework.

perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch
gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"| sort > outputfile.sorted
2009-06-18 20:35:00
User: slashdot
Functions: egrep sort
-1

This commands will make it easier to select only common items between two files being compared. If your lines start with things other than lowercase a-z, adjust this Regex appropriately. Number of lines in the output has been set to no more than 10000, and should be adjusted as needed.

cdrecord -v path_to_iso_image.iso
file -sL /dev/sda7
salt -G 'os_family:Debian' cmd.run ' /usr/lib/update-notifier/apt-check --human-readable'
for i in *.tar.gz *.tgz; do tar -zxvf $i; done
2009-02-18 10:58:12
User: bohemicus
Functions: tar
-1

This is a little bash script that will take all files following the *gz pattern in the directory and apply the tar -zxvf command to them.

ls -F|grep /
2009-10-08 16:35:15
User: romulusnr
Functions: grep ls
-1

No need for -l and the output can be sent directly into another function expecting directory names.

git archive HEAD | gzip > ~/Dropbox/archive.tar.gz
ssh remotebox tail -f /var/log/remotelog
alias ll="ls -lh --color=auto"
: ${VAR:?unset variable}
2009-09-14 19:41:01
User: arcege
Tags: shell
-1

Works in all shells. Does not require a test. Handles like an assertion.

scp -i /path/to/file.pem [local-files] root@[dest-host]:[dest-path]
PS1="\[\033[44;1;37m\]\u\[\033[0m\]@\h\\$ "
watch ccache -s
2009-02-13 17:16:32
User: piyo
Functions: watch
-1

OMG, you are a Gentoo junkie.

-funroll-loops-me-harder ;-)

http://ccache.samba.org/

ccache is a compiler cache, which speeds up your compiler on successive runs, because it caches intermediate compiled output.

dig google.com
2009-08-28 04:32:52
User: unixbhaskar
Functions: dig
Tags: dns
-1

It is a much better tool then nslookup for getting information about the any site.It has got better capability too.For reverse information please use the switch "-x" and the ip address.

find . -maxdepth 1 -type f -mtime +60 -ls
grep -rnA 10 TODO *
2011-09-28 16:26:14
User: blockcipher
Functions: grep
Tags: grep
-1

This will recursively go through every file under the current directory showing all lines containing "TODO" as well as 10 lines after it. The output will be marked with line numbers to make it easier to find where the TODO is in the actual file.

startx -- :1
2009-02-13 17:22:13
User: sudo
-1

Just tape:

sudo -s

your passwd

startx -- :1

airmon-ng start <interface> <channel>
2009-02-18 11:46:36
User: jie
-1

First you need to instal aircrack-ng

Use this command if you need to put your wireless card into monitor mode.

interface = wlan0 || wifi0 || ath0 et ceatera...

channel = 6, 11, 10, 9 et ceatera

evince "$(find -name 'NameOfPdf.pdf')"
2010-04-04 20:55:51
User: RBerenguel
-1

This assumes there is only one result. Either tail your search for one result or add | head -n 1 before the closing bracket. You can also use locate instead of find, if you have locate installed and updated

setlocal enabledelayedexpansion
2010-08-10 12:26:43
User: Marco
-1

Usually the MS-DOS cmd.exe processes in the whole FOR loop as one command and expands each var like %varname% in before (except the loop var of course).

This command enables expansion of other vars than only the loop var during the FOR loop. The syntax of the var to expand is then !varname! inside the FOR loop.

Use command

endlocal

to end the setlocal command.

E.g. (only works from batch files, not from commandline directly):

@echo off

setlocal enabledelayedexpansion

FOR %%A IN (*) DO (

set file=%%A

echo !file!

)

endlocal

for x in *s.yml; do mv $x `echo $x | sed 's/s\.yml/\.yml/'`; done
2009-03-10 17:51:19
Functions: mv sed
-1

Jan Nelson from Grockit came up with this for us when we needed to rename all of our fixtures.