FIND - Exec: Difference between revisions
From Wiki.IT-Arts.net
(Created page with "Category:Post-It == grep --help == The basic syntax to execute find with exec : <nowiki> find [path] [arguments] -exec [command] {} \;</nowiki> === List Files === <nowiki> find /home/user/ -type f -name *.txt -exec ls -l {} \;</nowiki> === Remove By Size === Files larger than 500 MB : <nowiki> find /home/user/ -size +500M -exec rm {} \;</nowiki> === Remove By Date === Files older than 10 days <nowiki> find /home/user/ -type f -mtime +10 -exec r...") |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Post-It]] | [[Category:Post-It]] | ||
== find + exec == | |||
== | |||
The basic syntax to execute find with exec : | The basic syntax to execute find with exec : | ||
Line 12: | Line 10: | ||
== List Files == | |||
<nowiki> | <nowiki> | ||
Line 19: | Line 17: | ||
== Remove By Size == | |||
Files larger than 500 MB : | Files larger than 500 MB : | ||
Line 25: | Line 23: | ||
<nowiki> | <nowiki> | ||
find /home/user/ -size +500M -exec rm {} \;</nowiki> | find /home/user/ -size +500M -exec rm {} \;</nowiki> | ||
* size n[cwbkMG] | |||
** File uses less than, more than or exactly n units of space, rounding up. The following suffixes can be used: | |||
*** `b' for 512-byte blocks (this is the default if no suffix is used) | |||
*** `c' for bytes | |||
*** `w' for two-byte words | |||
*** `k' for kibibytes (KiB, units of 1024 bytes) | |||
*** `M' for mebibytes (MiB, units of 1024 * 1024 = 1048576 bytes) | |||
*** `G' for gibibytes (GiB, units of 1024 * 1024 * 1024 = 1073741824 bytes) | |||
== Remove By Date == | |||
Files older than 10 days | Files older than 10 days | ||
Line 35: | Line 42: | ||
find /home/user/ -type f -mtime +10 -exec rm {} \;</nowiki> | find /home/user/ -type f -mtime +10 -exec rm {} \;</nowiki> | ||
* mtime n | |||
** File's data was last modified less than, more than or exactly n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times. | |||
* -atime n | |||
** File was last accessed less than, more than or exactly n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago. |
Latest revision as of 10:12, 9 June 2024
find + exec
The basic syntax to execute find with exec :
find [path] [arguments] -exec [command] {} \;
List Files
find /home/user/ -type f -name *.txt -exec ls -l {} \;
Remove By Size
Files larger than 500 MB :
find /home/user/ -size +500M -exec rm {} \;
- size n[cwbkMG]
- File uses less than, more than or exactly n units of space, rounding up. The following suffixes can be used:
- `b' for 512-byte blocks (this is the default if no suffix is used)
- `c' for bytes
- `w' for two-byte words
- `k' for kibibytes (KiB, units of 1024 bytes)
- `M' for mebibytes (MiB, units of 1024 * 1024 = 1048576 bytes)
- `G' for gibibytes (GiB, units of 1024 * 1024 * 1024 = 1073741824 bytes)
- File uses less than, more than or exactly n units of space, rounding up. The following suffixes can be used:
Remove By Date
Files older than 10 days
find /home/user/ -type f -mtime +10 -exec rm {} \;
- mtime n
- File's data was last modified less than, more than or exactly n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
- -atime n
- File was last accessed less than, more than or exactly n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.