Bash - find files older than X minutes and move them [duplicate] - linux

This question already has answers here:
find files older than X days in bash and delete
(3 answers)
Closed 7 years ago.
I need to create a bash script and put in CRON - on linux.
I need to loop through or just find all files in directory DIR_A and if files are older than, for example, 10 minutes, move them to directory DIR_B.
Any ideas? Thanks!

If anyone else needs it:
find DIR_A -maxdepth 1 -type f -mmin +10 -exec mv "{}" DIR_B/ \

Related

How to get deleted files into a log file. Bash script [duplicate]

This question already has answers here:
Linux find and delete files but redirect file names to be deleted
(5 answers)
Closed 1 year ago.
So im using the script
find /path/to/files/* -mtime +60 -exec rm {} \;
How can i collect the deleted files and transfer them into a logfile in Bash script
You could do something like:
find /path/... -print ... | tee -a <log.file>
The -print will print out all the hits, and the tee will append that to some log.file.
Side note: the * at the end of your /path/to/files/* seems superfluous.
Side note2: if you just want to delete the files, find has a built-in -delete.

Delete files older than 7 days in perl [duplicate]

This question already has answers here:
delete folders older than 12 hours in perl
(3 answers)
Closed 5 years ago.
How to delete files from directories who are older than certain days (7 days) OR files who was created on any certain date?
Be careful with special file names (spaces, quotes) when piping to rm.
There is a safe alternative - the -delete option:
find /path/to/directory/ -mindepth 1 -mtime +5 -delete
That's it, no separate rm call and you don't need to worry about file names.
Replace -delete with -depth -print to test this command before you run it (-delete implies -depth).

How to copy the results of a find command in linux [duplicate]

This question already has answers here:
Moving multiple files having spaces in name (Linux)
(3 answers)
Closed 7 years ago.
I have a find command which returns two files. Is there anyway of then copying those files to another directory? My find command is below if that will help.
find "$TEST" -iname "DTWD_????.JPG" -printf "%f\n"
New to linux, thanks.
You just need to use the -exec argument
find "$TEST" -iname "DTWD_????.JPG" -printf "%f\n" -exec mv -t '/home' '{}' +

How to find both files and folders that are used in some process? [duplicate]

This question already has answers here:
Delete files older than 10 days using shell script in Unix [duplicate]
(3 answers)
Closed 7 years ago.
I want to delete files and folders older than 15 days.
But Before deletion I want to check that those file and folders shouldn't use anywhere. How can i do that ?
is ps -ef works for this ?
Using the find command:
find /path/to/folder -type f -mtime +15 -delete

delete all files within a directory that are older than 1 day [duplicate]

This question already has answers here:
How to delete files older than X hours
(9 answers)
Closed 9 years ago.
I need to ensure that I have no old files left in my directory so what I think I do is
find . -type f -mtime +1 -delete
i got that from the find man page but then
find . -type f -mtime +1 -exec /bin/rm
but again, now told that find: -exec requires an argument - didn't iI pass this. So I started Googling and I found that my command needs to look likee this:
find . -type f -mtime +1 -exec /bin/rm -f {} +
and now I'm just wondering what the two {} s and the + sign are for. Can anyone help me here?
Thanks!
The {} stands for the name of the file(s) found.
The + sign (instead of a ;) means that this command accepts multiple file names in the same command, so that find can run much faster because it is run less times. The number of files added to each execution of the command is limited by the maximum length of the command line find is willing to use.

Resources