Operating System - HP-UX
1833187 Members
3185 Online
110051 Solutions
New Discussion

deletion of multiple files

 
SOLVED
Go to solution
bassey essien_1
Frequent Contributor

deletion of multiple files

i will like to delete huge files from the
server to free up space in a volume group, i don't want to automate a script for these process but rather would excute a command from the console. i know the rm command works,but this may be a lenghty process.
please help.
5 REPLIES 5
Rick Garland
Honored Contributor
Solution

Re: deletion of multiple files

In a simple way, you could do an 'ls' command in that directory, direct the output to a file, edit the file for what you want removed, add the 'rm' command to the beginning of each line, and run it.
Alan Riggs
Honored Contributor

Re: deletion of multiple files

Do the files have a name/property that you can use a find command to select? A generic "remove large files" command is:

find / -size +10000000c -ok rm {} \;

(If you don't mind verifying before each file removal, a good idea if you are not certain of your criteria. Alternatively, exec an ls first, check the list, then exec an rm.
Tony Constantine_1
Regular Advisor

Re: deletion of multiple files

Will the files always have the same filename?

if so you can have a text file containing the names of the files, ie remove.files

then

for REMOVE in `more remove.files`
do
rm $REMOVE
done

you could run this once a week for example
Dan Hetzel
Honored Contributor

Re: deletion of multiple files

Hi Bassey,

You could use something halfway between the script and the simple rm to make life easier.

Something like...

find /path_dir -type f -size +2048 -print -exec rm -i {} \;

... will find all files bigger than 1mb (2048x512 chars)
... print their names
... ask dor a delete confirmation (rm -i)

Be careful with the /path_dir as it will
look for all files in that tree. Imagine what could happen if you erase system files :-((
Make sure to use the 'rm -i' !!!

You could further restrict the files found with using the '-name' flag for find

like:
find /path_dir -type f -name "*.log" -size +2048 -print -exec rm -i {} \;

Regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Alan Riggs
Honored Contributor

Re: deletion of multiple files

You might also want to add an -xdev flag o your find command, to prevent it from crossing mountpoints.