Commands tagged find (410)

  • find . -type f -iname '*.flac' # searches from the current folder recursively for .flac audio files | # the output (a .flac audio files with relative path from ./ ) is piped to while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done # for each line on the list: # FILE gets the file with .flac extension and relative path # FILENAME gets FILE without the .flac extension # run flac for that FILE with output piped to lame conversion to mp3 using 192Kb bitrate Show Sample Output


    8
    find . -type f -iname '*.flac' | while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done
    paulochf · 2010-08-15 19:02:19 3
  • Just want to post a Perl alternative. Does not count hidden files ('.' ones). Show Sample Output


    8
    perl -le 'print ~~ map {-s} <*>'
    MarxBro · 2012-02-21 21:09:48 4
  • This is the way how you can find header and cpp files in the same time.


    7
    find . -regex '.*\(h\|cpp\)'
    Vereb · 2009-09-06 11:33:19 10
  • Recursively rename .JPG to .jpg using standard find and mv. It's generally better to use a standard tool if doing so is not much more difficult.


    7
    find /path/to/images -name '*.JPG' -exec bash -c 'mv "$1" "${1/%.JPG/.jpg}"' -- {} \;
    sorpigal · 2010-01-07 15:41:17 8
  • .flac is the filetype. /Volumes/Music/FLAC is the destination. Show Sample Output


    7
    find . -iname "*.flac" | cpio -pdm /Volumes/Music/FLAC
    sammcj · 2011-08-02 08:25:21 4
  • this will show the names of the deleted directories, and will delete directories that only no files, only empty directories.


    6
    find . -depth -type d -empty -exec rmdir -v {} +
    grokskookum · 2009-08-05 13:48:13 8
  • You can also use, $ find . -depth -type d -exec rmdir {} \; 2>/dev/null


    6
    find . -type d -empty -delete
    hemanth · 2009-08-22 09:03:14 8

  • 6
    find /backup/directory -name "FILENAME_*" -mtime +15 | xargs rm -vf
    monkeymac · 2009-08-22 16:58:23 6
  • Put the positive clauses after the '-o' option.


    6
    find . -name .svn -prune -o -print
    arcege · 2009-09-04 17:41:33 3

  • 6
    zip -r foo.zip DIR -x "*/.svn/*"
    foob4r · 2009-09-08 14:43:58 8
  • 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| Show Sample Output


    6
    nmap -v -sP 192.168.0.0/16 10.0.0.0/8
    anapsix · 2010-07-14 19:53:02 3
  • With this command you can get a previous or future date or time. Where can you use this? How about finding all files modified or created in the last 5 mins? touch -t `echo $(date -d "5 minute ago" "+%G%m%d%H%M.%S")` me && find . -type f -newer me List all directories created since last week? touch -t `echo $(date -d "1 week ago" "+%G%m%d%H%M.%S")` me && find . -type d -cnewer me I'm sure you can think of more ways to use it. Requires coreutils package. Show Sample Output


    5
    date -d '1 day ago'; date -d '11 hour ago'; date -d '2 hour ago - 3 minute'; date -d '16 hour'
    LrdShaper · 2009-06-01 10:41:56 9
  • This command uses the recursive glob and glob qualifiers from zsh. This will remove all the empty directories from the current directory down. The **/* recurses down through all the files and directories The glob qualifiers are added into the parenthesis. The / means only directories. The F means 'full' directories, and the ^ reverses that to mean non-full directories. For more info on these qualifiers see the zsh docs: http://zsh.dotsrc.org/Doc/Release/Expansion.html#SEC87


    5
    rm -d **/*(/^F)
    claytron · 2009-08-06 21:41:19 9

  • 5
    mysqldump -uUSERNAME -pPASSWORD database | gzip > /path/to/db/files/db-backup-`date +%Y-%m-%d`.sql.gz ;find /path/to/db/files/* -mtime +5 -exec rm {} \;
    nadavkav · 2009-10-28 19:49:39 5
  • The same as the other two alternatives, but now less forking! Instead of using '\;' to mark the end of an -exec command in GNU find, you can simply use '+' and it'll run the command only once with all the files as arguments. This has two benefits over the xargs version: it's easier to read and spaces in the filesnames work automatically (no -print0). [Oh, and there's one less fork, if you care about such things. But, then again, one is equal to zero for sufficiently large values of zero.] Show Sample Output


    5
    find . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) -exec wc -l {} + | sort -n
    hackerb9 · 2010-05-03 00:16:02 7
  • Cleans all files in /tmp that have been accessed at least 2 days ago.


    5
    find /tmp -type f -atime +1 -delete
    mattoufoutu · 2010-05-11 17:08:49 5
  • Some MP3s come with tags that don't work with all players. Also, some good tag editors like, EasyTAG output tags that don't work with all players. For example, EasyTAG saves the genre as a numeric field, which is not used correctly in Sansa MP3 players. This command corrects the ID3 tags in MP3 files using mid3iconv, which comes with mutagen. To install Mutagen on Fedora use "yum install python-mutagen" Show Sample Output


    5
    find -iname '*mp3' -exec mid3iconv {} \;
    schlaegel · 2010-10-29 05:35:46 5
  • -depth argument will cause find to do a "depth first" tree search, this will eliminate the "No such file or directory" error messages


    5
    find . -depth -name .svn -type d -exec rm -fr {} \;
    tebeka · 2010-12-16 17:16:23 4
  • This uses the ability of find (at least the one from GNU findutils that is shiped with most linux distros) to display change time as part of its output. No xargs needed.


    5
    find -printf "%C@ %p\n"|sort
    oivvio · 2013-06-19 10:42:49 10
  • Goes through all files in the directory specified, uses `stat` to print out last modification time, then sorts numerically in reverse, then uses cut to remove the modified epoch timestamp and finally head to only output the last 10 modified files. Note that on a Mac `stat` won't work like this, you'll need to use either: find . -type f -print0 | xargs -0 stat -f '%m%t%Sm %12z %N' | sort -nr | cut -f2- | head or alternatively do a `brew install coreutils` and then replace `stat` with `gstat` in the original command. Show Sample Output


    5
    find . -type f -print0 | xargs -0 stat -c'%Y :%y %12s %n' | sort -nr | cut -d: -f2- | head
    HerbCSO · 2013-08-03 09:53:46 13
  • This is a commodity one-liner that uses ShellCheck to assure some quality on bash and sh scripts under a specific directory. It ignores the files in .git directory. Just substitute "./.git/*" with "./.svn/*" for older and booring centralized version control. Just substitute ShellCheck with "rm" if your scripts are crap and you want to get rid of them :)


    5
    find . -type f ! -path "./.git/*" -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \;
    brx75x · 2017-03-16 08:43:56 24
  • Have a grudge against someone on your network? Do a "find -writable" in their directory and see what you can vandalize! But seriously, this is really useful to check the files in your own home directory to make sure they can't inadvertently be changed by someone else's wayward script.


    4
    find -writable
    kFiddle · 2009-04-11 22:16:35 6
  • find largest file in /var


    4
    find /var -mount -ls -xdev | /usr/bin/sort -nr +6 | more
    mnikhil · 2009-05-16 10:53:55 6

  • 4
    count() { find $@ -type f -exec cat {} + | wc -l; }
    Keruspe · 2009-05-19 15:02:51 9
  • Obviously, you can replace 'man' command with any command in this command line to do useful things. I just want to mention that there is a way to list all the commands which you can execute directly without giving fullpath. Normally all important commands will be placed in your PATH directories. This commandline uses that variable to get commands. Works in Ubuntu, will work in all 'manpage' configured *nix systems. Show Sample Output


    4
    find `echo "${PATH}" | tr ':' ' '` -type f | while read COMMAND; do man -f "${COMMAND##*/}"; done
    mohan43u · 2009-06-13 19:56:24 6
  •  < 1 2 3 4 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

