Remove all things from directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove all things from directory
# 1  
Old 03-10-2012
Remove all things from directory

Which command will be good to use when I want to remove all files and directories from the directory (i want to have empty derictory).
Sorry for my English Smilie
Greetings from Poland Smilie
# 2  
Old 03-10-2012
Just use the "rm" command carefully.

From with the directory that you wish to delete the contents of - eg

Code:
cd /home/my_dir_to_delete
rm -rf *

You'll have to make sure that you have the correct permissions to delete everything.

Go Carefully if you are new to this as mistakes can be hard to rectify - and always ensure that you have a backup even if you think you'll never need the data againSmilie
# 3  
Old 03-10-2012
rm -rf * is the most destructive command - Nuke_bomb of Unix. Be sure what your present directory is.

Cheers!
# 4  
Old 03-10-2012
Quote:
Originally Posted by gull04
Just use the "rm" command carefully.

From with the directory that you wish to delete the contents of - eg

Code:
cd /home/my_dir_to_delete
rm -rf *

You'll have to make sure that you have the correct permissions to delete everything.

Go Carefully if you are new to this as mistakes can be hard to rectify - and always ensure that you have a backup even if you think you'll never need the data againSmilie
Good advice and a case in point, suppose the first of the two commands (the cd command) fails and you are either too quick with the second command or you are executing the two together (from the command line or from a script) then you end up deleting the current directory and everything underneath Smilie

So use a long pause after the first command and type pwd and ls -al etcetera to verify that you are in the proper directory and have proper rights.

Last edited by Scrutinizer; 03-10-2012 at 03:56 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to make a bash script that goes through directory files and changes things

I'm trying to write a script in a directory that goes through the column the user specifies of 4 files that are inside the directory and calculates the min and the max values. This means that if the user specifies column 5, the script will go through column 5 of all 4 files and all that should give... (2 Replies)
Discussion started by: Eric1
2 Replies

2. UNIX for Dummies Questions & Answers

How to remove directory of a particular user?

How to remove directory of a particular user (1 Reply)
Discussion started by: pspriyanka
1 Replies

3. HP-UX

Directory can't remove!

Hello my friends, I have a directory called log_old when I try to delete it, it tells me no such file or directory. Then I tried to run this command: ls -lb It tells me the directory name, it is: log_old1\177 !! I tried to remove it using inode, using this... (4 Replies)
Discussion started by: Mohannad
4 Replies

4. Shell Programming and Scripting

Remove Directory

By Mistake i created a directory named "-lrt" in one of my working directories and now i am not able to delete it , please suggest hw to delete this directory now ? Thanks in advance. (1 Reply)
Discussion started by: neeraj617
1 Replies

5. Shell Programming and Scripting

Remove contents of directory, but not directory

What's the best way to delete everything in a directory, but not the directory itself, without using shell wildcards? (9 Replies)
Discussion started by: pdc
9 Replies

6. Solaris

Can't remove a directory

Hello, somehow a directory called -r was created on one of my servers and I can't remove is using either rm or rmdir. Is there a way to remove this directory? Thank you. -David (2 Replies)
Discussion started by: dkranes
2 Replies

7. AIX

remove hardlink directory

I have to move a lpar from one 671 to another (aix 5.2 ML 07) when I run mksysb, It alway hangs with "archieving file list" I've tried to exlude every directory, but still not working the only thing that can be a problem, is a hardlink directory normally it should not be possible to... (4 Replies)
Discussion started by: funksen
4 Replies

8. UNIX for Dummies Questions & Answers

smitty, remove user, remove directory as well..

hi, i am on aix. i used smitty to remove a user.. but then found that its directory still exists.... so i have to remove the directory manually... am i doing it the right way? (2 Replies)
Discussion started by: yls177
2 Replies

9. UNIX for Dummies Questions & Answers

a program which linux things is a directory??

Hi, Well I finally got around to installing linux , the install went fine. I have just tried on to install some software.It gunziped and untared fine. It even complied fine. However when I try to run the program. I get the message "bash: is a directory". I have tried changing the permission on... (4 Replies)
Discussion started by: john_bir
4 Replies
Login or Register to Ask a Question