find command - no subdirs


 
Thread Tools Search this Thread
Operating Systems AIX find command - no subdirs
# 1  
Old 07-09-2008
find command - no subdirs

I am looking to delete files that are of a certain age with something like the following...

find /directory -type f -mtime +14 | xargs rm

....however, I would like to only execute this on the current directory and not subdirectories.

Any ideas?
# 2  
Old 07-09-2008
Have a look at the "-prune" clause of "find". It prevents "find" from traversing subdirectories. On the man page of "find" you'll find several examples on how to use it.

Btw.: do not use "xargs", but the "-exec" clause instead. Why use a second utility when one already suffices.

I hope this helps.

bakunin
# 3  
Old 07-09-2008
You could use the maxdepth switch (maxdepth 1 in your case) if your find implementation supports it.
Otherwise you could use something like this:

Code:
find .  \( -name . -o -prune \) -type f -mtime +14 ...

With zsh it would be:

[hidden files included]
Code:
rm -- *(.Dm+10)

[only non hidden files]
Code:
rm -- *(.m+10)

# 4  
Old 07-09-2008
This did the trick...
Code:
find .  \( -name . -o -prune \) -type f -mtime +14 ...

-maxdepth is not available in AIX 5.3.

I will use -exec as well.

Thanks.
# 5  
Old 07-09-2008
Quote:
Originally Posted by andrewsc
[...]
-maxdepth is not available in AIX 5.3.
[...]
For those of you, who are used to this parameter: find from the AIX Linux Toolbox does it. It is possible to use both find versions on an AIX server so that one can have the best of both (AIX/Linux) worlds.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i move folders and its content if folder is older than 1,5 days and keep subdirs in bash?

Hello all, do you know any way i can i move folders and its content if folder is older than 1,5 days in bash? I tried: find /home/xyz/DATA/* -type d -ctime +1.5 -exec mv "{}" /home/xyz/move_data_here/ \;All i got was that Files from DATA /home/xyz/DATA/* ended messed up in... (1 Reply)
Discussion started by: ZerO13
1 Replies

2. Shell Programming and Scripting

Replace [ ] by [[ ]] in multiple subdirs

Dear guru's I have a bunch of scripts that were written in bash and are now supposed to become sh compatible regarding the conditions( && .. and if ;then .. Within those scripts there are obviusly some math operations like var=$ or array usage like var=${array} Now these scripts are also... (5 Replies)
Discussion started by: sea
5 Replies

3. Shell Programming and Scripting

Make directories containing subdirs using mkdir

Hello everybody, I wonder if there's a way to make a directory that contains multiple subdirectories. For example, if I want to make /home/student under the current working directory, how do I do it? Can I do it using a single mkdir command or do I have make home first, cd into it and then make... (1 Reply)
Discussion started by: Yongfeng
1 Replies

4. UNIX for Dummies Questions & Answers

List files older that 7 days in a dir, excluding all subdirs

Hi, I would like to list all files, older than 7 days, in a directory, but exclude all subdirectories in the find command. If I use find . -type f -mtime +7 all files in the subdirs are also included. How can I exclude them? Regards, JW (6 Replies)
Discussion started by: jwbijl
6 Replies

5. Emergency UNIX and Linux Support

Command to calculate space for all subdirs under a dir

du -hs command calculates the space for all the subdirs under a dir ...but it is very slow if the dir is huge....is there any quick way ...I am using Sun OS. Thanks, Ajay (19 Replies)
Discussion started by: ajaypatil_am
19 Replies

6. Shell Programming and Scripting

Printing empty subdirs before delete

I am using following code to delete all the empty sub dirs from the inputted dir $1. Before deleting empty dirs, I want to print those dirs which are going to be deleted. Can this be done with little modification in following code #!/bin/sh if ; then echo "Searching '$1' dir for empty... (16 Replies)
Discussion started by: ajaypatil_am
16 Replies

7. Shell Programming and Scripting

Request for shell script for listing directories, subdirs containing specific files.

I'm looking for a script which outputs the list of directories and sub directories from root level consisting of specific files. For instance I want shell script to list all the directories and subdirectories containing .txt files.:wall: (4 Replies)
Discussion started by: super210
4 Replies

8. Shell Programming and Scripting

create dir in main &subdirs,perform action

Hi, I have one dir which has N subdirs.For ex: /home/user/Project_Src /home/user/Project_Src/Dir_A /home/user/Project_Src/Dir_A/subdir/sub_dir2 /home/user/Project_Src/Dir_A/subdir/sub_dir3 /home/user/Project_Src/Dir_B /home/user/Project_Src/Dir_B/Build i want to create a folder with... (2 Replies)
Discussion started by: dragon.1431
2 Replies

9. UNIX for Dummies Questions & Answers

Creating tar file for subdirs, excluding one and preserving user info

Hi All, I am not one of the super users / root for AIX 5.3 system. There is a filesystem Say /DIR1 and its has several subdirs in it say SUBDIR1, SUBDIR2, SUBDIR3. Can I create a tar file for all files under DIR1 and SUBDIR1, SUBDIR3. Excluding SIBDIR2? Also how can I preserve... (2 Replies)
Discussion started by: Hangman2
2 Replies

10. Shell Programming and Scripting

substrings from all files incl subdirs into csv with dir names

Greetings! I have multiple files, one per subdirectory, all with the same file name. All subdirectories are one level deep from the main directory. The data in the files is tab delimited between fields and record delimited with a newline. The subdirectory names have the date in the... (5 Replies)
Discussion started by: vtischuk@yahoo.
5 Replies
Login or Register to Ask a Question