Sponsored Content
Top Forums Shell Programming and Scripting Remove contents of directory, but not directory Post 91598 by pdc on Saturday 3rd of December 2005 08:57:54 PM
Old 12-03-2005
Except that won't remove any subdirectories. Removing the "-type f" and specifying "rm -r" fixes this issue... but you'll still hit an error when find attempts to remove the "." directory. Incidentally, "find . -delete" is probably a nicer way of coding this.

Anyone else got suggestions? It seems like the kind of thing their should be a command, or flag to rm, for: a simple way to empty a directory.

Last edited by pdc; 12-03-2005 at 10:08 PM..
 

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
rm(1)								   User Commands							     rm(1)

NAME
rm, rmdir - remove directory entries SYNOPSIS
/usr/bin/rm [-f] [-i] file... /usr/bin/rm -rR [-f] [-i] dirname... [file...] /usr/xpg4/bin/rm [-fiRr] file... /usr/bin/rmdir [-ps] dirname... DESCRIPTION
/usr/bin/rm /usr/xpg4/bin/rm The rm utility removes the directory entry specified by each file argument. If a file has no write permission and the standard input is a terminal, the full set of permissions (in octal) for the file are printed followed by a question mark. This is a prompt for confirmation. If the answer begins with y (for yes), the file is deleted, otherwise the file remains. If file is a symbolic link, the link will be removed, but the file or directory to which it refers will not be deleted. Users do not need write permission to remove a symbolic link, provided they have write permissions in the directory. If multiple files are specified and removal of a file fails for any reason, rm will write a diagnostic message to standard error, do noth- ing more to the current file, and go on to any remaining files. If the standard input is not a terminal, the utility will operate as if the -f option is in effect. /usr/bin/rmdir The rmdir utility will remove the directory entry specified by each dirname operand, which must refer to an empty directory. Directories will be processed in the order specified. If a directory and a subdirectory of that directory are specified in a single invoca- tion of rmdir, the subdirectory must be specified before the parent directory so that the parent directory will be empty when rmdir tries to remove it. OPTIONS
The following options are supported for /usr/bin/rm and /usr/xpg4/bin/rm: -r Recursively removes directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. The write-protected files are removed without prompting, however, if the -f option is used, or if the standard input is not a terminal and the -i option is not used. Symbolic links that are encountered with this option will not be traversed. If the removal of a non-empty, write-protected directory is attempted, the utility will always fail (even if the -f option is used), resulting in an error message. -R Same as -r option. /usr/bin/rm The following options are supported for /usr/bin/rm only: -f Removes all files (whether write-protected or not) in a directory without prompting the user. In a write-protected directory, how- ever, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a write-protected directory is attempted, this option will not suppress an error message. -i Interactive. With this option, rm prompts for confirmation before removing any files. It overrides the -f option and remains in effect even if the standard input is not a terminal. /usr/xpg4/bin/rm The following options are supported for /usr/xpg4/bin/rm only: -f Does not prompt for confirmation. Does not write diagnostic messages or modify the exit status in the case of non-existent oper- ands. Any previous occurrences of the -i option will be ignored. -i Prompts for confirmation. Any occurrences of the -f option will be ignored. /usr/bin/rmdir The following options are supported for /usr/bin/rmdir only: -p Allows users to remove the directory dirname and its parent directories which become empty. A message is printed to standard error if all or part of the path could not be removed. -s Suppresses the message printed on the standard error when -p is in effect. OPERANDS
The following operands are supported: file A path name of a directory entry to be removed. dirname A path name of an empty directory to be removed. USAGE
See largefile(5) for the description of the behavior of rm and rmdir when encountering files greater than or equal to 2 Gbyte ( 2 **31 bytes). EXAMPLES
The following examples are valid for the commands shown. /usr/bin/rm /usr/xpg4/bin/rm Example 1: Removing directories The following command: example% rm a.out core removes the directory entries a.out and core. Example 2: Removing a directory without prompting The following command: example% rm -rf junk removes the directory junk and all its contents, without prompting. /usr/bin/rmdir Example 3: Removing empty directories If a directory a in the current directory is empty, except that it contains a directory b, and a/b is empty except that it contains a directory c, the following command will remove all three directories: example% rmdir -p a/b/c ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of rm and rmdir: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 If the -f option was not specified, all the named directory entries were removed; otherwise, all the existing named directory entries were removed. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin/rm /usr/bin/rmdir +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ /usr/xpg4/bin/rm +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
rmdir(2), unlink(2), attributes(5), environ(5), largefile(5), standards(5) DIAGNOSTICS
All messages are generally self-explanatory. It is forbidden to remove the files "." and ".." in order to avoid the consequences of inadvertently doing something like the following: example% rm -r .* It is forbidden to remove the file "/" in order to avoid the consequences of inadvertently doing something like: example% rm -rf $x/$y or example% rm -rf /$y when $x and $y expand to empty strings. NOTES
A - permits the user to mark explicitly the end of any command line options, allowing rm to recognize file arguments that begin with a -. As an aid to BSD migration, rm will accept -- as a synonym for -. This migration aid may disappear in a future release. If a -- and a - both appear on the same command line, the second will be interpreted as a file. SunOS 5.10 26 Jan 2001 rm(1)
All times are GMT -4. The time now is 12:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy