0

tried to print all the files in the current directory using

find .  -newer myfile -mtime +3 ! -name . -prune 

but it is also printing the files in the sub directories tried to read related post here :

How to use '-prune' option of 'find' in sh?

but did not understand but tried

find . -newer myfile -mtime +3 ! -name . -prune -o -print 

this also did not bring what I wanted also tried

find . -type f  -newer myfile -mtime +3 ! -name . -prune 

but this is bringing all .snapshots sub directories in the output recursively. Please tell me how can I avoid all sub directories in the out put using prune.

OUTPUT

find .  -newer myfile -mtime +3 ! -name . -prune

./.snapshot/hourly.7/file_status_out.txt
./.snapshot/hourly.1/file_status_out.txt
./.snapshot/hourly.6/file_status_out.txt
./.snapshot/hourly.5/file_status_out.txt
./.snapshot/nightly.0/file_status_out.txt
./.snapshot/hourly.0/file_status_out.txt
./.snapshot/hourly.4/file_status_out.txt
./.snapshot/hourly.2/file_status_out.txt
./.snapshot/hourly.3/file_status_out.txt
./.snapshot/nightly.2/file_status_out.txt
./.snapshot/nightly.1/file_status_out.txt
./.snapshot/veritas.nfs01p_vol1/file_status_out.txt
./.snapshot/weekly.0/file_status_out.txt
./.snapshot/lonnf30060(1874649454)_nfs01p_vol1.58917/file_status_out.txt
./.snapshot/lonnf30060(1874649454)_nfs01p_vol1.58916/file_status_out.txt
./.snapshot/dfpm_base(dataset-id-225039)conn1.0/file_status_out.txt
./file_status_out.txt
Vicky
  • 1,150
  • 10
  • 25
  • 1
    I dont get you. What are you trying to accomplish? If you do not want find files in subdirectories just add "-maxdepth 1" flag. – Matias Barrios Oct 03 '17 at 13:14
  • I have edited so that it makes more sense , with my actual purpose – Vicky Oct 03 '17 at 13:21
  • Please list some example files (name and relative path) and wether you want them to be found or not and why. – Yunnosch Oct 03 '17 at 13:38
  • Please, explain what you intend to achieve with the `!´. – Yunnosch Oct 03 '17 at 13:39
  • I want to find out all the files that are newer than myfile() but older than 3 days in the current directory (not in any of the sub directories) – Vicky Oct 03 '17 at 13:49
  • I have shown the output of my command , I cannot understand why the command is descending to .snapshot directories even if all the subdirectories are pruned in the command – Vicky Oct 03 '17 at 13:55
  • As Martias says.....just use -maxdepth 1 – Raman Sailopal Oct 03 '17 at 13:58
  • `find . -maxdepth 1 -newer myfile -mtime +3 ! -name . -prune | xargs ls -l` find: bad option -maxdepth seems like maxdepth is not supported on my unix `uname -v` Generic_118833-36 – Vicky Oct 03 '17 at 14:00

1 Answers1

0

It depends on the last modification time of "myfile", implicitly find does a -and or -a with the expressions, so the paths to prune are (directory files) newer than myfile -newer myfile and -mtime +3 with last modification time greater than 3 days, this may be not possible if myfile is more recent than 3 days.

Another solution to prune directories if -maxdepth is not supported

find . ! -name . -type d -prune -o -print

specific condition can be added after -o

find . ! -name . -type d -prune -o -newer myfile -print

update following comments, it seems conditions are not added at the right place:

find . ! -name . -type d -prune -o -newer myfile -mtime +1 -print

conditions before -prune are to filter subdirectories (type d except . otherwise would return nothing), conditions after -o are to filter files to -print or to -ls depending the last argument

Nahuel Fouilleul
  • 16,821
  • 1
  • 26
  • 32
  • details of myfile is `-rw------- 1 xxxx xxxx 0 Sep 29 00:00 myfile` command you have given `find . ! -name . -type d -prune -o -newer myfile -print` also bring file which are not older than 3 days as it prints files modified today and yesterday. I also did not understand why you have used `-o` for OR I want to print file that satisfy `-and`. Things become worst when I do `find . ! -name . -type d -prune -o -newer myfile -print | xargs ls -l` as this seems to long list everything – Vicky Oct 03 '17 at 14:16
  • `-o` is needed after `-prune` to bypass false for files not pruned – Nahuel Fouilleul Oct 03 '17 at 14:28
  • your comments confirm my answer `-mtime +3` and `-newer myfile` can't be true because Sep 29 was exactly 3 days before now – Nahuel Fouilleul Oct 03 '17 at 14:32
  • it still prints those snapshots if I make it `mtime +1` in that command – Vicky Oct 03 '17 at 14:34
  • where did you add -mtime +1 – Nahuel Fouilleul Oct 03 '17 at 14:36
  • `find . -newer myfile -mtime +1 ! -name . -prune` – Vicky Oct 03 '17 at 14:37
  • this looks better I did `find . ! -name . -type d -prune -o -newer myfile -mtime +1 -print | xargs ls -l` which brings output ` `-rw------- 1 xxxx xxxx 22564 Sep 29 22:16 ./.bash_history -rw------- 1 xxxx xxxx 0 Sep 29 14:11 ./file_status_out.txt -rw------- 1 xxxx xxxx 922 Sep 29 18:10 ./filefile.txt -rwxrwxrwx 1 xxxx xxxx 1409 Sep 29 18:10 ./formatperl.pl -rwx------ 1 xxxx xxxx 1408 Sep 29 18:17 ./formatperl2.pl -rwx------ 1 xxxx xxxx 1402 Sep 29 18:22 ./formatperl3.pl -rw------- 1 xxxx xxxx 0 Oct 1 00:00 ./myfile1` – Vicky Oct 03 '17 at 14:48
  • I guess bu default it will aslo match hidden files so `./.bash_history` is in the out put and also it does not print file of Oct 2 `-rw------- 1 xxxx xxxx 1354656 Oct 2 12:20 jobs2 -rwxrwxrwx 1 xxxx xxxx 396 Oct 2 14:34 perlfor.pl` command ran as of `Tue Oct 3 15:46:35 BST 2017` – Vicky Oct 03 '17 at 14:50