Operating System - HP-UX
1820262 Members
2871 Online
109622 Solutions
New Discussion юеВ

Re: Copy directory while preserving modification time.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

Copy directory while preserving modification time.

I have a directory /psoft which contain hundreds of files and subdirectories.

I would like to make a duplicate copy of this dir structure while preserving original modification times of all files and subdirectories underneath it.

I tried this command but didnтАЩt preserve the mtime.
#cp тАУr /psoft /psoftold (changes the modification time)

Thanks,

Gulam
Everyday Learning.
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: Copy directory while preserving modification time.

You could try using tar.

# cd /psoft
# tar -cf - . | (cd /psoftold ; tar -xf -)

In the first tar command it is 'tar-cf-.'

The second tar command is 'tar-xf-'.

Bill Hassell
Honored Contributor

Re: Copy directory while preserving modification time.

The -p option (as mentioned in the man page) will preserve the modification time, access time, file mode, user ID, and group ID as allowed by permissions (to quote the man page). If the amount space is significant, you might want use cpio like this:

cd /psoft
find . | cpio -pudlmv /psoftold

This is the fastest way to copy lots of files. Note that both tar and cpio will not handle large files (files larger than 2Gb) so the cp command would be needed in that case. To see whether there may be largefiles in this directory, use this command:

fsadm /psoft

(this assumes that the /psoft directory is a VxFS filesystem).


Bill Hassell, sysadmin
rariasn
Honored Contributor

Re: Copy directory while preserving modification time.

Hi Gulam,

Duplicate a directory hierarchy:

# cd olddir
# find . -depth -print | cpio -pdm newdir

More information: man cpio

rgs,

ran
Arunkumar.B
Trusted Contributor

Re: Copy directory while preserving modification time.

Hi Gulam,


use cp -p option it will preserve the Permissions & time stamp too...

You can also use tar&cpio but that limitation is u cannot take a copy of files more than 2 Gb

Necessity breaks iron
Arunkumar.B
Trusted Contributor

Re: Copy directory while preserving modification time.

Hi Gulam,


use cp -p option it will preserve the Permissions & time stamp too...

You can also use tar&cpio but that limitation is u cannot take a copy of files having size more than 2 Gb

Necessity breaks iron