Operating System - HP-UX
1825722 Members
3022 Online
109687 Solutions
New Discussion

Error while deleting subdirectories & files.

 
Gulam Mohiuddin
Regular Advisor

Error while deleting subdirectories & files.

Finally I ran the following command all files were deleted but directories & sub directories were not deleted.

Why I am getting the error and what is the right command to deleted subdir as well?.

find . -type f -mtime +90 -exec rm {} \;


rm: ./PSAPPSRV.8861/cache directory
rm: ./PSAPPSRV.1138 directory
rm: ./PSAPPSRV.1138/cache directory
rm: ./PSAPPSRV.6822 directory
rm: ./PSAPPSRV.6822/cache directory
rm: ./PSAPPSRV.27391 directory
rm: ./PSAPPSRV.27391/cache directo


Thanks,

Gulam.
Everyday Learning.
12 REPLIES 12
baiju_3
Esteemed Contributor

Re: Error while deleting subdirectories & files.

hi ,


use -f option to rm (rm -f) and try .


Thanks,
bl.
Good things Just Got better (Plz,not stolen from advertisement -:) )
Uday_S_Ankolekar
Honored Contributor

Re: Error while deleting subdirectories & files.

add Rf infront of rm command
find . -type f -mtime +90 -exec rm -Rf {} \;
Good Luck..
Robert-Jan Goossens
Honored Contributor

Re: Error while deleting subdirectories & files.

Gulam,

find . -type f -mtime +90 -exec rm {} \;

change rm to rm -Rf

Regards,
Robert-Jan
Peter Godron
Honored Contributor

Re: Error while deleting subdirectories & files.

Gulam,
the problem is that your find has found a directory which qualifies for removal.

However the command for removing a directory is rmdir dirname

A rm -R will remove ALL files within that directory and the directory. Not what I think you want.

Generaly is best to test these commands out very thoroughly before using them to remove live files!
Hein van den Heuvel
Honored Contributor

Re: Error while deleting subdirectories & files.


Well, rm does not work on directories. rmdir does.
You may want to test for directory files.

-type c "True if the type of the file is c, where c is:
f regular file
d directory"....

Also, check out -depth :

" A position-independent term which causes descent of the directory hierarchy to be done so that all entries in a directory are acted on before the directory itself.

man find for details...

Hein.
Pete Randall
Outstanding Contributor

Re: Error while deleting subdirectories & files.

First off, your find is only looking for files (-type f). Leave out the "-type f", then change your "rm" to "rm -rf".


Pete

Pete
Arturo Galbiati
Esteemed Contributor

Re: Error while deleting subdirectories & files.

Hi Gulam,
to remove directory use option R.
From man rm:

...
-R For each argument that is a directory, this option causes rm
to recursively delete the entire contents of that directory
before removing the directory itself. When used in
conjunction with the -i option, rm asks whether to examine
each directory before interactively removing files in that
directory and again afterward to confirm removing the
directory itself.
....

HTH,
Art
Muthukumar_5
Honored Contributor

Re: Error while deleting subdirectories & files.

Files are having permission. Few of them are expecting forceful deletion to delete the files.

The messages are related with diagnostic messages on regarding nonexistant operands.

Use -f with rm to delete files. Use -rf for directory deletion.

Use as,

find . -type f -mtime +90 -exec rm -f {} \;

find . -type f -mtime +90 | xargs rm -f

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: Error while deleting subdirectories & files.

Hello,

In order to delete files, you can use -f option with "rm". Man page says,

-f Force each file or directory to be removed without prompting
for confirmation, regardless of the permissions of the
entry. This option also suppresses diagnostic messages
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 -f option should
be used while redirecting standard error output to
/dev/null.


-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Chushia
Frequent Advisor

Re: Error while deleting subdirectories & files.

Hi,

Many have said to use -rf after rm, like :

find . -type f -mtime +90 -exec rm -rf {} \;

This is very strong. It'd be good to do this:

cd /mmm/nnnn && find . â mtime 35 â exec rm -rf {} \;

add your cd command to current directory in front of "find and delett".

Chushia
Frequent Advisor

Re: Error while deleting subdirectories & files.

Hi,

Many have said to use -rf after rm, like :

find . -type f -mtime +90 -exec rm -rf {} \;

This is very strong. It'd be good to do this:

cd /mmm/nnnn && find . â mtime +90 â exec rm -rf {} \;

add your cd command to current directory in front of "find and delett".

Chushia
Frequent Advisor

Re: Error while deleting subdirectories & files.

Sorry, the cut paste garbled,

should be:

cd /mmm/nnnn && find . -type f -mtime +90 -exec rm -rf {} \;


Chushia