1822145 Members
3974 Online
109640 Solutions
New Discussion юеВ

how to delete directory

 
Jason Tan
Advisor

how to delete directory

i have a directory that i want to delete, if i go inside the directory and key in command like rm *, the message prompt : arg list too long. If i use rm -r to delete the directory, it take too long.

Now, is there a faster way to do?
smtan
11 REPLIES 11
Sridhar Bhaskarla
Honored Contributor

Re: how to delete directory

Hi,

Try "rm a* c* d*"

and keep doing it.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Patrick Wallek
Honored Contributor

Re: how to delete directory

'rm -r dirname' will probably be the quickest way. If the directory has lots of files, it could take a while.

Sridhar's way could work too, but it will also take a while, especially if you have to go thru a*, b*, etc. for all letters of the alphabet.
James R. Ferguson
Acclaimed Contributor

Re: how to delete directory

Hi Jason:

# rm -fr thedir

...will recursively delete the directory's contents and the directory itself. If it takes a long time, that's a reflection of the number of files and subdirectories being processed.

Regards!

...JRF...
Michael Tully
Honored Contributor

Re: how to delete directory

You could also try this:

# find . -type f -name "*" -print | xargs rm
Anyone for a Mutiny ?
Jason Tan
Advisor

Re: how to delete directory

But, what about the directory cannot be deleted? so, rm -r still is the quickest way?
smtan
Michael Tully
Honored Contributor

Re: how to delete directory

# find . -type d -name "mydirname" -print | xargs rm -rf

Using the find command in conjunction with the 'xargs' command should fix the problem with the 'arg list' being too long
Anyone for a Mutiny ?
KCS_1
Respected Contributor

Re: how to delete directory

Hi,

Look at man pages of "rmdir" and "rm" commands.

I think that good way to get delete the director.

# rmdir -f directory

or


# rm -rf directory


Happy new year!!
Easy going at all.
Patrick Wallek
Honored Contributor

Re: how to delete directory

The directory cannot be deleted until all the files and sub-directories within it are deleted.

Thus the command:

# rm -rf dirname

Bill Hassell
Honored Contributor

Re: how to delete directory

rm -r dir_name is the fastest way to delete the files. The "arg list too long" is a message that indicates the directory contains thousands of files so using the * to represent the list will produce a command line that is too long.

As far as the speed, there is nothing faster since every file removed must be properly handled in the directory structures. Now if the directory is actually a mountpoint, then you can always un-mount the directory and use newfs to create an empty directory in just a couple of seconds.


Bill Hassell, sysadmin
Ravi_8
Honored Contributor

Re: how to delete directory


Hi,

rm -rf will delete all files in the directory including directory
never give up
Chakravarthi
Trusted Contributor

Re: how to delete directory

do
sh
get into the directory
run

for i in $i; do ls ; rm -rf $i; echo $i; done

regards
chakri