Sponsored Content
Full Discussion: rmdir a non-empty directory.
Top Forums UNIX for Dummies Questions & Answers rmdir a non-empty directory. Post 32944 by indo1144 on Wednesday 11th of December 2002 06:44:13 AM
Old 12-11-2002
Re: rmdir a non-empty directory.

You could also do a:

rm -rf <target>

The -r and -R (see previous reply from TioTony) parameter are the same and will make it recursively travel down any subdirectory it finds.
The -f makes sure you are not prompted for confirmation (handy if there are lots of files and directories inside the target-directory).

Same warning applies here... Be careful when using this. Re-read your commandline and make sure you're in the right directory!

Most of the time, when using a powerful command like this, I use the full path + directoryname, just to be sure.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Setting the right directory as non-empty

Hi guys, I've been trying to get this part of my script to work for ages and now it's getting me annoyed!! So i thought a fresh group of eyes could see where i'm going wrong! The idea is getting a directory and all its files moved to a temp folder, but similar to the rm -ir command where it... (0 Replies)
Discussion started by: olimiles
0 Replies

2. UNIX for Dummies Questions & Answers

-r paramater with chown and rmdir

If I am root user, and trying to chown everything in a directory and it's subdirectories (e.g. httpdocs and everything inside that directory, including it's sub directories), how would I do that? I tried it with -r but it didnt seem to work...can someone help with the correct syntax? Also, if I... (3 Replies)
Discussion started by: Eman619
3 Replies

3. Shell Programming and Scripting

How to empty all files in a directory

Hi all, Can you tell me how to empty all files in a directory with a "find" command? It does not seem to work the way I try it: # ls -l *.dat -rw-r--r-- 1 root root 7 Jul 20 20:51 la2.dat -rw-r--r-- 1 root root 4 Jul 20 20:51 la.dat # find... (9 Replies)
Discussion started by: majormark
9 Replies

4. Shell Programming and Scripting

How do I tell if a directory is empty?

To see if a directory is has anything in it, I do this: if ; then # do something fi But surely there is a more easy-to-read and elegant way. Isn't there? (6 Replies)
Discussion started by: KenJackson
6 Replies

5. UNIX for Dummies Questions & Answers

Quick question...rmdir -l

