How can I not transfer directories recursively using Perl or shell?

We are moving home folders to the new file system, and I'm looking for a way to automate it using Perl or a shell script. I don't have much choice in programming languages, since systems are proprietary storage clusters that should remain unchanged as much as possible.

Task: In the directory / home / I have the home folders of different users aaa, bbb, ccc, ... and they have certain access rights and the rights of the user / group, which should remain intact when going to / newhome /. Here is an example of what you need to migrate from / home:

drwxr-xr-x    3 aaaaa    xxxxxxxxx   4096 Feb 26  2008 aaaaa/
drwxrwxrwx   88 bbbbbbb  yyyyyy      8192 Dec 16 16:32 bbbbbbb/
drwxr-xr-x    6 ccccc    yyyyyy      4096 Nov 24 04:38 ccccc/
drwxr-xrwx   36 dddddd   yyyyyy      4096 Jun 20  2008 dddddd/
drwxr-xr-x   27 eee      yyyyyy      4096 Dec 16 02:56 eee/

Thus, the same folders with permissions and owners must be created in / newhome. Copying / moving files should not be a concern, as this will be processed later.

Has anyone worked on such a script? I'm really new to Perl, so I need help.

+3
source share
4 answers

cp-a flag will support resolution, modification time, etc. You should do something like:

for a in `ls /home`; do cp -a "/home/$a" "/newhome/$a" ; done

Try using one directory to see if it does everything you need before automating it.

EDIT: You can disable recursive copying of files using rsync or tar, as mentioned by Paul. With rsync, subdirectories are still saved, but files are not copied:

sudo rsync -pgodt /home/ /newhome/

tar -no-recursion, .

2:

find /home/ -maxdepth 1 -print | sudo cpio -pamVd /newhome

+8

, root. - tar cp -rp .

, , , , root. :

(cd /home; find . -depth) | cpio -pvdumB /newhome

-depth , , , . 'sort -r' , , .

+4

This will create directories and copy all files.

cd /home; tar cvBf - . | (cd /newhome; tar xvpBf -)

If you do not want to copy all the files, you can do this by adding "-no-recursion" to the first tar command.

+3
source

If these directories are on the same file system, why not just

cp -p /home/* /newhome/
+1
source

All Articles