Solved

CP

Posted on 2012-03-11
6
315 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
Comment Utility
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
Comment Utility
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
Comment Utility
What you want to use is rsync, eg:

rsync -av --stats --progress /source/dir /dest/dir
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 44

Accepted Solution

by:
Darr247 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
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…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now