The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cp files (>5 Mb size) from one directory to another skcontact UNIX for Dummies Questions & Answers 6 06-12-2008 07:39 AM
searching files inside directory kylethesir UNIX for Dummies Questions & Answers 4 06-06-2008 01:44 AM
How to see directory and the files inside it. shaan_dmp UNIX for Advanced & Expert Users 4 12-17-2007 04:48 AM
How to delete Directory and inside files using Find command bmkreddy SUN Solaris 3 07-10-2007 02:35 PM
How to check if 3 files have same size in directory oggle Shell Programming and Scripting 5 02-16-2005 11:51 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-27-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 357
files of size 0 need to be deleted inside a directory

Hiiii,

I have written a script which takes backup of some log files.
let say the backuplocation is ---

/abc/backuplocation

-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt23994.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3601.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3619.log
-rw-r----- 1 webmut2 spgroup 1551 Jan 25 07:13 ansrpt3619.log

after taking the backup i have to delete the files and then touch the files so that it create the file but with size 0 this is required in the script.

suppose the location of the files that need to backed up is---

/namish/logs
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt23994.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3601.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3619.log


My script is working fine for all these but a problem is coming ie when i am touchng the files they are still under the directory /namish/logs,when again i ran the script,my script is picking these files(files with size 0) also and taking the backup.I do not want this because this time the size of the file will be 0.

My script should delete the files from the backuplocation whose size is 0.

The script is -----
Code:
l) BackupLocation="$OPTARG"
                if [[ $BackupLocation != *backup ]]; then
                        echo "Appending backup subdirectories"
                        BackupLocation=$BackupLocation/backup
                        mkdir -p $BackupLocation >/dev/null 2>&1
                        if [[ $? != 0 ]];then
                        echo "First Create The Directory And Then Take backup"
                        fi
                        cd $FileLocation
                        pwd
                        cp -R $FilesToDelete $BackupLocation
                        list=$(ls *log*)
                        for files in $list
                        do
                         echo $files >namish1
                          rm -f $files
                          touch $files
                        done
                else
                        mkdir -p $BackupLocation >/dev/null 2>&1
                        cp -R $FilesToDelete $BackupLocation
                        for files in $list
                        do
                          rm -$files
                          touch $files
                        done
                if [[ ! -d $BackupLocation ]]; then
                echo "Unable to make backup directory: $BackupLocation"
                        if [[ $IsCronJob -eq 1 ]]; then
                          SendMiddleTierCleanMail "Middletierclean error message" $mt_clean_errfile
                        fi
                        return $E_INT_MISSING_DIR
                fi
                fi
                l_flag=Y
                Llcron=l
                ;;
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-27-2008
awk awk is offline
Registered User
 

Join Date: Feb 2007
Posts: 133
how about

ls -l | awk '/ 0 /{print $NF}' | xargs rm -f

of course, you could do a system call within the awk, and forget the xargs.

Dont forget the spaces around the "0"
Reply With Quote
  #3 (permalink)  
Old 01-28-2008
dj -------
 

Join Date: Feb 2007
Location: Cochin/Bangalore, India
Posts: 482
Try this: This will delete 0 byte files in the current directory

Code:
find . -name "*" -size 0b -maxdepth 1 -type f -exec rm {} \;
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 04:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66