The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 05: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 12:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-27-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
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
                ;;
  #2 (permalink)  
Old 01-27-2008
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
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"
  #3 (permalink)  
Old 01-28-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Cochin/Singapore
Posts: 515
Try this: This will delete 0 byte files in the current directory

Code:
find . -name "*" -size 0b -maxdepth 1 -type f -exec rm {} \;
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 12:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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