Solved

CP

Posted on 2012-03-11
6
320 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

778 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