Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to remove directory with subdirectories and files? Post 302118268 by ppa108 on Monday 21st of May 2007 04:39:53 AM
Old 05-21-2007
How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside.
I used the command rm -r <dirname>
But, it always ask "examine file in directory <dirname> yes/no?" line by line.
So, i need to write "y" for every line.
How can i skip this step and remove all directories with asking confirmation?
Thank you.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Remove Ctrl M characters in files from directories and its subdirectories

Hi, How to recursively remove Ctrl M characters in files from a directory and its sub directory ? I know unix2dos command is there but to remove in bunch of files ... ? Thanks (7 Replies)
Discussion started by: skdp
7 Replies

2. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies

3. Shell Programming and Scripting

Replace a string in all files under a directory and its subdirectories

Hello Friends, I've been trying to write a script which finds a string and change it with another string. For this i want to search all files (with its arguments) under a spesific directory and its subdirectories. For example lets assume i want to replace an IP= 192.168.0.4 with another... (4 Replies)
Discussion started by: EAGL€
4 Replies

4. Shell Programming and Scripting

Bash: Gzip files in Directory and itīs Subdirectories

Hello dear Community, I have a task to wrtie a script which will gzip not zipped files in a directory and itīs subdirectories. I succeeded in gzippung the directory but not the subdirectories: #/bin/bash #go to the directory where to zip cd $1 #Zip unzipped files for i in `ls | xargs... (2 Replies)
Discussion started by: JamesCarter
2 Replies

5. Shell Programming and Scripting

Find files only in current directory...not subdirectories

Hi, I have to find files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..I tried to use maxdepth..but it is not working in AIX. (2 Replies)
Discussion started by: vsachan
2 Replies

6. Shell Programming and Scripting

Remove files from subdirectories given a list of filenames

Dear all, I have a dir structure like main_dir At_nn Ag_js Nf_hc .... mcd32 mgd43... mcd32 mgd43... mcd32 mgd43... and each subdir (e.g. mcd32, mgd43) contains files. Now, i... (15 Replies)
Discussion started by: yogeshkumkar
15 Replies

7. Shell Programming and Scripting

Help on Backing up all the files in the subdirectories under a parent directory

Hi, I am not too familiar with Unix scripting but I have to write code to find all the files under all the sub directories under a parent directory of unix location and move them to the corresponding Windows location. For eg: I have \home\sreenu\Files\ Under neath this I have multiple sub... (3 Replies)
Discussion started by: raj.sreenu
3 Replies

8. Shell Programming and Scripting

List files with *.i extension in a directory and all its subdirectories + 30days old then remove

I need to write a script to : list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Discussion started by: lena keung
2 Replies

9. 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

10. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 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 06:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy