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 - 354 results
find . -maxdepth 1 -type f | wc -l
find ~/path/to/apk/files -name '*.apk' -exec adb install {} \;
2012-02-16 03:59:44
Functions: find install
Tags: find adb
0

You must have the android sdk installed with 'adb' executable on your system. This is just a way to loop over files in a folder using 'find' to locate and install android apps.

diff --suppress-common-lines -y <(cd path_to_dir1; find .|sort) <(cd path_to_dir2; find .|sort)
2012-02-13 12:49:33
User: knoppix5
Functions: cd diff find
2

Output of this command is the difference of recursive file lists in two directories (very quick!).

To view differences in content of files too, use the command submitted by mariusbutuc (very slow!):

diff -rq path_to_dir1 path_to_dir2
find . ! -name "*.tar.gz"
find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar`
2012-02-03 16:24:08
User: 0disse0
Functions: find tar xargs
1

Finally, we can make the file "unchangeable"

sudo chattr +i

find . | grep -E "(\||\\|\?|\*|<|\"|:|>)"
2012-01-21 17:59:20
User: dj_bushido
Functions: find grep
0

Find all files under "." that are invalid NTFS filenames. Find locates all files, and grep shows the invalid ones.

find . | grep -E "(\||\\|\?|\*|<|\"|:|>|\+|\[|\])"
2012-01-21 17:54:58
User: dj_bushido
Functions: find grep
0

Find is used to "find" all filenames - grep shows those that are invalid.

find . -perm 777 ?print
2012-01-21 10:20:52
User: javabuddy
Functions: find
Tags: find
0

I use this find command example to find out all the executable files you can modify it to find readonly file as well.

find ./ -type f -size +100000k -exec ls -lh {} \; 2>/dev/null| awk '{ print $8 " : " $5}'
2012-01-21 04:19:35
User: Goez
Functions: awk find ls
0

This command does a basic find with size. It also improves the printout given (more clearer then default)

Adjusting the ./ will alter the path.

Adjusting the "-size +100000k" will specify the size to search for.

find /etc/ /pentest/ -type f -iname "*sql*" | grep map
2012-01-15 13:30:32
User: celalerdik
Functions: find grep
Tags: find grep
0

you can find a special things(with defined -iname "*sql*") from in most of one direcroty(for example from both /etc/ and /pentest/) and then you can want to grep only include "map" word

find /pentest/ -type f -iname "*trace*"
2012-01-14 20:43:30
User: celalerdik
Functions: find
Tags: find
0

you can find all "trace" phrases within everywhere else under the pentest directory..

find . -type f|perl -lne '@x=sort {$b->[0]<=>$a->[0]}[(stat($_))[7],$_],@x;splice(@x,11);print "@{$x[0]}";END{for(@x){print "@$_"}'
2012-01-08 14:43:43
User: bazzargh
Functions: find perl
Tags: sort perl find
-2

A different approach to the problem - maintain a small sorted list, print the largest as we go, then the top 10 at the end. I often find that the find and sort take a long time, and the large file might appear near the start of the find. By printing as we go, I get better feedback. The sort used in this will be much slower on perls older than 5.8.

find $(pwd) -maxdepth 1 -name "*" -printf "%p\n"
find `pwd` -type f \( -iname thumb.php -or -iname timthumb.php \) -exec grep -HP 'define ?\(.VERSION' {} \;
2011-12-27 11:33:54
User: djkee
Functions: find grep
-3

Good for finding outdated timthumb.php scripts which need to be updated, anything over 2.0 should be secure, below that timthimb is vulnerable and can be used to compromise your website.

find `pwd` -maxdepth 1 -exec ls --color -d {} \;
find -iname "*.pdf" -exec pdfinfo -meta {} \;|awk '{if($1=="Pages:"){s+=$2}}END{print s}'
2011-12-13 15:02:11
User: Barabbas
Functions: awk find
Tags: awk find pdf count sum
0

This sums up the page count of multiple pdf files without the useless use of grep and sed which other commandlinefus use.

mplayer -endpos 0.1 -vo null -ao null -identify *.avi 2>&1 |grep ID_LENGTH |cut -d = -f 2|awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 wc -l | tail -1
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -exec cat {} \;|wc -l
2011-12-01 19:58:52
User: kerim
Functions: cat find wc
-4

Count your source and header file's line numbers

For example for java change the command like this

find . -name '*.java' -exec cat {} \;|wc -l

find . -type f -exec awk '/linux/ { printf "%s %s: %s\n",FILENAME,NR,$0; }' {} \;
find `pwd` -name '.*' -prune -o \( -name *.h -o -name *.cpp \) -print | cscope -bi-
2011-11-02 08:43:40
User: kev
Functions: find
Tags: find cscope
-2

cd /

find `pwd` -name '.*' -prune -o \( -name *.h -o -name *.cpp \) -print | cscope -bi-

export CSCOPE_DB=/cscope.out

vim +'set cst'

find . ! -name "$(printf '*[\001-\037\177]*')"
grep -Ilr "<?php" .
for i in /usr/bin/* ;do touch ${i##*/}; done
2011-10-20 12:38:45
User: _john
Functions: touch
Tags: bash find xargs zsh
0

You could avoid xargs and sed in this case (shorter command and less forking): At least bash and zsh have some mighty string modifiers.

I would also suggest using find with exec option to get more flexibility. You may leave out or include "special" file for example.