How to copy groups of files at once?
Hi,
I've been working on this all morning and I cannot figure it out.
I'm running Ubuntu Server 8.04.4 and I have directories on an ext3 partition (SOURCE) that I would like to copy. I have a USB drive (DESTINATION) connected to the server and mounted NTFS.
#1
I want to copy files from the SOURCE with "preserve" or "-p." I am interested in keeping the timestamps, owner, permissions, etc. Is this just not possible or am I missing something?
#2
I want to give the copy command through BASH and not copy duplicates. If the server asks whether to overwrite/replace, I want the default answer to just be "no." I do not want to sit at the computer for days attending to this copy typing no. Researching all morning, I thought I was golden with the "--reply=no" argument. I then found that this argument was deprecated and did not work (oh, the joy).
On testing, my workaround command was
yes "no" | cp -r /SOURCE/ /DESTINATION/
This worked to preserve the timestamp on the directory. However, it re-copied the (already existing) files in the directory with today's timestamp. This makes the job much longer than it needs to be and messes up the timestamp.
To summarize, I want to copy only directories/files that are not already at the (NTFS) destination and preserve the timestamps, etc. with the directories/files that are copied. I already have a large number of other files on this USB drive for another project so I can't just reformat to, say, ext3 (although it seems that might be easiest at this point) Can this be done? Thanks.
Mark
Comments
-
If you mean to use this for backup then I recommend using rsync to run the backup mechanisn because rather than always trying to replace each files, it only updates with mising or updated files. A good guide was written at http://www.linux.com/news/enterprise/storage/8200-back-up-like-an-expert-with-rsync.
If you still want to use the cp command then "cp -a -u" should work, read the manual (http://unixhelp.ed.ac.uk/CGI/man-cgi?cp) to see exactly what they do.
Now for the real issue, your attempt to copy the files including all attributes will fail because the permissions cannot be retained when you are copying from a unix type file-system (ext3) to a windows filesystem (ntfs) because the windows filesystem permissions are different.0 -
In addition to rsync, you may also want to consider cpio in copy-pass mode. Both tools are generally faster than cp and can preserve all the attributes you want to preserve (assuming destination file system compatibility).
find /path/to/old/dir -depth -print | cpio -pamd /path/to/new/dir
-p is copy-pass mode
-a preserve file's access time
-m preserve file's modification time
-d create directories as needed0
Categories
- All Categories
- 177 LFX Mentorship
- 177 LFX Mentorship: Linux Kernel
- 769 Linux Foundation IT Professional Programs
- 379 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 75 DevOps IT Professional Program - Discontinued
- 7 DevOps & GitOps IT Professional Program
- 102 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 7 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 16 Cloud & Containers Training
- 2 Cybersecurity Training
- 2 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 2 Networking Training
- 2 Open Source Best Practice Training
- 4 System Administration Training
- 1 System Engineering Training
- 2 Web & Application Development Training
- 796 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 91 Storage
- 771 Linux Distributions
- 81 Debian
- 68 Fedora
- 23 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 466 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 79 Network Management
- 101 System Management
- 46 Web Management
- 127 Mobile Computing
- 20 Android
- 92 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 401 Off Topic
- 125 Introductions
- 32 Study Material
- 1K Programming and Development
- 310 Kernel Development
- 705 Software Development
- 1K Software
- 409 Applications
- 182 Command Line
- 5 Compiling/Installing
- 70 Games
- 318 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)