The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find files ONLY in current directory gio001 Shell Programming and Scripting 8 06-19-2009 06:58 AM
To find files with specific dates and cp another folder. *Jess* UNIX for Dummies Questions & Answers 2 03-17-2009 08:23 PM
Recursive call to find files and directories in Shell script from current path. Ramit_Gupta Shell Programming and Scripting 2 10-07-2008 04:33 AM
Shell script to find out 2 last modified files in a folder..PLZ HELP!!!!!!!!! anju Shell Programming and Scripting 3 02-01-2008 01:47 AM
how to find files less than the current date mallikarjuna UNIX for Dummies Questions & Answers 4 01-20-2006 01:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-04-2009
Hangman2 Hangman2 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 27
How to find files in current folder only?

How do I find files in current folder only?

We are on AIX 5.3, so maxdepth is not supported.

I tried to do this

find /dir1/dir2/dir3/dir4 -prune -type f

to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files.

Somehow the -prune option works for dir3 level only.

if I try to display files in /dir1/dir2/dir3/dir4 then it does not work.

There is "-depth" option, I am copying help desc.

======================
-depth
Always evaluates to the value True. Causes the descent of the directory hierarchy to be done so that all entries
in a directory are affected before the directory itself is affected. This can be useful when the find command is
used with the cpio command to transfer files that are contained in directories without write permission.
==============

Last edited by Hangman2; 01-04-2009 at 01:10 AM..
  #2 (permalink)  
Old 01-04-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,310
Quote:
Originally Posted by Hangman2 View Post
How do I find files in current folder only?

We are on AIX 5.3, so maxdepth is not supported.

I tried to do this

find /dir1/dir2/dir3/dir4 -prune -type f

to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files.

Code:
printf "%s\n" /dir1/dir2/dir3/dir4/*
  #3 (permalink)  
Old 01-04-2009
Hangman2 Hangman2 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 27
This displays any subdir if any under dir4 also.

?
  #4 (permalink)  
Old 01-04-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,310
Quote:
Originally Posted by Hangman2 View Post
This displays any subdir if any under dir4 also.

It will display the name, but it will not descend into it.

If you only want files and not directories:

Code:
for f in /dir1/dir2/dir3/dir4/*
do
   [ -f "$f" ] && printf "%s\n" "$f"
done

Last edited by cfajohnson; 01-04-2009 at 01:36 AM..
  #5 (permalink)  
Old 01-04-2009
Hangman2 Hangman2 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 27
That worked.

I had to delete the file so I added

&& `rm $f`

  #6 (permalink)  
Old 01-04-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,310
Quote:
Originally Posted by Hangman2 View Post
That worked.

I had to delete the file so I added

&& `rm $f`

Why are you trying to execute the output of `rm $f`?

It should be:

Code:
&& rm "$f"
If you just want to delete the files in dir4, why not:

Code:
rm  /dir1/dir2/dir3/dir4/* 2>/dev/null
  #7 (permalink)  
Old 01-04-2009
Hangman2 Hangman2 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 27
Agreed that I should not use `rm $f` and instead rm $f will also work.

If I try to use

rm /dir1/dir2/* 2 > /dev/null

then it also tries to delete any subdir under it also.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0