Search through subfolders and move them into separate folder on the base of file size

Hello guys
I am sure that you will help me on this issue as you did earlier::slight_smile:
Scenario :
I have a folder named "XYZ". It consist many sub-folders and subfolder contain severals files. there may be abc.dat in each subfolder. Now i want to seperate subfolders on follwing conditions-
if abc.dat > 1kb (size) move all subfolders to folder healthy
if abc.dat <=1kb move all subfolders to folder unhealty
if there is no abc.dat move all subfolders to folder others.
So at the end we have 3 sub-folders named healthy, unhealty and others containing subfolders with differnt condition.

Please write a shell script for this .
Thanks in advance.

do your own work. Show some effort.. what have you got ? if you are lost, here's a hint. you can use the find command with its options to find size, etc. check the man page. read the documentation.

i am sorry but i would really appreciate if you give me the solution

i/we will give solution to those who put in effort. Also, i have been very kind to give you a hint already. another hint: use find command's -size option to find file sizes....so now, pull up your socks and start the ball rolling...

if you don't have capability to solve this why u r wasting my time.

He have the capability to solve but we are not here for answering the questions in the way you asked(unless you show some effort from your side). First learn to give respect to the senior forum members.

Read the forum rules before further posting.

How do you know that he having capability to do this. Different people have different capability and as far as mine is concern i am not mad to just post my problem for fun. Please try to understand . I already tried but cant solve it.
hope you will give me the solution. and sorry for any misunderstanding:)

so, your code, where is it since you said you tried ?

I think everybody here has the capability to answer your question. It is really very basic. If you want to learn coding, you should try to think and read manpages. The thing is, you do not want to put time and effort into your own problem but expect others to do so.

find /xyz -type f -name "abc.dat" -size +1024c -print

this is only printing the direcory having abc.dat more than 1 kb.
please guide me

Hi infiant ,

I tried but did not find any one line solution .

You can try something like this :

find . -name "abc.data" -depth -size +2c -print >> healthy_files.lst

find . -name "abc.data" -size -2c >> unhealthy.lst

find . ! -name  "abc.data" >> others.lst

Again for the distinct path names from these files you can move them.

I will put the complete script once i done it.

thanks. i will try with the script u have given. and also waiting for exact solution.

Hi infiant,

Here is my clumsy code which serves the need.

Pls test it thoroughly before using it in production.

  1. place the script in the path just before the search path . In your case in will be "/".

  2. change the size parameters according to your requirement.

  3. Assumed that you have created directories "HEALTHY","UNHEALTHY" and "OTHERS" in the proper path.

path="/disk1/jvsh/TEST/TES/FORUM"

## Replace the above bold one with the search path


pres=`pwd`

find $path  -name "abc.data"  -size +1c -print > healthy_files.lst

find $path  -name "abc.data" -size -3c > unhealthy.lst

find $path  ! -name  "abc.data" > others.lst

for file in `awk -F"/" '{$NF=" ";print }' OFS="/" healthy_files.lst | sort -u`
do
echo "$file"
mv  "$file" /disk1/jvsh/TEST/TES/HEALTHY ##put your healthy dirpath
done

for file in `awk -F"/" '{$NF=" ";print }' OFS="/" unhealthy.lst | sort -u`
do
echo "$file"
mv "$file" /disk1/jvsh/TEST/TES/UNHEALTHY 
##put your unhealthy dirpath in place of bold
done


for file in `awk -F"/" '{$NF=" ";print }' OFS="/" others.lst | sort -u `
do
echo "$file"
if [ "$file" = "$path""/" -o "$file" = "$pres""/" ];then
echo "nothing"
else
mv "$file" /disk1/jvsh/TEST/TES/OTHERS 2>/dev/null
fi
done

##put your others dirpath in place of bold

rm healthy_files.lst unhealthy.lst others.lst