Hi,
I would need to find for files modified more than one day only in the current directory specified and NOT its subdirectories included.
How do I do this?
Hi,
I would need to find for files modified more than one day only in the current directory specified and NOT its subdirectories included.
How do I do this?
you answered your own question.
use the find command.
search the forum for various example like what you are asking.
This is a complex command. And we have some threads with the wrong answer. So I'll do this again....
cd <directory>
find . \( ! -name . -prune \) -type f -mtime +1 -print
can you explain the \( ! -name . -prune \) ? Don't really understand that portion. Prune itself means not finding in its directory, but then ! -name . also means not to find in its own directory, right?
:
:
It means if the name is not ".", do not look inside it. This is to stop "find" from descending into subdirectories.
I think we can force find not to descend more than n levels. Isnt it ?
find . -name "*.c" -maxdepth 1
this will find all the ".c" files in the current directory only. It wont go beyond.
-maxdepth is non-standard...only gnu find has it as far as I know. Yes it will work if you have it.
Hi perdarabo
Thanks for the information. I dont know that till you mentioned and i went onto study what GNU/Linux history is. I learned an important point on this. May be some of you knew it already.
do You guys all know that GNU is an operating system and Linux is the kernal for most of the Linux based systems. Most of the users call it "Linux systems" instead of "GNU/Linux system". GNU is a free software foundation which developed a free UNIX like operating system (which is GNU operating system). Go here if you want to learn more on this.
http://www.gnu.org/gnu/linux-and-gnu.html
Once again thanks perdarabo ....
I learned (from the forum) that the way to non-recursively find a <directory> files is:
cd <directory>
find . \( ! -name . -prune \) -type f -print
But that way outputs a list that starts with ./ for all files, and I need to get a list of full pathnames.
What about the following syntax, assuming <directory> starts with /?
find <directory> \( ! -path <directory> -prune \) -type f -print
It seems to work for me (HP-UX 11.0), but I like to know if it has some hidden traps.
Thanks.
How about replacing "-print" with "-exec print - <directory>/{} \;" ?
Just a thought....
bakunin
find `pwd` \( ! -name . -prune \) -type f -print
Coulnd't you just use the whereis command?
How would I modify this command to match files with a particular name? For example, in my directory I have files of the form costing.M01, costing.M02, etc, but there are also many other files that don't begin with costing*. I need to limit the search to this directory only, ie don't search subdirectories, but only match costing.M* files older than 7 days. 
Thanks, Andie
With gnu find you can:
cd <dir>
find -type f -name "costing.m*" -maxdepth 1
Thanks, but the maxdepth option isn't valid on my system. I am using Sun Solaris 6
You can get gnu find easily for solaris,
anyway as already clearly documented in this thread
cd <dir>
find . \( ! -path . -prune \) -type f -name "costing.M*" -print
Thank you, I had already read the thread and tried the options suggested and they didn't work. I get the output shown below.
� find . \( ! -path . -prune \) -type f -name "costing.M*" -print
find: bad option -path
find: path-list predicate-list
�
Given that I am not able to add non-standard stuff to our unix system, is there a way of doing what I originally asked?
I tested this on solaris 8
cd <dir>
find . \( ! -name . -prune \) -type f -name "costing.M*" -print
Brilliant, thank you very much, that works great. I was having trouble knowing where to put the second 'name' part.