How can I find files in Linux that were not accessed for X days?
I found that command, but it will show files that were viewed for the last x days:
$ find /home/you -iname "*.pdf" -atime -60 -type -f
Use -atime +60 to see files that have not been accessed within the last 60 days:
find /home/you -iname "*.pdf" -atime +60 -type f
Related
I'm trying to run an auto-delete script to free up space on a remote server.
The command I'm thinking to use is:
find . -atime +30 -mtime +30 -type f -delete
What I want is to also capture which files were successfully deleted and which failed because of access issue. How should I do this? I think this command below might take care of the failures only, but I'm not sure.
find . -atime +30 -mtime +30 -type f -delete 2>failed_deletions.txt
find out of the box does not print the files it processes. If you want to list the files, add a -print or -ls before the -delete.
This obviously prints all the files it processes, including the ones it fails to delete for whatever reason.
Redirecting standard output to a different file should be trivial to discover; command >stdout 2>stderr
The final command would become
find . -atime +30 -mtime +30 -type f \
-print -delete >success.txt 2>errors.txt
Less performant, but should do what you wanted:
find . -atime +30 -mtime +30 -type f -exec rm -v {} \; >successful.txt 2>failed.txt
Given the below linux directory structure, how would I skip each excluded directory, (/assess), to remove files older than 30 days for the rest of the entire directory structure?
Thanks for your assistance...
/mnt/nfsmountpoint/location1/appliance1
/assess
/discover
/bkup
/mnt/nfsmountpoint/location1/appliance2
/assess
/discover
/bkup
etc...
I cobbled together an answer and proofs:: (my asterisks * are not showing sorry)
Run from the /mnt/nfsmountpoint/ directory.
find .// -not -path "/assess/" -type f -mtime +30 -delete
validate::
Does it skip the directory?:
find .// -not -path "/assess/" -type f -mtime +30 -ls|more
Verify no current month (January 2021) files included?:
find .// -not -path "/assess/" -type f -mtime +30 -ls|grep Jan
How much space is made free?:
find .// -not -path "/assess/" -type f -mtime +30 -print0 | du --files0-from=- hc | tail -n1
find /path/to/dir -mtime +30 -type f -not -name "*assess*" -delete
Find files (-type f) in /path/to/dir as well as children directories. Specify only files that have been modified more than 30 days ago (-mtime +30) and do not include files that contain "assess" (-not -name "assess")
how can i find all files that were not accessed in the last 10 days with extension ".png"?
This is a question of my homework but i'm not getting it right
I tried find / -type f -mtime -10 -name "*.png" but it's not right
You should use -atime for access time and +10 for greater than 10 days:
find / -type f -atime +10 -name "*.png"
I have been searching but I cannot find a way to essentially do the following in 1 line at Linux, so as to find files and directories that are more than 30 days old, starting the recursive search from script_dir:
cd $script_dir
find . -type f -or -type d -mtime +30
If I do not do the cd to change to directory that I need to start searching from recursively (and use directly only the find), then, although I specify the script_dir at find the recursive search starts from the directory I am currently and NOT from the script_dir and beneath this directory. I want to do something like the following and even if I am currently at other directory than script_dir, the recursive search to start from script_dir:
find $script_dir -type f -or -type d -mtime +30
Thank you.
In one line, you can do like this :
cd /path/to/directory && find . -type f -or -type d -mtime +30
that do the search from the specified directory
I can find the files in a directory which changed the last 4 minutes with the command:
find ~ -type f -mmin -4
how could I find the files which have not changed the last X minutes?
thanks.
find ~ -type f -mmin +4
sweet, not?
With !, which may need escaping in your shell.
find ~ -type f \! -mmin -4