bionpanama.blogg.se

Bash find file size greater than
Bash find file size greater than




In this case we request it to only filter for files.

bash find file size greater than

and -regex which uses regular expression instead of glob to match against filename including path.įor more info on glob and regex read this article or search for "difference glob regex" path matches against the filename and the path to the file. There are several tests that filter agains the "name" of a file: -name matches against the filename regardless of the path to the file. See here for more information about quoting the glob: Otherwise the shell will expand the glob before find gets the arguments and it will execute a completely different command. It works like you would expect in a typical command like for example rm *.tif.īe carefull to put the glob in quotes ( "*.tif"). This test filters the files based on filename. If you just write 160 it will be interpreted as 160*512 bytes. If you want to filter size in bytes (as in 160 bytes instead of 160 kilobytes) then you have to write it like this: 160c. If you want smaller and equal to 160k then do -161k. This is the relevant part for this question. This test filters the files based on size. There is also -ls which will print the files found in a format similar to the command ls. Other common actions are -printf (to print based on custom format) or -exec (to execute a command on the found file). In our case it does not matter because we filtered out directories. As the name says it instructs find to delete the files found.Ī directory will only be deleted if it is empty. for brevity will i will only say "files" from now on instead of "files and directories". ) filter out directories ( -type f) filter by name filter by size and ultimately delete those files. type f -name "*.tif" -size -160k -delete if no explicit action is given then it is default -print (print the filename including path to file). the action then does things with the final result. so the second test gets the result from the first test. then the tests filter the files (and directories) based on some criteria. We start with all files (and all directories) in dirname.

bash find file size greater than

This way you can verify the correct files are to be deleted.Ī typical find command looks like this find dirname -test a -test b -action It will just list the files instead of deleting. This will search for files with filenames matching the glob *.tif and size smaller than 160 kilobytes recursively (in the current directory and all subdirectories) and then delete them. type f -name "*.tif" -size -160k -delete






Bash find file size greater than