Solved

CP

Posted on 2012-03-11
6
322 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

730 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