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

Commands tagged find from sorted by
Terminal - Commands tagged find - 350 results
find . -type d -not \( -name .svn -prune \) -exec svn propset svn:ignore '*' {} \;
2010-08-15 03:45:57
User: tristan_ph
Functions: find
0

If you would like to ignore a directory including its subdirectory. For example, a tmp/ directory

ls | perl -lne '++$x{lc $1} if /[.](.+)$/ }{ print for keys %x'
2010-08-13 20:05:15
User: recursiverse
Functions: ls perl
-3

All with only one pipe. Should be much faster as well (sort is slow). Use find instead of ls for recursion or reliability.

Edit: case insensitive

find /path/to/dir -type f -name '*.*' | sed 's@.*/.*\.@.@' | sort | uniq
2010-08-12 15:48:54
User: putnamhill
Functions: find sed sort
1

If your grep doesn't have an -o option, you can use sed instead.

find /path/to/dir -type f | grep -o '\.[^./]*$' | sort | uniq
find <dir> -name "<pattern>" | while read file; do echo -n .; output=$(<command>) || (echo ; echo $file:; echo "$output"; ); done
2010-08-10 11:45:31
User: Marco
Functions: echo find read
2

This is a command template for achiving the following:

* loop over files --> find -name "" | while read file; do ...; done

* output progress --> echo -n .

* execute some command on each file and save output for later usage --> output=$()

* if command failed, open subshell and echo newline --> || (echo;...;...;)

* echo output of command --> echo "$output"

find "$1" -iname "*$2*"
find . -iname \*${MYVAR}\* -print
2010-08-04 05:43:51
User: Buzzcp
Functions: find
0

You define your variable MYVAR with the desired search pattern:

MYVAR=

...which can then be searched with the find command.

This is useful if you in a script, where you want the arguments to be fed into the find command.

The provided search is case insensitive (-iname) and will find all files and directories with the pattern MYVAR (not exact matches). This may go without saying, but if you want exact matches remove the \* and if you want case sensitive, use the -name argument.

find -maxdepth 1 -mtime 0 -type f
2010-07-30 01:56:34
Functions: find
Tags: find today mtime
1

Then pipe to 'xargs ls' for a familiar listing, possibly using find's -print0 and xarg's -0 options.

find . -name '*.txt' -print0 | parallel -0 -j+0 lzma
2010-07-28 21:01:12
Functions: find
Tags: find grep lzma
1

This will deal nicely with filenames containing newlines and will run one lzma process per CPU core. It requires GNU Parallel http://www.youtube.com/watch?v=OpaiGYxkSuQ

echo ${fullpath##*/}
2010-07-21 22:35:29
User: quincymd
Functions: echo
9

Quick method of isolating filenames from a full path using expansion.

Much quicker than using "basename"

find . -name '*.txt' | grep -v '\.lzma$' | xargs -n 1 lzma -f -v -3
find -type l -xtype d
ls -l $(find ./ -type l | perl -ne 'chomp; if (-d) { print "$_\n" }')
2010-07-16 19:31:28
User: rwadkins
Functions: find ls perl
-1

This will list all symlinks that are directories under the current directory. This will help you distinguish them from regular files.

nmap -v -sP 192.168.0.0/16 10.0.0.0/8
2010-07-14 19:53:02
User: anapsix
6

nmap for windows and other platforms is available on developer's site: http://nmap.org/download.html

nmap is robust tool with many options and has various output modes - is the best (imho) tool out there..

from nmap 5.21 man page:

-oN/-oX/-oS/-oG : Output scan in normal, XML, s|

grep -R --include=*.cpp --include=*.h --exclude=*.inl.h "string" .
2010-07-14 16:32:28
User: sweinst
Functions: grep
Tags: find xargs grep
0

Gnu grep allows to restrict the search to files only matching a given pattern. It also allows to exclude files.

find . -name '*.?pp' -exec grep -H "string" {} \;
find . -name '*.?pp' | xargs grep -H "string"
2010-07-14 14:41:07
User: cout
Functions: find grep xargs
Tags: find xargs grep
2

I like this better than some of the alternatives using -exec, because if I want to change the string, it's right there at the end of the command line. That means less editing effort and more time to drink coffee.

find /usr/share/figlet -name *.?lf -exec basename {} \; | sed -e "s/\..lf$//" | xargs -I{} toilet -f {} {}
2010-07-13 20:12:54
Functions: basename find sed xargs
Tags: find
1

Lists a sample of all installed toilet fonts

find . -name .svn -exec rm \-rf {} \;
sudo arp-scan -I eth0 192.168.1.0/24
FOR /L %i IN (1,1,254) DO ping -n 1 10.254.254.%i | FIND /i "Reply">> c:\ipaddresses.txt
2010-06-29 21:02:21
Functions: ping
-9

documents all active ips on a subnet and saves to txt file.

for f in $(find /path/to/base -type f | grep -vw CVS); do grep -Hn PATTERN $f; done
find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar`
2010-06-29 12:43:30
User: 0disse0
Functions: find tar xargs
Tags: find tar dump
0

The following command finds all the files not modified in the last 5 days under /protocollo/paflow directory and creates an archive files under /var/dump-protocollo in the format of ddmmyyyy_archive.tar

find / -type f -name *.tar.gz -size +10M -exec ls -l {} \;
2010-06-29 12:39:02
User: 0disse0
Functions: find ls
Tags: find ls exec rm type
0

Please be careful while executing the following command as you don?t want

to delete the files by mistake. The best practice is to execute the same

command with ls ?l to make sure you know which files will get deleted when

you execute the command with rm.

find . -regextype posix-extended -not -regex '.*/[A-Za-z_]*([.][A-Za-z_]*)?'
2010-06-25 00:27:09
User: zhangweiwu
Functions: find
Tags: find iso9660
1

You might want to check what file and directory names would be renamed or chopped if you create iso 9660 level 2 image out of them. Use this command to check first.