IT

Bash Script to Remove Files in List

In a unix/linux environment I get a list of hundreds of files that need to be deleted.  This list comes to me every week in the form of a text file and I need to do two things.

  1. Check to see how many bytes are involved.
  2. Delete the files.

Some of the files have spaces in their names.  Two scripts are used. One for checking and one for deleting.

Following is the script for checking:

#!/bin/bash
for token in `cat $1`
do
      printf  “du  -sk  \ “%s\”  \n”  $token  >> $1.sh
done

Following is the script for deleting:

#!/bin/bash
for token in `cat $1`
do
      printf  “rm  -rf  \ “%s\”  \n”  $token  >> $1.sh
done
Advertisements

Categories: IT, Unix Scripts

Tagged as:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s