Hello, We use a very basic version of unix via putty and are not experts by any means. We accidentally submitted the statement: "mkdir -l" ("dash-letter L) and a new directory was created. Putty/UNIX will now not recognize the statement "rmdir -l". When we run a "ls -l" command, it shows... (3 Replies)
Discussion started by: UDcc123
3 Replies

6. Shell Programming and Scripting

remove empty directory

Hi, I need to delete an empty directory in a temp directory except "dir5" (keep everything that is not empty). Plese advise. Here is an example of my directory. /dir/temp/ dir1 - delete if this is empty dir2 - delete if this is empty dir3 - delete if this is empty dir4 - delete if this... (7 Replies)
Discussion started by: sirrtuan
7 Replies

7. SCO

Deleting a directory that is not empty

I know someone will probably laugh at this question, I probably knew the answer many years ago when I was doing this full time but here goes..... I have a directory that has many files and sub-directories in it, RMDIR will not delete a directory that is not empty so what is the command to... (1 Reply)
Discussion started by: moondogi
1 Replies

8. Shell Programming and Scripting

Check whether a Directory is empty or not

1.pls tell me the command for checking whether a given directory is empty or not . 2. can i check what is the last copied item in a directory . and i yes , i want to move that last copied item in another directory . pls help me with shell code for these two tasks thanks (1 Reply)
Discussion started by: upvan111
1 Replies

9. Homework & Coursework Questions

Check whether a Directory is empty or not

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1.pls tell me the command for checking whether a given directory is empty or not . 2. can i check what is the... (1 Reply)
Discussion started by: upvan111
1 Replies

10. Programming

Perl - How to empty a directory?

Hi Guys, i'm writing a perl script which whenever runs, should empty 3 pre-decided directories as first step and then the script has the logic to parse some other directories and copy the files inside those directories into these 3 directories. I've the logic already developed, just need to... (2 Replies)
Discussion started by: jhamaks
2 Replies
RM(1)							    BSD General Commands Manual 						     RM(1)

NAME
rm, unlink -- remove directory entries SYNOPSIS
rm [-f | -i] [-dIPRrvWx] file ... unlink file DESCRIPTION
The rm utility attempts to remove the non-directory type files specified on the command line. If the permissions of the file do not permit writing, and the standard input device is a terminal, the user is prompted (on the standard error output) for confirmation. The options are as follows: -d Attempt to remove directories as well as other types of files. -f Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. The -f option overrides any previous -i options. -i Request confirmation before attempting to remove each file, regardless of the file's permissions, or whether or not the standard input device is a terminal. The -i option overrides any previous -f options. -I Request confirmation once if more than three files are being removed or if a directory is being recursively removed. This is a far less intrusive option than -i yet provides almost the same level of protection against mistakes. -P Overwrite regular files before deleting them. Files are overwritten three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are deleted. Files with multiple links will not be overwritten nor deleted and a warning will be issued. If the -f option is specified, files with multiple links will also be overwritten and deleted. No warning will be issued. Specifying this flag for a read only file will cause rm to generate an error message and exit. The file will not be removed or over- written. N.B.: The -P flag is not considered a security feature (see BUGS). -R Attempt to remove the file hierarchy rooted in each file argument. The -R option implies the -d option. If the -i option is speci- fied, the user is prompted for confirmation before each directory's contents are processed (as well as before the attempt is made to remove the directory). If the user does not respond affirmatively, the file hierarchy rooted in that directory is skipped. -r Equivalent to -R. -v Be verbose when deleting files, showing them as they are removed. -W Attempt to undelete the named files. Currently, this option can only be used to recover files covered by whiteouts in a union file system (see undelete(2)). -x When removing a hierarchy, do not cross mount points. The rm utility removes symbolic links, not the files referenced by the links. It is an error to attempt to remove the files /, . or ... When the utility is called as unlink, only one argument, which must not be a directory, may be supplied. No options may be supplied in this simple mode of operation, which performs an unlink(2) operation on the passed argument. EXIT STATUS
The rm utility exits 0 if all of the named files or file hierarchies were removed, or if the -f option was specified and all of the existing files or file hierarchies were removed. If an error occurs, rm exits with a value >0. NOTES
The rm command uses getopt(3) to parse its arguments, which allows it to accept the '--' option which will cause it to stop processing flag options at that point. This will allow the removal of file names that begin with a dash ('-'). For example: rm -- -filename The same behavior can be obtained by using an absolute or relative path reference. For example: rm /home/user/-filename rm ./-filename When -P is specified with -f the file will be overwritten and removed even if it has hard links. EXAMPLES
Recursively remove all files contained within the foobar directory hierarchy: $ rm -rf foobar Either of these commands will remove the file -f: $ rm -- -f $ rm ./-f COMPATIBILITY
The rm utility differs from historical implementations in that the -f option only masks attempts to remove non-existent files instead of masking a large variety of errors. The -v option is non-standard and its use in scripts is not recommended. Also, historical BSD implementations prompted on the standard output, not the standard error output. SEE ALSO
chflags(1), rmdir(1), undelete(2), unlink(2), fts(3), getopt(3), symlink(7) STANDARDS
The rm command conforms to IEEE Std 1003.2 (``POSIX.2''). The simplified unlink command conforms to Version 2 of the Single UNIX Specification (``SUSv2''). HISTORY
A rm command appeared in Version 1 AT&T UNIX. BUGS
The -P option assumes that the underlying storage overwrites file blocks when data is written to an existing offset. Several factors includ- ing the file system and its backing store could defeat this assumption. This includes, but is not limited to file systems that use a Copy- On-Write strategy (e.g. ZFS or UFS when snapshots are being used), Flash media that are using a wear leveling algorithm, or when the backing datastore does journaling, etc. In addition, only regular files are overwritten, other types of files are not. BSD
April 25, 2013 BSD
All times are GMT -4. The time now is 10:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy