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 using find from sorted by
Terminal - Commands using find - 1,012 results
find . -type f -exec grep -Hn <pattern> {} \;
sudo find . -name "*.csv" | xargs /bin/rm
2012-08-29 11:38:37
User: defc0n1
Functions: find sudo xargs
0

In case you ever got to many arguments using rm to delete multiple files matching a pattern this will help you

find . -name vmware-*.log -exec rm -i {} \;
find . -type f | xargs -I% bash -c 'echo -e "\033[31m%\033[0m" && [[ ! `file %` =~ .*binary.* ]] && head "%"'
touch -t 201208211200 first ; touch -t 201208220100 last ; find /path/to/files/ -newer first ! -newer last | xargs -ifile mv -fv file /path/to/destination/ ; rm first; rm last;
2012-08-22 09:51:40
User: ktopaz
Functions: file find last mv rm touch xargs
0

touch -t 201208211200 first ; touch -t 201208220100 last ;

creates 2 files: first & last, with timestamps that the find command should look between:

201208211200 = 2012-08-21 12:00

201208220100 = 2012-08-22 01:00

then we run find command with "-newer" switch, that finds by comparing timestamp against a reference file:

find /path/to/files/ -newer first ! -newer last

meaning: find any files in /path/to/files that are newer than file "first" and not newer than file "last"

pipe the output of this find command through xargs to a move command:

| xargs -ifile mv -fv file /path/to/destination/

and finally, remove the reference files we created for this operation:

rm first; rm last;

find . -type f -size -80k -delete
find $(locate hello) -type f -executable -print|grep -E "hello\$"
2012-08-18 07:51:53
Functions: find grep locate
-1

This command allow you quick find any executable by keyword(s) in your system.

NOTE: Sometime this command will output like this:

`hello.py.launch': No such file or directory

this is normal behaviour

find . -name ".svn" -type d -exec rm -rf {} \;
2012-08-16 13:04:47
User: gigo6000
Functions: find rm
Tags: svn git rm
-2

This is useful when you are uploading svn project files to a new git repo.

find . -cnewer <file a> -and ! -cnewer <file b>
2012-08-15 21:57:42
User: rdc
Functions: find
Tags: find
1

This command finds all the files whose status has changed between the ctime of the older and newer .

Very useful if you can see from an ls listing a block of consecutive files you want to move or delete, but can't figure out exactly the time range by date.

ff() { find -maxdepth 3 -type f -iname "$1"; }; fd() { find -maxdepth 4 -type d -iname "$1"; }
2012-08-15 15:04:48
User: plasticboy
Functions: find
Tags: find simple
-1

These should be a little faster since they don't have to spawn grep.

ff() { find -maxdepth 3 -type f | grep -i "$1"; }; fd() { find -maxdepth 4 -type d | grep -i "$1"; }
find . -type f -exec file '{}' + | grep shell | awk -F':' '{print $1}' | xargs chmod u+x
2012-08-09 18:53:08
User: llebegue
Functions: awk chmod file find grep xargs
0

Allows to change 'shell' compatible files execution bit even if their name is not *.sh

find . -type f -name "*.sh" -exec chmod u+x {} \;
find ./ -empty -type d -delete
find ./ -empty -type d -print
find ./ -maxdepth 1 -empty -type d -delete
find ./ -maxdepth 1 -empty -type d -print
find Files/ -type d | parallel 'mkdir -p /BKP/{}' && find Files/ -type f | parallel 'rsync -a {} MKD/$(dirname {})'
2012-08-08 21:01:37
User: phribbr
Functions: dirname find
0

Copy files and dir in parallel. It is Faster.

Using the gnu-parallel.

Has 2 commands:

- First - Create dir structure in /BKP

find Files/ -type d | parallel 'mkdir -p /BKP/{}'

- Second - Copy for structure created

find Files/ -type f | parallel 'rsync -a {} /BKP/$(dirname {})'

- Great for backups!

- Can use "rsync" or "cp".

- Compare with a simple "rsync" or "cp"!

ls -il; find * \( -type d -prune \) -o -inum <NUM> -exec rm -i {} \;
2012-08-04 00:22:33
User: yingw
Functions: find ls rm
0

Code to delete file with gremlins/special characters/unicode in file name.

Use ls -i to find the INODE number corresponding to the file and then delete it using that find statement.

detailed here:

http://www.arsc.edu/arsc/support/howtos/nonprintingchars/

find . -type f -exec ls -l --full-time {} + | sort -k 6,7
2012-08-03 22:22:51
User: quadcore
Functions: find ls sort
Tags: sort find ls
2

This sorts files in multiple directories by their modification date. Note that sorting is done at the end using "sort", instead of using the "-ltr" options to "ls". This ensures correct results when sorting a large number of files, in which case "find" will call "ls" multiple times.

for folder in $( find $( pwd ) -maxdepth 1 -type d | grep -v .svn ); do svn propset svn:ignore -F ignorelist ${folder}; done
2012-08-03 13:50:45
User: Highwayman
Functions: find grep pwd
Tags: bash
0

To use this comment you'll have to create a file entitled 'ignorelist' where you put the file name or pattern of the files you want to ignore. I used it for my maven project which generates the child project files in each folder so I can import them into eclipse. By adding these project files to the ignore list ensure they won't appear each time I run 'svn status'.

find . -type f -exec du -sh {} + | sort -hr | head
find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {} +
find path -name '*' -type f | pax -wd > txtarchive.tar
2012-07-29 00:44:51
User: bugmenot
Functions: find pax
0

NOTE that pax goes always recursively, for that reason -d option should be added when you don't want to go recursively into directories.