Transfer SSH public key to another machine in one step
This command sequence allows simple setup of (gasp!) password-less SSH logins. Be careful, as if you already have an SSH keypair in your ~/.ssh directory on the local machine, there is a possibility ssh-keygen may overwrite them. ssh-copy-id copies the public key to the remote host and appends it to the remote account's ~/.ssh/authorized_keys file. When trying ssh, if you used no passphrase for your key, the remote shell appears soon after invoking ssh user@host.

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

Read aloud a text file in Mac OS X

Get Hardware UUID in Mac OS X
Formats the output from `ioreg` into XML, then parses the XML with `xmllint`'s xpath feature.

Tracklist reaplace backspace to '-'
Requires perl 5.14 or greater

Download all PDFs from an authenificated website
Replace *** with the appropiate values

Multi-thread any command
For instance: $ find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8 will encode all .wav files into FLAC in parallel. Explanation of xargs flags: -P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage]. -n [max-args]: Max number of arguments from the list to send to each invocation. -0: Stdin is a null-terminated list. I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa

disable caps lock
a quick one-line way to disable caps lock while running X.

Image to color palette generator
Extract a color palette from a image useful for designers. Example usage: $extract-palette myawesomeimage.jpg 4 Where the first argument is the image you want to extract a palette from. The second argument is the number of colors you want. It may be the case where you want to change the search space. In that case, change the -resize argument to a bigger or smaller result. See the ImageMagick documentation for the -resize argument.

Setting reserved blocks percentage to 1%
According to tune2fs manual, reserved blocks are designed to keep your system from failing when you run out of space. Its reserves space for privileged processes such as daemons (like syslogd, for ex.) and other root level processes; also the reserved space can prevent the filesystem from fragmenting as it fills up. By default this is 5% regardless of the size of the partition. http://www.ducea.com/2008/03/04/ext3-reserved-blocks-percentage/


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: