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
Check all files in directories for string and remove.. possible? LordJezo Shell Programming and Scripting 7 11-30-2005 01:00 AM
file size check malaymaru Shell Programming and Scripting 2 10-19-2005 12:26 AM
Check file size alnita UNIX for Dummies Questions & Answers 6 06-20-2005 02:34 PM
How to check if 3 files have same size in directory oggle Shell Programming and Scripting 5 02-16-2005 12:51 PM
remove files with 0 size, space and double qoute nongrad Shell Programming and Scripting 3 02-08-2002 03:32 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-13-2006
srivsn srivsn is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 32
Check file size and remove files

Hi,
Here we have a situation where we have to check the file size and if the file size is greater than 0 bytes then remove the files from the directory.
1)EdwTrxn 2)EdwPost 3)EdwTndr 4)EdwSls 5)EdwSlsRej 6)EdwTndrRej
Files will be created in the directory in the following manner.
If any of the Rej files (5.EdwSlsRej 6.EdwTndrRej) size is greater than 0 bytes then we have to delete remaining 4 files (1.EdwTrxn 2.EdwPost 3.EdwTndr 4.EdwSls ).Else if Rej files size is 0 bytes then We have to remove those 2 Rej files(5.EdwSlsRej 6.EdwTndrRej) from the directory.
Thanks
  #2 (permalink)  
Old 04-13-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Something like this?
Code:
cd /directory/where/files/are/present
if [ -s EdwSlsRej -o -s EdwTndrRej ]; then
echo rm EdwPost EdwSls EdwTndr EdwTrxn
elif [ ! -s EdwSlsRej -a ! -s EdwTndrRej ]; then
echo rm EdwSlsRej EdwTndrRej
fi
This will delete the EdwPost EdwSls EdwTndr EdwTrxn files if any of EdwSlsRej or EdwTndrRej files are larger than 0 bytes, but delete EdwSlsRej and EdwTndrRej files if they *both* are 0 bytes. No action is taken in any other case.

N.B. Just remove the echo commands to actually delete the files.
  #3 (permalink)  
Old 05-28-2009
Reshma_4287 Reshma_4287 is offline
Registered User
  
 

Join Date: May 2009
Posts: 1
Red face Check file size and move to a folder

Hi,

I am new here.I want to write a script with following conditions -
1. I have files with name IF008*
2. If size of the file IF008* is 84 bytes then move it to junk folder
3. If size of the file IF008* is greater than 84 bytes then move it to tmp folder.

Please reply.
All ideas are appreciated.
  #4 (permalink)  
Old 05-28-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,837
A hint to get you started:
Code:
$ find dir/ -type f -name 'IF008*' -size 84c
$ find dir/ -type f -name 'IF008*' -size +84c
Send those into a loop or use -exec
  #5 (permalink)  
Old 05-28-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,508
you can combine the sizes together so there's no need to invoke 2 times
Code:
find dir/ -type f -name 'IF008*' \( -size 84c -o -size .........\)
  #6 (permalink)  
Old 05-28-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
Code:
find dir/ -type f -name 'IF008*' -size 84c -exec mv {}  junk/ \;
find dir/ -type f -name 'IF008*' -size +84c -exec mv {} tmp/ \;

-Devaraj Takhellambam
Sponsored Links
Reply

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 06:12 AM.


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