Bulk moving files script?

Using applications, configuring, problems
Post Reply
Message
Author
hansol
Posts: 23
Joined: Sat 23 Nov 2013, 01:55

Bulk moving files script?

#1 Post by hansol »

Hi guys,

Been doing some googling on how to bulk move files. So far stuff on "recursive" moving, but that doesn't seem to be helping. So here's my situation. I have the following directory setup:

Code: Select all

 /mnt/folder/
-Clientname1
   ->2012
   ->2013
         -> clietnname1file.ext
-Clientname2
   ->2012
   ->2013
         -> clientname2file.ext
-Clientname3
   ->2012
   ->2013
         -> clientname3file.ext
What I need to do is get the .ext file moved to the client-specific "2013" folder. I can get the .ext file moved to a parent directory, or a specific target directory, but that isn't what I need in the circumstance. Currently I've come up with:

Code: Select all

for file in /mnt/folder/*/*.ext; do
        mv "$file" "$dir/2013"
done
But all this seems to do is make the .ext file disappear somewhere. Any help would be appreciated.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post by Flash »

Puppy comes with rsync. Maybe rsync is what you need? Copy Fast uses rsync.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#3 Post by mikeb »

What is $dir set to?

mike

hansol
Posts: 23
Joined: Sat 23 Nov 2013, 01:55

#4 Post by hansol »

Mike,

I want "$dir" to be the "2013" folder in the respective Clientname directory. I'm assuming this is where I'm making my error?

Thanks -Hansol
mikeb wrote:What is $dir set to?

mike

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#5 Post by mikeb »

well at a quick guess without seeing the rest of the code...yes

mike

hansol
Posts: 23
Joined: Sat 23 Nov 2013, 01:55

#6 Post by hansol »

:oops: that's literally all the code I have at current...
mikeb wrote:well at a quick guess without seeing the rest of the code...yes

mike

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#7 Post by mikeb »

ok well a preceeding
dir=/root

would help for example.....

There are many ways to crack these nuts

mike

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#8 Post by 8-bit »

You might modify your script slightly to specify the directory in sequence in your script using a variable.

I have a script that unzipped a number of zipped files in a directory by using a variable to specify part of the zipped file name.

To give you an idea, you would use the variable to specify the ClientnameX directory with the X being represented by a variable.

My script looks like;

Code: Select all

 #!/bin/bash
# An attempt to unzip multiple files
a=99
 for j in $(eval echo {31..$a});do
 

file="GAMES0"$j".ZIP";
a=a+1;
echo $file;
unzip -d /root/atr $file
done
You would change the file line to dir="Clientname"$j"/2013" and also for the file to be moved to "clientname"$j"file.ext".

And naturally the line that unzips to a move one worded appropriately.
I hope that helps.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#9 Post by 8-bit »

I do not know the Clientname directory locations or the clientnamefilex.ext directory so my script would need some cleanup.
But afterward, it should move all of those files to the respective directories.
I would suggest trying a small number using copy instead of move so you preserve your original *.ext files
Anyway this is my attempt.

Code: Select all

#!/bin/bash
# An lame attempt to move multiple files to multiple directories
a=99
 for j in $(eval echo {31..$a});do
 
dir="Clientname"$j"/2013"
file="clientname"$j"file.ext";
a=a+1;
echo $file;
mv "$file" "$dir"
done


Post Reply