How to find files in current folder only?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find files in current folder only?
# 1  
Old 01-04-2009
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  
Old 01-04-2009
Quote:
Originally Posted by Hangman2
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  
Old 01-04-2009
This displays any subdir if any under dir4 also.

?
# 4  
Old 01-04-2009
Quote:
Originally Posted by Hangman2
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  
Old 01-04-2009
That worked.

I had to delete the file so I added

&& `rm $f`

Smilie
# 6  
Old 01-04-2009
Quote:
Originally Posted by Hangman2
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  
Old 01-04-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

3. Shell Programming and Scripting

Find specific files only in current directory...not sub directories AIX

Hi, I have to find specific files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help.. I am using the below command. And i am... (2 Replies)
Discussion started by: aakishore
2 Replies

4. Shell Programming and Scripting

Find files only in current directory...not subdirectories

Hi, I have to find files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..I tried to use maxdepth..but it is not working in AIX. (2 Replies)
Discussion started by: vsachan
2 Replies

5. Shell Programming and Scripting

Convert all files in current folder from UTF8 to ANSI, name unchanged.

Asking for a Linux command line to convert all files in current folder from UTF8 to ANSI, name unchanged. Best Regards Pei (3 Replies)
Discussion started by: jiapei100
3 Replies

6. Shell Programming and Scripting

Getting current folder name appended to all desired files

Hello everyone, Just registered here, I'm kinda new to Unix :o I've been trying to automate some processes with various Windows tools. I found that using unix scripts the result would be closest to my needs. So I installed Cygwin on Windows 7. My folders and files are structured like this:... (7 Replies)
Discussion started by: c_bg1
7 Replies

7. Shell Programming and Scripting

How to find particular string in multiple files with in the current directory.

Hello friends, Plz suggest the find command, How to search a string in a paticular string in miltiple files with current dirctory.:) Thanks in advance. Siva Ranganath Ch (2 Replies)
Discussion started by: sivaranga001
2 Replies

8. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

9. Shell Programming and Scripting

Find files ONLY in current directory

Hello all, I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories. I tried: find . -name "*.ksh" -prune this also returns ksh files from lower subdirectories. I also tried find . -ls -name "*.ksh" This also... (8 Replies)
Discussion started by: gio001
8 Replies

10. UNIX for Dummies Questions & Answers

how to find files less than the current date

Hai, i have one directory contains 100 files .each file name like xvb_dateformat.i want find which file names are xvb_lessthan or equal to currentdate. any one give the solution. regards (4 Replies)
Discussion started by: mallikarjuna
4 Replies
Login or Register to Ask a Question