Moving a file based on size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving a file based on size
# 1  
Old 08-15-2011
Moving a file based on size

hello,

I am creating a script that is going to scan the contents of a directory, and if it finds a certain DocumentName that is a certain size (The example, DocumentName and a size of 8777)

If this file exists, it needs to be moved to a directory for later removal/processing..anyone have insight on this?

Code:
ls -l /Directory/subdirectory/DocumentName.*.Business.Qualifier.Status.pdf awk '{
 if ($5 = 8777) { print "mv " $7 " /Directory/forremoval" }}
 }'

# 2  
Old 08-15-2011
Hi,

You can use 'find' command with options '-name', '-size' and '-exec ...'

Regards,
Birei
# 3  
Old 08-16-2011
Heres where I am at.

Code:
find /Directory/sub/files/1/pdf -type f -name "branch.*.business.*.PDF.status" -size 1111 | while read name
do
 fname=`basename $name | sed 's/\(.*\)\..*/\1/'`
 touch $name /garbage_collector 
done

Looking for the branch.business.*(Some kind of time stamp).pdf.status
if it finds that file name, that is 1111 bytes, move it to the /garbage_collector directory. It is still not working for me.
# 4  
Old 08-16-2011
Hi,

I need indicate 'units of space' in the '-size' parameter, see my example with no output in the first command and the correct file in the second. I hope it helps.
Code:
$ ls -l script.*
-rw-r--r-- 1 birei birei 805 ago 16 12:25 script.pl                                                                                                                                                                                              
-rw-r--r-- 1 birei birei 569 ago 16 12:20 script.pl~                                                                                                                                                                                             
-rw-r--r-- 1 birei birei  42 jul 27 09:26 script.sed                                                                                                                                                                                             
-rw-r--r-- 1 birei birei  64 jul 27 00:37 script.sed~                                                                                                                                                                                            
-rw-r--r-- 1 birei birei  66 ago 14 00:54 script.sh                                                                                                                                                                                              
-rw-r--r-- 1 birei birei  47 ago 14 00:54 script.sh~
$ find . -type f -name "script.*" -size 66 -print
$ find . -type f -name "script.*" -size 66c -print
./script.sh

Regards,
Birei
# 5  
Old 08-16-2011
Thank you for the feedback. Here's where I'm at now.

Code:
 
find /Directory/subdirectory/-type f -name "Business.*" -size 1111c -print

I issue this in the home/userid directory, and it displays the full file name located in the /Directory/subdirectory folder. The next step, is moving the file if it found. Can I have help with that?
# 6  
Old 08-16-2011
Hi,

Next bash script works in my system. It moves file 'script.sed' to the previous directory in the tree. The '-v' parameter of 'mv' is verbose, to show what moves from one directory to another. Adapt it to your situation:
Code:
$ cat script.sh
#!/usr/bin/env bash

find . -type f -name "script.*" -size 64c -print0 | while read -d '' file; do
        mv -v "$file" ..
done
$ bash script.sh
«./script.sed~» -> «../script.sed~»

Regards,
Birei
# 7  
Old 08-16-2011
Made your suggestions, heres my output

Code:
find: bad option -print0
test.sh: read: bad option(s)

Using KSH on AIX btw..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split the File based on Size

I have a file that is about 7 GB in size. The requirement is I should split the file equally in such a way that the size of the split files is less than 2Gb. If the file is less than 2gb, than nothing needs to be done. ( need to done using shell script) Thanks, (4 Replies)
Discussion started by: rudoraj
4 Replies

2. Programming

Perl - Moving file based upon filesize in folder

Hi I'm trying to look through a series of directories in A folder, lets just call it A: for example: A/1 A/2 A/3 Etc and I wish to move the files in the folder if they are bigger than a certain size into a structure like below: A/TooBig/1 A/TooSmall/1 A/TooBig/2 A/TooSmall/2... (1 Reply)
Discussion started by: PerlNewbRP
1 Replies

3. Shell Programming and Scripting

Moving files based on file name

Hi All, I have multiple files in the folder, I want to move those files into the other folder on based of name File names: Template_server1_01==> Template_server1_02==>To one directory /Server1 Template_server1_03==> Template_server2_01==> Template_server2_02==>To one... (9 Replies)
Discussion started by: sharsour
9 Replies

4. Shell Programming and Scripting

Moving files based on size (string to integer)

I have a log file that I want to archive out as it reaches 100MB. I am using the following to get the file size into a variable but get the error "line 5: filesize=$(wc -c < logfile.log) if then echo "is greater than 100M" else echo "is less than 100M" fi I'm sure there's something... (2 Replies)
Discussion started by: Flakman
2 Replies

5. Shell Programming and Scripting

Moving files based on file creation

Hi, I have a directory having so many number of files. Now I want to move the files which are older than one month (lets say) from this directory to another directory (say BKP dir). Simply, if file is olderthan one month move it from source1 dir to BKP1 dir. My file names doesn't have... (7 Replies)
Discussion started by: karumudi7
7 Replies

6. Shell Programming and Scripting

Split file based on size

Hi Friends, Below is my requirement. I have a file with the below structure. 0001A1.... 0001B1.. .... 0001L1 0002A1 0002B1 ...... 0002L1 .. the first 4 characters are the sequence numbers for a record, A record will start with A1 and end with L1 with same sequence number. Now the... (2 Replies)
Discussion started by: diva_thilak
2 Replies

7. UNIX for Dummies Questions & Answers

ftping a file based in the size

Hi, I want to connect to a remote machine using FTP, check for the size of a file there. If it is 0 bytes, then there is no need to ftp else i have to ftp the file. Any help will be highly appreciated. (7 Replies)
Discussion started by: vikas.rao11
7 Replies

8. Shell Programming and Scripting

file moving based on file content

Hi All my scenario is as follows... I have the following three files in directory alphabet, containing the respective character string... Filename Character String alphabet01.dat AAA alphabet02.dat BBB alphabet03.dat CCC based on... (12 Replies)
Discussion started by: melvyn.cochrane
12 Replies

9. Shell Programming and Scripting

Moving file to directory based on condition.

Can any one help me to correct following script. I have 2 directories DropZone and ProcessZone. File pattern is *VEHDESCSUM*. Finding the 'no of files' in DropZone directory using ls *VEHDESCSUM* |wc -l If DropZone has more than one file or 0 files then exit 1 If DropZone has one file then... (2 Replies)
Discussion started by: ramanagh
2 Replies

10. UNIX for Dummies Questions & Answers

Mail based on file size

Hi Friends, i am trying to write a shell script which will check for the logfile size. if the content of the logfile is wc -l >=1 then send mail with log file as attachment.else do nothing. i'm trying the below code can any one help on this if ] then (echo "`cat... (2 Replies)
Discussion started by: rajendragora
2 Replies
Login or Register to Ask a Question