Sponsored Content
Top Forums Shell Programming and Scripting remove a whole directory tree WITH files inside? Post 302562142 by pstein on Thursday 6th of October 2011 06:54:20 AM
Old 10-06-2011
remove a whole directory tree WITH files inside?

Assume I want to remove a whole directory tree beginning with /foo/bar/
The directory or sub-directories may contain files.

The top directory /foo/bar/ itself should not be deleted.
Code:
rm -f- r /foo/bar

does not work because it requires a directory tree without files.

How does it work with files inside?

Peter

Moderator's Comments:
Mod Comment Please use code tags

Last edited by zaxxon; 10-06-2011 at 08:15 AM.. Reason: code tags, see PM
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read from fileList.txt, copy files from directory tree

Hi, hopefully this is a fairly simple Q&A. I have a clean file list of approximately 180 filenames with no directory or slashes in front of the filename nor any extension or dot ".". I would like to read from this list, find these files recursively down through directory trees, copy the files... (1 Reply)
Discussion started by: fxvisions
1 Replies

2. Shell Programming and Scripting

Recursively copy only specific files from a directory tree

Hi I am a shell-script newbie and am looking to synchronize certain files in two directory structures. Both these directory-trees are in CVS and so I dont want the CVS directory to be copied over. I want only .sh and .pl files in each subdirectory under these directory trees to be... (3 Replies)
Discussion started by: sharpsharkrocks
3 Replies

3. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies

4. UNIX for Dummies Questions & Answers

Copy directory tree with files

Iam in the process of copying a directory with thousands of directories and files into a new directory. I need to preserve permissions, owner, group, date and timestamps, everything. Iam using AIX and would need help of writing the command whether it is cp-RP or cpio. Apprecaite your... (3 Replies)
Discussion started by: baanprog
3 Replies

5. Shell Programming and Scripting

Compressing all directories inside a directory and remove the uncompressed version

hi pls give me a script to compress all directories inside a directory and remove the original uncompressed version... >> please also tell the single commmand to uncompress all the directories back...whemn needed (2 Replies)
Discussion started by: dll_fpga
2 Replies

6. Shell Programming and Scripting

How to find files in directory tree by date

I'm using a directory naming convention to organize files as exemplified here: 2012/Aug/week-20-Aug/23-Thu/tuv.txt 2012/Aug/week-27-Aug/30-Thu/abc.txt 2012/Sep/week-27-Aug/01-Sat/def.txt 2012/Sep/week-03-Sep/07-Fri/xyz.txt How do I write a command that will list the file names abc.txt and... (4 Replies)
Discussion started by: siegfried
4 Replies

7. Shell Programming and Scripting

Shell script to build directory tree and files

Hi all, I'm trying at the moment to write a shell script to build a directory tree and create files within the built directories. I've scoured through sites and text books and I just can't figure out how to go about it. I would assume that I need to use loops of some sort, but I can't seem... (8 Replies)
Discussion started by: Libertad
8 Replies

8. Shell Programming and Scripting

Delete all files with specific extension in directory tree

I'm sure this has been asked many times, but a search didn't turn up a definitive best method for this (if there ever is such a thing). I have been using rsync to back up my main data directory, but I have accumulated a large number of older backups that I don't need. All of the files I don't... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

9. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

10. UNIX for Dummies Questions & Answers

Remove all the subdirectories except latest 5 inside any given directory

I Want to remove all the sub-directories except latest five in any given TGTDIR. Is there a way to do so without making a cd to TGTDIR? I have tried the following but not worked. Thank you. rm -rf `ls -t $TGTDIR | awk 'NR>5'` (20 Replies)
Discussion started by: Devendra Hupri
20 Replies
nisrmdir(1)							   User Commands						       nisrmdir(1)

NAME
nisrmdir - remove NIS+ directories SYNOPSIS
nisrmdir [-if] [-s hostname] dirname DESCRIPTION
nisrmdir deletes existing NIS+ subdirectories. It can remove a directory outright, or simply remove replicas from serving a directory. This command modifies the object that describes the directory dirname, and then notifies each replica to remove the directory named dirname. If the notification of any of the affected replicas fails, the directory object is returned to its original state unless the -f option is present. This command will fail if the NIS+ master server is not running. OPTIONS
The following options are supported: -i Interactive mode. Like the system rm(1) command the nisrmdir command will ask for confirmation prior to removing a direc- tory. If the name specified by dirname is a non-fully qualified name this option is forced on. This prevents the removal of unexpected directories. -f Force the command to succeed even though it may not be able to contact the affected replicas. This option should be used when a replica is known to be down and will not be able to respond to the removal notification. When the replica is finally rebooted it will read the updated directory object, note that it is no longer a replica for that directory, and stop responding to lookups on that directory. Cleanup of the files that held the now removed directory can be accomplished manu- ally by removing the appropriate files in the /var/nis directory. See nisfiles(4) for more information. -s hostname Specify that the host hostname should be removed as a replica for the directory named dirname. If this option is not present all replicas and the master server for a directory are removed and the directory is removed from the namespace. Special per-server and per-directory access restrictions may apply when this command updates the serving lists of the affected NIS+ servers. For more information, see nisopaccess(1). OPERANDS
The following operand is supported: dirname An existing NIS+ directory. EXAMPLES
Example 1 Using the nisrmdir Command To remove a directory bar under the foo.com. domain, one would use the command: example% nisrmdir bar.foo.com. To remove a replica that is serving directory bar.foo.com. one would use the command: example% nisrmdir -s replica.foo.com. bar.foo.com. To force the removal of directory bar.foo.com. from the namespace, one would use the command: example% nisrmdir -f bar.foo.com. ENVIRONMENT VARIABLES
NIS_PATH If this variable is set, and the NIS+ directory name is not fully qualified, each directory specified will be searched until the directory is found. See nisdefaults(1). EXIT STATUS
The following exit values are returned: 0 Successful operation. 1 Operation failed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWnisu | +-----------------------------+-----------------------------+ SEE ALSO
NIS+(1), nisdefaults(1), nisopaccess(1),nisrm(1), nisfiles(4), attributes(5) NOTES
NIS+ might not be supported in future releases of the Solaris operating system. Tools to aid the migration from NIS+ to LDAP are available in the current Solaris release. For more information, visit http://www.sun.com/directory/nisplus/transition.html. SunOS 5.11 2 Dec 2005 nisrmdir(1)
All times are GMT -4. The time now is 07:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy