Computing.Net > Forums > Unix > find files in current dir ONLY

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

find files in current dir ONLY

Reply to Message Icon

Name: Arne Matthijssen
Date: April 1, 2003 at 17:30:32 Pacific
OS: unknown
CPU/Ram: unknown
Comment:

Hi,

I need to pick up files older than 5 days and then do something (move them, actually).

This works fine with the find command. However i do NOT want to look in the subdirectories - how can i prevent the find command from looking there?

If that is impossible, is there an alternative approach???

Thanx



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: April 1, 2003 at 18:29:48 Pacific
Reply:

try 'man find'

take a look at the 'maxdepth' option. Looks to me like that is what you are looking for.


0

Response Number 2
Name: Arne
Date: April 1, 2003 at 18:38:23 Pacific
Reply:

I am using bash 2.03; that option seems not to be available here?

Any other suggestions?

Thanx, Arne


0

Response Number 3
Name: nails
Date: April 1, 2003 at 20:15:27 Pacific
Reply:

Arne:

If you don't have maxdepth, try this:

# find all on one line
find . -type f|awk ' gsub("^./","") '|egrep -v "/"

provided you execute find in the current directory, find returns files in the form:

./directorypath/filename
./fileinhere

Pipe the find command to awk to rid yourself of the beginning ./ and pipe that to egrep to eliminate anything that has a directory / in it.

This is terribly inefficient because find still is forced to check the directory structure. If you use Solaris, use nawk instead of awk.

Maybe somebody smarter than 1 can come up with a better idea.

Regards,


Nails


Also something like:

find /tmp -type f .....

for obvious reasons.

Regards,


Nails


0

Response Number 4
Name: Arne
Date: April 1, 2003 at 20:31:26 Pacific
Reply:

Thank you, this is indeed an alternative, especially since the underlying directory structure is rather limited.

But... Using find seems a bit heavy for the task... Would there be alternatives where the find command is not used altogether?

E.g., can we process the timestamp of a file directly as a date, say, after an ls? In that case we would not need the -m option of the find command.

thanx for your help.


0

Response Number 5
Name: WilliamRobertson
Date: April 2, 2003 at 08:25:07 Pacific
Reply:

Well, if directories never have an extension and files always do:

find ./*.* -mtime +5

That's a bit of an assumption though.

The -prune option has always looked promising but I could never figure out from the man pages exactly what it does.


0

Related Posts

See More



Response Number 6
Name: Arne
Date: April 2, 2003 at 10:04:28 Pacific
Reply:

hm. Prune is not supported in bash (or do i miss something here) and find ./*.* still doesnt seem to work in bash either?

bash-2.03$ find ./ -type f -mtime -1 -print
./rd/found
bash-2.03$ find ./*.* -type f -mtime -1 -print
find: cannot open ./*.*: No such file or directory

(even though a file was in there)

thanx


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: find files in current dir ONLY

Comparing all files in current dir www.computing.net/answers/unix/comparing-all-files-in-current-dir/4102.html

find files in specific date www.computing.net/answers/unix/find-files-in-specific-date/4708.html

Delete all files in sub-dir +10 old www.computing.net/answers/unix/delete-all-files-in-subdir-10-old/7166.html