find -mmin -19 -exec rm '{}'\;
It will find the modified files 1st and then remove them. but it gives me error as below, find: missing argument to `-exec'
Also tried various combinations like,
find -mmin -19 -exec rm '{}';\
find -mmin -19 -exec rm '{}'/;
To remove (or delete) a file in Linux from the command line, use either the rm (remove) or unlink command. The unlink command allows you to remove only a single file, while with rm , you can remove multiple files at once.
Use the rm command to remove files you no longer need. The rm command removes the entries for a specified file, group of files, or certain select files from a list within a directory. User confirmation, read permission, and write permission are not required before a file is removed when you use the rm command.
Deleting multiple files To delete multiple files at once, simply list all of the file names after the “rm” command. File names should be separated by a space. With the command “rm” followed by multiple file names, you can delete multiple files at once.
However, the rm command does not support search criteria. For example, find all “*.bak” files and delete them. For such necessities, you need to use the find command to search for files in a directory and remove them on the fly. You can combine find and rm command together.
Remove a file with rm Simplest form of this command is rm . So if we have a file called try1: Removing multiple files is done by either listing the files as separate command line parameters to rm:
Modern version of find command has -delete option too. Instead of using the -exec rm -rf {} \;, use the -delete to delete all matched files.
For example, find all “*.bak” files and delete them. For such necessities, you need to use the find command to search for files in a directory and remove them on the fly. You can combine find and rm command together.
You need space between the command and \;
find -mmin -19 -exec rm {} \;
find
already provide -delete
option, so you don't need to use -exec rm ..
:
find -mmin -19 -delete
-delete
Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.
Warnings: Don't forget that the find command line is evaluated as an expression, so putting -delete first will make find try to delete everything below the starting points you specified. When testing a find command line that you later intend to use with -delete, you should explicitly specify -depth in order to avoid later surprises. Because -delete implies -depth, you cannot usefully use -prune and -delete together.
You're missing an essential space to separate the braces from the semicolon.
find -mmin -19 -exec rm '{}' \;
but this does the same ting, is easier to type, and probably executes faster.
find -mmin -19 -delete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With