Solved

CP

Posted on 2012-03-11
6
323 Views
Last Modified: 2012-03-27
Good evening,
Im a newbie with linux, and Ive figured out I can do "CP -R" to copy all files and directories, which works great, but if Im doing several Gb, I have no idea how far its got, or if its failed.

Is it possible to add a parameter in to show me which files its copying/copied, and maybe the progress of the current file?

On another question, is it possible to tell it to skip files if they exist already, or overwire if it does exist.

Thank you
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 37707673
I don't know any way cp will show progress.  You might want to look at the -a option.

To not overwrite exisitng files, use -n.  You might also want to look at -u.

See http://linux.die.net/man/1/cp
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 37707675
I'm not sure what you want with overwrite if they exist.  I think you want -f.  Again, see the man page at http://linux.die.net/man/1/cp
0
 
LVL 48

Expert Comment

by:Tintin
ID: 37708079
What you want to use is rsync, eg:

rsync -av --stats --progress /source/dir /dest/dir
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 44

Accepted Solution

by:
Darr247 earned 500 total points
ID: 37708553
Look at these switches/parameters and see which of them you want to use...

# \cp -cfpv

the # means you're at root-level access (user-level access has $ prompt)
the \ makes it ignore parameters that have been stored as defaults and use only the parameters specified
the c makes it preserve the 'context' so SELinux shouldn't complain about wrong context
the f makes it 'force'  an overwrite
the p makes it preserve the date/time stamp, otherwise they're set to the moment copied
the v makes it verbose

other switches you might find useful immediately
the r makes it recursive
the n makes it NOT overwrite (aka "no-clobber")
the u makes it overwrite only if the file being copied is newer (another reason to use -p)

Without using \ you probably won't be able to use -f or -u, because I think most distros store -n (no-clobber) as a default, so cp ignores the overwrite and update switches.

In my opinion, the most important thing to know about linux commands is 'man' e.g.
$ man cp
and use PgDn/PgUp to scroll down/up through the help file. Press 'q' to quit man pages.
Any [command] you're not sure how to use, and what parameters it has, just run
$ man [command]
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 37709318
I'd like to note that running at the #, especially for commands you don't understand, is a bad idea, especially for a newbie unless it's a "sandbox" system that you are willing to reload (as people did a lot in the old days of Linux).
0
 
LVL 48

Expert Comment

by:Tintin
ID: 37774093
You are still much better off to use rsync.   For your purposes it will be way quicker and use much fewer resources.
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question