Sponsored Content
Top Forums Shell Programming and Scripting Remove contents of directory, but not directory Post 91628 by blowtorch on Sunday 4th of December 2005 01:25:58 AM
Old 12-04-2005
Quote:
Originally Posted by pdc
It's not homework. I'm looking to know mostly out of curiosity, but you could argue that using wildcards is bad anyway. If there's a million files in the directory, that's a million rm processes (obviously not all simultaneous, but still). It's not bullet-proof:

/*skipped the code*./

On top of that, it's not easy to use from, say, an exec() call. You need the infrastructure of a shell.

So my question stands.
I dont think you have that right.. a million processes is not a million rm processes. Its all those million files as arguments to one rm process. Now that might fail due to too many arguments (any command can handle only a finite number).
I will give you your second argument about not being easy to use from an exec() call.

Why don't you use a slightly modified form of the find command that ppierald gave:
Code:
find . -exec rm -rf {} \;

That, by the way, would be a million rm processes (one for each file/directory that the find command would output).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unable to view contents of a directory

Hi, first post here be gentle. Very new to Unix. Using HP-UX 10.20 I CD into a remote directory on one machine $ cd /net/remote hostname yet when I do an ll in this directory none of the contents appear. It just is empty. when I do the same command from another machine, $ cd... (13 Replies)
Discussion started by: maddave
13 Replies

2. UNIX for Dummies Questions & Answers

Message trying to list contents of directory

I'm getting this return whenever I try to do anything on a directory root# ls -al /directory ls: .: Value too large to be stored in data type. total 0 I can change directory down two levels but can not list contents of the root of this directory. ANy one seen this? (1 Reply)
Discussion started by: sallender
1 Replies

3. UNIX for Dummies Questions & Answers

list contents of directory

I want to list the contents of a directory, but I do not want to use the ls, is there another way?? (3 Replies)
Discussion started by: carl_vieyra
3 Replies

4. UNIX for Dummies Questions & Answers

Best way to list a directory's contents?

Hey guys! I'm so glad I found this site, I've had so many questions and have been left alone for roughly a year scanning man pages but It's just not quite cutting it for some things. So, I often like to list directories when browsing around my local machine, a friend's machine, or my web... (6 Replies)
Discussion started by: bbilheimer
6 Replies

5. Solaris

Directory should not be deleted, But the contents can be

Hi Guys, I have an user's home directory set to /home/A And A contains the following directories B & C Is there some way in solaris by which i can prevent the directories B and C from getting deleted by the user but the contents of the directories B & C can be deleted ? Also i have... (2 Replies)
Discussion started by: localhost
2 Replies

6. Shell Programming and Scripting

Create a list of directory contents

Well I did a search and didn't anything for my specific case. I got a directory with a bunch of text file. All of them have the following pattern on the filename "ABCD_<As of Date>.txt" Example: ABCD_20110301.txt ABCD_20110302.txt ABCD_20110303.txt All I want to accomplish is a Korn... (3 Replies)
Discussion started by: Shark Tek
3 Replies

7. Shell Programming and Scripting

Script that displays contents of a directory

Hello all! I am writing a script that takes in a directory name as input and if the directory exists, it shows the files inside the directory here is what I have so far (incomplete) (mostly like pseudocode) #/bin/sh echo Please enter the name of a directory read dir grep $dir... (2 Replies)
Discussion started by: subway69
2 Replies

8. UNIX for Dummies Questions & Answers

What option will use for deleting directory with all its contents?

Hi How to completely delete directory with all it contents I try to use rmdir -r but it give error Thanks ---------- Post updated at 03:10 AM ---------- Previous update was at 02:52 AM ---------- Hi all I got the solution for my thread i use mkdir with the option -p Thanks (1 Reply)
Discussion started by: Tauatioti
1 Replies

9. AIX

Restore directory and contents from tape

Hi, I have taken a backup of a directory on my tape in using below command cd /backup find * -print|backup -ivf '/dev/rmt0' '-U' |tee -a /syslogs/backup.log and output appear in below format. a 0 rman-before-08032014 a 58403323904... (2 Replies)
Discussion started by: m_raheelahmed
2 Replies

10. Shell Programming and Scripting

Zipping contents without the actual directory

Hi , I want to zip files present in the directories listed under a parent directory without zipping the directory itself my parent directory path is /informatica/DGDMN/PowerCenter1011/server/infa_shared/SrcFiles/OTE/Final_Directory I have the below directories named as 1,2,3,4,5 listed... (9 Replies)
Discussion started by: paul1234
9 Replies
list directory(1m)														list directory(1m)

NAME
list directory - Displays a list of all the directories whose names match the specified directory name SYNOPSIS
cdscp list directory directory-name [with attribute-name = attribute-value] ARGUMENTS
The full name of a specific directory. The last simple name can contain wildcard characters. The name of a particular attribute. The value of a particular attribute. DESCRIPTION
The list directory command displays a list of all the directories whose names match the specified directory name. The last simple name can contain wildcards. You can use a with attribute-name = attribute-value clause to limit output only to directories whose attributes have values equal to the specified values. A space must precede and follow the = (equals sign). Privilege Required You must have read permission to the parent directory. If you use a with attribute-name = attribute-value clause in the command, you also need read or test permission to the selected directories. NOTE
This command is replaced at Revision 1.1 by the dcecp command and may not be provided in future releases of DCE. EXAMPLE
The following command displays the names of all the directories in the /.:/sales directory: cdscp> list directory /.:/sales/* LIST DIRECTORY /.../abc.com/sales AT 1991-10-15-15:43:58 atlanta austin boston chicago ontario ny seattle RELATED INFORMATION
Commands: add directory(1m), create directory(1m), delete directory(1m), remove directory(1m), set directory(1m), set directory to skulk(1m), show directory(1m) list directory(1m)
All times are GMT -4. The time now is 05:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy