• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1386
  • Last Modified:

AIX shell script loop and move

I need a shell script for AIX unix that will let me specifiy a starting directory and then loop through all the sub-directories and files and move them according to the sub-directory they were located in.  For example.

If I start in a directory named "tommy" and I have three sub-directories named "a", "b", and "c" then I want to move all the files located in "a" to a specific folder name "newfoldera", and so forth.  Keep in mind, one of the sub-directories could also have a sub-directory in itself so the script would need to be recursive. Thanks in advance for the help on this!
0
Quetysis
Asked:
Quetysis
2 Solutions
 
rockiroadsCommented:
I guess a number of ways

imagine we had a variable

SD="/mydir/old"
ND = "/mydir/new"

firstly, there is cp and with cp you can specify -r

cd $SD
cp -r * $ND

I dont have my unix box handy, I dont even know if its available on AIX Unix

another is find, trying to remember my syntax

cd $SD
find . -print | cpio -pmvd $ND


another is tar

cd $SD
tar cvf /tmp/flist *
cd $ND
tar xvf /tmp/flist


for testing purposes, dont delete until u know its fine
then when u do, just issue

cd $SD
rm -rf *




0
 
ahoffmannCommented:
find tommy -print | sed -ne '/a\//s#\(.*\)/\(a/\)\(.*\)#mkdir \1/newfolder\2;mv & \1/newfolder\2\3#p'

if that returns what you want, simply add
  |sh
to execute it
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now