Check file size and remove files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check file size and remove files
# 1  
Old 04-13-2006
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  
Old 04-13-2006
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  
Old 05-28-2009
Power 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  
Old 05-28-2009
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  
Old 05-28-2009
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  
Old 05-28-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check total files size in hdfs directory?

Is there a way to calculate the total file size of HDFS file directory in GB or MB? I dont want to use du/df command. Without that is there a way HDFS Directory - /test/my_dir (1 Reply)
Discussion started by: rohit_shinez
1 Replies

2. Shell Programming and Scripting

File size check

I am trying to check whether two files are empty or not using below if condition but its checking for only one file if ] Again I tried if && ] Need your assistance (2 Replies)
Discussion started by: Aditya_001
2 Replies

3. Shell Programming and Scripting

Check a file size

I'm doing a script thats check if mylogfile.log is bigger then 5000 but i dont know how to write it. thanks in avance. (6 Replies)
Discussion started by: Froob
6 Replies

4. Shell Programming and Scripting

check the file size

if ; then cp /tmp/testfolder/*.* ~/new/logs/ else echo "No files today" exit fi The problem is this doen't work when there is more than 1 file. Please tell me how to take the latest file and check the size of the file in a directory (1 Reply)
Discussion started by: sandy1028
1 Replies

5. Shell Programming and Scripting

To remove the files in MB size

Hi, Using the shell script, I need to remove the files that are larger than 50 MB in size. I am not good in shell scripting. (1 Reply)
Discussion started by: gsiva
1 Replies

6. Shell Programming and Scripting

To remove files with 0 File Size

Dear All, I want to remove files having size of (0) that are generated once script is completed. Here is the code but i m not sure about /usr/bin do i need to write /usr/bin, or the path of my script /tmp/test please find below the script logic #!/usr/bin/ksh for i... (9 Replies)
Discussion started by: jojo123
9 Replies

7. Shell Programming and Scripting

Check for file size is zero or not.

I have following script on AIX/KSH if ] ; then echo "filename exists and is > 0 bytes" else echo "filename does not exist or is zero length" fi It is not working. What is wrong here??? (3 Replies)
Discussion started by: Hangman2
3 Replies

8. UNIX for Dummies Questions & Answers

Check the size of files

Hi, I need to put a script working to see in a directory with logs if exists file or files with size more than 12Mb. If exists it shoul send mail. Can anyone help me? thanks (3 Replies)
Discussion started by: osramos
3 Replies

9. Shell Programming and Scripting

How to check if 3 files have same size in directory

I need to determine if any three files have the same file size in a specified directly? I have got as far as listing the file sizes but where to go from here? ls -al |sort -n -r +4 | awq '{print $5}' Thanks in anticipation (5 Replies)
Discussion started by: oggle
5 Replies

10. Shell Programming and Scripting

remove files with 0 size, space and double qoute

os=hpux11 shell=ksh some jokers had written thousands of empty files into my $HOME. and the files are named inconsistently that some of them include space and double qoutes. all those files are of 0 size (when i did ls -al it told me so). the naming paterns are like e.g of ls -al output: ... (3 Replies)
Discussion started by: nongrad
3 Replies
Login or Register to Ask a Question