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

most used commands in history (comprehensive)
Most of the "most used commands" approaches does not consider pipes and other complexities. This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ; Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops) note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator

check open ports without netstat or lsof

Move a folder and merge it with another folder
This will move a folder and merge it with another folder which may contain duplicates. Technically it's just creating hardlinks of everything in the folder, and after it's done, delete the source (with rm -r source/ ) to complete the move. This is much faster than, for example, using rsync to merge folders which would actually copy the entire contents and so for a lot of files would take much longer. This uses macutils gcp port of cp so it can be used on osx/MacOS. If using in linux or some unix where cp includes the ability to create links with -l you can just use cp instead of gcp.

download a list of urls

Find the package that installed a command

Generate a random password 30 characters long

Generate a random left-hand password
Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.

vi a new file with execution mode
$ vix /tmp/script.sh Open a file directly with execution permission. Put the function in your .bashrc You can also put this in your vimrc: $ command XX w | set ar | silent exe "!chmod +x %" | redraw! and open a new file like this: $ vi +XX /tmp/script.sh

Extract tarball from internet without local saving

Swap a file or dir with quick resotre
This lets you replace a file or directory and quickly revert if something goes wrong. For example, the current version of a website's files are in public_html. Put a new version of the site in public_html~ and execute the command. The names are swapped. If anything goes wrong, execute it again (up arrow or !!).


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: