last day (15 days later) » 

1:14 PM
9
A: How can I get files using find command

KusalanandaAssuming that the implementation of find on your Unix has the -maxdepth predicate (it's non-standard, but often available), the following find command would do that: find . -maxdepth 1 -type f -mtime +1 This would print the names of the regular files (i.e. not directories, sockets, named pipes...

 
I wonder if maxdepth is an option from the GNU find only?
 
@Jayjargot It's a non-standard option, but frequently implemented (for example on BSD systems that does not use GNU find).
 
sorry but maxdepth is throwing error as "find: bad option -maxdepth"
 
@Anony Please see update.
 
What it actually checks for in update?
 
1:14 PM
@Anony Sorry, I had a typo. There should be a -print at the end. And I don't quite understand your question in your last comment.
 
I didn't understand the new method u put : find . ( -type d ! -name . -prune ) -o -type f -mtime +1 -print. And moreover it is listing the directory name too
 
@Anony Added more explanation.
 
This is working but the directory name is also getting printed
 
@Anony Sorry, what directory name? Do you mean the initial ./ in the pathname to the files? Ok, I'll add something for that.
@Jayjargot I'm interested to know what Unix you are using.
 
Linux myhostname 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
 
1:14 PM
@Jayjargot Your find is GNU find, which has -maxdepth.
 
Sorry for the late reply. The directory which I don't want to include is also getting listed over there
 
@Anony Sorry, "over there"? You have to be more specific. I can't see what you're doing or what you are seeing on your screen. If it helps, edit the question to describe the issues you are having (including exactly what commands you are using). Also note that it helps if you mention what Unix you are using.
 
It is AIX flavour.Suppose I have 3 files and 1 directory inside my folder, /A/B/C. I want to print only file names and not the directory name. lets say the file names are 1.txt, 2.txt, 3.txt. and the folder present is fold. I execute the command given by you and what I am getting is 1.txt 2.txt 3.txt fold I have to take thse filenames as input to compress files, so the folder name should not come in my o/p. And what is the reason maxdepth not working and how to make it work?
 
@Anony What is the exact command you are using? I can't reproduce what you are seeing. To make -maxdepth work, you would need to install a version of find that actually implements this option, for example GNU find.
 
Do you have both sub directories and files inside the folder you are checking in?
 
1:14 PM
@Anony I do, yes, and I test with both new and old directories and files in the directory where I'm running the command. What command are you actually using?
 
1:25 PM
Again: What is the exact command that you are using?
 
1:49 PM
ok so the question is any simple command to do the same?
 
Why would you want another command? What command are you currently using and why does it not do what you want? Note: I can't reproduce your result (which produces a directory name) and I don't know what command you are using, so I can't correct it.
 
Really sorry , i am using the same command which u gave. As it lists some unwanted files too, i need to change the find command to more complicated one. the command is find . ( -type d ! -name . -prune ) -o -type f -mtime +1 -exec basename {} \; which perfeclty lists files
 
2:04 PM
Note that my command uses \( .. \) (escaped parentheses).
Did you see that I also added a variation that compresses files?
(instead of listing them)
You may also want to try putting the bit after -o within \( ... \).
 
sorry i cant go ahead with gzip. but the rest all which i did is same
is there any way to exclude .a files while using find?
 
! -name '*.a'
 

last day (15 days later) »