Is there a way to find all files that have been modified the last x days from a specific directory? I have done this
find /home/user -iname "*.txt" -mtime -$x -print
but it shows the files from user not from the directory.
the content of the directory is:
total 8
-rw------- 1 danae danae 0 Jun 21 22:08 a
dr-x------ 2 danae danae 4096 Jun 30 10:56 d
-rw------- 1 danae danae 0 Jun 30 10:56 file
-rw-rw---- 1 danae danae 8 Jun 29 13:03 file2
-rw-rw---- 1 danae danae 0 Jun 21 22:06 file3
-rwxrwx--x 1 danae danae 0 Jun 21 22:06 file4
-r-------- 1 danae danae 0 Jun 21 22:07 file5
-rw-rw-r-- 1 danae danae 0 Jun 21 22:07 file6
The issue with your current command
find /home/user -iname "*.txt" -mtime -$x -print
Is "/home/user" which is telling find to always look in that directory.
This should be replaced with the directory you want to look in. Or if you are doing this within a bash script first cd
to the directory and then use
find . -iname "*.txt" -mtime -$x -print
Use . to indicate the current directory:
find . -iname "*.txt" -mtime -$x -print
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.