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?

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

Hi,

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

Regards,
Birei

Heres where I am at.

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.

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.

$ 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

Thank you for the feedback. Here's where I'm at now.

 
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?

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:

$ 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

Made your suggestions, heres my output

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

Using KSH on AIX btw..

Try deleting print0 and -d ''. You can get the job done without problem if your file names have not special characters like newline or similar.

Regards,
Birei.