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

NAME
rm - remove files or directories SYNOPSIS
file ... DESCRIPTION
The command removes the entries for one or more files from a directory. If an entry was the last link to the file, the file is destroyed. Removal of a file requires write and search (execute) permission in its directory, but no permissions on the file itself. However, if the sticky bit is set on the directory containing the file, only the owner of the file, the owner of the directory, or a user having appropri- ate privileges can remove the file. If a user does not have write permission for a file to be removed and standard input is a terminal, a prompt containing the file name and its permissions is printed requesting that the removal of the file be confirmed (see Access Control Lists below). A line is then read from standard input. If that line begins with the file is deleted; otherwise, the file remains. No questions are asked when the option is given or if standard input is not a terminal. If file is of type directory, and the option is not specified, and either the permissions of file do not permit writing and standard input is a terminal or the option is specified, writes a prompt to standard error and reads a line from standard input. If the response does not begin with it does nothing more with the current file and goes on to any remaining files. If file is a symbolic link, then only the symbolic link is removed. The file or directory pointed to by the symbolic link is not affected. If any of the intermediate path components of file happens to be a symbolic link, then follows the symbolic link and removes the file. Options recognizes the following options: Force each file or directory to be removed without prompting for confirmation, regardless of the permissions of the entry. This option also suppresses diagnostic mes- sages regarding nonexistent operands. This option does not suppress any diagnostic messages other than those regarding nonexistent operands. To suppress all error message and interactive prompts, the option should be used while redirecting standard error output to This option ignores any previous occurrence of the option. Write a prompt to standard error requesting confirmation before removing each entry. This option ignores any previous occurrence of the option. For each argument that is a directory, this option causes to recursively delete the entire contents of that directory before removing the directory itself. When used in conjunction with the option, asks whether to examine each directory before interactively removing files in that directory and again afterward to confirm removing the directory itself. The option will descend to arbitrary depths in a file hierarchy and will not fail due to path length limitations unless the length of file name, specified by the user exceeds system limitations. Equivalent to Access Control Lists If a file has optional ACL entries, displays a plus sign after the file's permissions. The permissions shown summarize the file's value returned by (see stat(2)). See also acl(5). EXTERNAL INFLUENCES
Environment Variables provides a default value for the internationalization variables that are unset or null. If is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, will behave as if all internationalization variables are set to "C". See environ(5). If set to a non-empty string value, overrides the values of all the other internationalization variables. determines the interpretation of file names as single and/or multi-byte characters, the classification of characters as printable, and the characters matched by character class expressions in regular expressions. determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informa- tive messages written to standard output. determines the location of message catalogues for the processing of International Code Set Support Single- and multibyte character code sets are supported. DIAGNOSTICS
Generally self-explanatory. Note that the option does not suppress all diagnostic messages. It is forbidden to remove the file in order to avoid the consequences of using a command such as: If a designated file is a directory, an error comment is printed unless the or option is used. RETURN VALUE
exits with one of the following values: If the option is not specified, 0 is returned only if all the named directory entries (the arguments specified in the command) are removed. If the option is specified, then all the existing named directory entries are removed. If any of the named directory entries are non-existent, still returns a zero. An error occurred. EXAMPLES
Remove files with a prompt for verification: Remove all the files in a directory: Note that the previous command removes files only, and does not remove any directories in Remove a file in the current directory whose name starts with or or some other character that is special to the shell: etc. Remove a file in the current directory whose name starts with some strange (usually nonprinting, invisible) character or perhaps has spaces at the beginning or end of the filename, prompting for confirmation: If is not unique in the directory, enter when each of the other files is prompted. A powerful and dangerous command to remove a directory is: or which removes all files and directories from without any prompting for verification to remove the files or the directories. This command should only be used when you are absolutely certain that all the files and directories in as well as itself are to be removed. DEPENDENCIES
NFS does not display a plus sign to indicate the existence of optional access control list entries when asking for confirmation before removing a networked file. SEE ALSO
rmdir(1), unlink(2), acl(5). STANDARDS CONFORMANCE
rm(1)
All times are GMT -4. The time now is 12:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy