Reputation: 276
I have main DIR X and inside this I have many sub directories like A,B,C,D. I have main DIR Y and inside this i have many sub directories with same name as X main directory sub directories like A,B,C,D.
Now I need to MOVE all the files from X main dir sub directories to Y main directory sub directory.
Eg:
Inside main directory X ,sub directory A has 100 files
and B has 1 file
and C has 5 files
and D has 50 files...
my cursor should be at main DIR X , from there I need to MOVE all the sub directory files to same named sub directories(A,B,C,D) which is there inside Y main directory.
how can I do this in SHELL SCRIPTING(KSH) or unix??
Upvotes: 0
Views: 147
Reputation: 20012
First of all you should get used to your unix environment. Unix commands can be very powerful, get used to it step by step and do not take advice that you do not understand. The links I will give here have beautiful information, but first try to learn the basics. Do not call your current dir or your homedir cursor, get used to lowercase characters and how to learn new commands in temporary directories.
First you asked about copy. man cp
or google unix copy
should give you plenty information. To copy from dir $HOME/a to dir $HOME/b, use
# go to $HOME dir
cd
# copy dirs not files including subdirs
cp -r a/*/ b
Move everything when dir is b is empty
cd
mkdir b
mv a/* b
More difficult is moving files when b already has some subdirs. mv
is not used for merging. When the existing content of b is old, the easiest way is to remove b first
cd
rm -r b/*
mv a/* b/
When you want to keep files in b, look at links like
mv equivalent rsync command
https://unix.stackexchange.com/questions/43957/using-rsync-to-move-not-copy-files-between-directories
and the nice answers at
https://unix.stackexchange.com/questions/9899/how-to-overwrite-target-files-with-mv
Upvotes: 1