New Posts  All Forums:Forum Nav:

Recursive Move

post #1 of 27
Thread Starter 
How can I get the equivalent of mv -r so that it searches subdirectories also?

**EDIT 5/28**
Uploaded are both scripts (both are in perl). mvrec.txt will move all files of a given type in a given folder/subfolders into a single target folder. Copy it to /usr/bin/mvrec and run chmod u+x /usr/bin/mvrec (should require privledges). mvrec with no options will bring up the usage.

mvr.txt keeps folder structure intact. So if you have /foo/bar.txt and /foo/foo/foobar.txt and you want to move it to /bar the result is /bar/bar.txt and /bar/foo/foobar.txt. Install it in the same way as mvrec
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #2 of 27
If I'm right in thinking, mv is the Move command?
Isn't it just mv -r dir1 dir2?

dir1 being the directory you want to move, and dir2 being the target directory.

You said "so that it searches" subdirectories. Don't you mean the search function? If this is the case, use find filename or grep keyword, the latter searching inside text documents for the keyword.
    
CPUMotherboardGraphicsRAM
AMD X2 3800+ Manchester Asus A8N-SLi SE nForce4 BFG 8800GTS OC 640MB @ 661/2Ghz Nanya 1GB DDR400 
Hard DriveOptical DriveOSMonitor
160 GB WD Caviar Acer DVD+-RW 16x Windows XP Pro x64 Acer AL1916WS 19" Wide 
KeyboardPowerCaseMouse
Logitech Explorer Hiper Type-R Modular 580W Thermaltake Soprano Black Logitech 500 G-Optical 
Mouse Pad
£3 Generic :D 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD X2 3800+ Manchester Asus A8N-SLi SE nForce4 BFG 8800GTS OC 640MB @ 661/2Ghz Nanya 1GB DDR400 
Hard DriveOptical DriveOSMonitor
160 GB WD Caviar Acer DVD+-RW 16x Windows XP Pro x64 Acer AL1916WS 19" Wide 
KeyboardPowerCaseMouse
Logitech Explorer Hiper Type-R Modular 580W Thermaltake Soprano Black Logitech 500 G-Optical 
Mouse Pad
£3 Generic :D 
  hide details  
Reply
post #3 of 27
Thread Starter 
What I meant is that if you have this directory structure
one folder called foo with bar.m4a in it
one folder called bar with foo.m4a in it
Both in the working directory. I want to know how to move all files with extension .m4a in any subdirectory somewhere

The -r flag is not valid for mv

I came up with a workaround but I'm not very experienced with unix (just a few months) so I'm having problems. Here's what I came up with:
ls -R | grep .m4a | mv <target dir>
The problems are 1) ls -R does not print out the full path name (I can fix that) and 2) it is not piping the output of the grep to mv. mv is acting like <target> is it's input for source. Does anybody know how I can pipe to a certain argument?
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #4 of 27
Quote:
Originally Posted by rabidgnome229
ls -R does not print out the full path name (I can fix that)
How do you get it to display the full path with ls?
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #5 of 27
Thread Starter 
I only thought I could do that. Right now I'm trying a really messy way using find and a perl script - but the damn perl script won't work with |
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #6 of 27
LOL, I was writing a perl script too, its about done.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #7 of 27
Thread Starter 
How are you giving it input? I'm doing "find . -name *.m4a | ./full.pl"
The first part spits out a couple hundred files. All that the perl script does is echo the size of @ARGV, which it says is 0. What's wrong here?
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #8 of 27
On mine you have to enter the directory that contains all of the folders that may contain a .m4a file, and then you have to enter the final directory they are moved to.

EX)
>/home/hobo/test
>enter final:
/home/hobo/new

example of new after:
/home/hobo/new/directory_file_was_in_under_test_folder/file.m4a
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #9 of 27
Thread Starter 
Cool - could you upload it?
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #10 of 27
There is still something wrong with the move part. It worked once, but not on the other times.
I'll continue to mess with it but here it is so far:

Code:
#!/usr/bin/perl


use warnings;
use strict;

#print ("Must enter full path. EX) /home/user/  NOT) ~/\
\
");
#print ("Enter the directory path to the one you wish to search in.\
=>  ");
#my $o_dir = <STDIN>;
#chomp ($o_dir);

#print ("Enter final move location\
=> ");
#my $f_dir = <STDIN>;
#chomp ($f_dir);

# $o_dir is the original directory
# $f_dir is the directory the files will be moved too
#
my $o_dir = "/home/michael/test";
my $f_dir = "/home/michael/test/final";

my $list = `ls -R -1 $o_dir`;
print ("O: $o_dir\
F: $f_dir\
");
my @array = split(/\
/, $list);

my $mid; # The sub directory the file was under $o_dir
my $dir; # The full path to the directory the file is in
my $move; # Full path to the file to be moves
my $here; # Full path to where the file is to be moved

foreach my $m (@array){
if ($m =~ /:$|:\
$/){
$dir = $m;
chop ($dir);
$dir .= "/";
$mid = $dir;
        $mid =~ s/^$o_dir//;
$mid =~ s/[\\s*]/\\\\ /g;
my $temp = $f_dir."/".$mid;
`mkdir $temp`;
#print ("$dir\
");  # For debugging
#print ("$mid\
");  # For debugging
}elsif ($m =~ /.mp3$|.mp3\
$/){
my $file = $m;
$file =~ s/[\\s*]/\\\\ /g;
$move = $o_dir."/".$mid.$file;
$here = $f_dir."/".$mid.$file;
print ("$here\
");
`mv $move $here`;
}
}
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix