
We want to start getting some results as soon as possible, even though it’ll take more time to get all the results.Running the tool on so many files at once might use up too much memory. Finding a file requires some criteria a part of the file name, a file type, permissions on the file, etc.The tool run by -exec doesn’t accept multiple files as an argument.However, we may prefer using the semi-colon delimiter in one of the following cases: Gustav Mahler/05 - Der Trunkene im Frühling.mp3įrom a performance point of view, we usually prefer to use the plus-sign delimiter, as running separate processes for each file can incur a serious penalty in both RAM and processing time. Gustav Mahler/04 - Von der Schönheit.mp3 Gustav Mahler/02 - Der Einsame im Herbst.mp3 Gustav Mahler/01 - Das Trinklied vom Jammer der Erde.mp3 We can achieve this by running the following command: $ find Music/ -name *.mp3 -exec file \ Let’s say we want to run the file command on the list of mp3 files we just found to determine their filetype. In contrast, the -exec action allows us to execute commands on the resulting paths. It’ll run if no other action is specified. This action prints the resulting paths with newline characters in between.

The action part in this example is the default action, -print. This command will result in a list of mp3 files in the Music directory and all its subdirectories. Music/Gustav Mahler/06 - Der Abschied.mp3 Music/Gustav Mahler/05 - Der Trunkene im Frühling.mp3 Music/Gustav Mahler/04 - Von der Schönheit.mp3 Music/Gustav Mahler/03 - Von der Jugend.mp3 Music/Gustav Mahler/02 - Der Einsame im Herbst.mp3 It also doesn't have problems with file names containing quotes or apostrophes.Music/Gustav Mahler/01 - Das Trinklied vom Jammer der Erde.mp3 The syntax is almost indentical to xargs, except it runs in parallel. Note: a modern replacement for xargs is GNU parallel. print0 | xargs -0 -l -i echo ".png" Use GNU Parallel for xargs Use “find” on file names that may contain spaces or dash # print file names that may contain spacesįind. Xargs is a command that is used together with find to allow you to call arbitrary unix commands on list of files. The advantage of using -exec is that you can call any unix command, not just options supported by find. When you use -exec, it actually spawn process to run the shell command for each file. Using the -delete option is much faster because it doesn't spawn processes. # delete all files whose name ends with ~ # list files whose file status changed in last 60 min # list files that has been opened (accessed) in last 60 min

# list files whose file content is modified in last 60 min # list files whose content have been modified within past 2 days depth -empty -type d -delete Find Recently Modified File

depth -empty -type d # delete empty dirsįind. type f -empty -delete Delete empty dirs # list empty dirsįind. type f -empty # delete all empty filesįind. Delete empty files # list all empty filesįind. Make sure you test first without -delete, and make sure -delete is the last argument. (By default, directory is processed before its content.)īe very careful when using -delete.

-depth means process directory's content before the directory.Delete all files, name matches a text pattern # delete all files, name ends with ~ size -9k # list files exactly 1234 bytes size +9M # list files smaller than 9 kibi bytesįind. List only files larger than n bytes # list files larger than 9 mibi bytesįind. List files whose name matches a text pattern # list files ending in.
