LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-25-2009, 02:04 PM   #1
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,378

Rep: Reputation: Disabled
using cp -u command


Would someone explain to me how to use "cp -u" properly, or what I'm doing wrong in using it? According to man cp, it is supposed to back up only files that had changed since the last backup or files that don't exist on the last backup. So I entered this:
Quote:
josh@mepis1:~$ cp -u '/home/josh' '/mnt/sdb1/josh'
which resulted in only this:
Quote:
cp: omitting directory `/home/josh'
Why did that happen? I'm sure I have at least one file in the source folder and subfolders that has been changed.

Last edited by newbiesforever; 10-25-2009 at 02:05 PM.
 
Old 10-25-2009, 02:32 PM   #2
janoszen
Member
 
Registered: Oct 2009
Location: Budapest
Distribution: Mostly Gentoo, sometimes Debian/(K)Ubuntu
Posts: 143

Rep: Reputation: 22
CP

Why not try /my/folder/* ?
 
Old 10-25-2009, 02:33 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
From the cp man page:
Quote:
DESCRIPTION
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Try modifying your command to include multiple sources to the desired directory:
Code:
josh@mepis1:~$ cp -u '/home/josh/*' '/mnt/sdb1/josh'
Note the /* after /home/josh.
 
Old 10-25-2009, 03:26 PM   #4
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,378

Original Poster
Rep: Reputation: Disabled
Okay, I just tried that. The response was:
Quote:
cp: cannot stat `/home/josh/*': No such file or directory
That's very odd...it sure sounded as though it would work.

Last edited by newbiesforever; 10-25-2009 at 03:34 PM.
 
Old 10-25-2009, 03:36 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Do away with the single quotes, use double quotes if you have to.

Single quotes prevents bash from doing expansion, so /home/josh/* is taken literal (a file called * in /home/josh).

Hope this helps.
 
Old 10-25-2009, 03:43 PM   #6
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Alternately, use cp's -r option
 
Old 10-25-2009, 03:53 PM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@AlucardZero: You need to loose the single quotes, even when using -r. Expansion is done before the cp command takes effect.

I do suspect that newbiesforever's initial command (cp -u '/home/josh' '/mnt/sdb1/josh') would have worked without the single quotes (ie: cp -u /home/josh /mnt/sdb1/josh).
 
Old 10-25-2009, 03:59 PM   #8
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
If it has a voiced Z sound, then it’s “lose.” If it has a hissy S sound, then it’s “loose.” Here are examples of correct usage: “He tends to lose his keys.” “She lets her dog run loose.” Note that when “lose” turns into “losing” it loses its “E.”

Code:
alucard@organa:/tmp$ mkdir -p a/b/c
alucard@organa:/tmp$ mkdir -p d
alucard@organa:/tmp$ cp a d
cp: omitting directory `a'
alucard@organa:/tmp$ cp 'a' 'd'
cp: omitting directory `a'
alucard@organa:/tmp$ cp -r 'a' 'd'
alucard@organa:/tmp$ ls d/a/b
c
alucard@organa:/tmp$ mkdir a/e
alucard@organa:/tmp$ ls d/a
b
alucard@organa:/tmp$ cp -ur 'a' 'd'
alucard@organa:/tmp$ ls d/a
b  e
There is no expansion in the following command because there are no wildcards:
Code:
josh@mepis1:~$ cp -u '/home/josh' '/mnt/sdb1/josh'
The crux of the matter is that cp does not recurse (sub)directories unless you tell it to.

Last edited by AlucardZero; 10-25-2009 at 04:00 PM.
 
Old 10-25-2009, 04:18 PM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
What are you trying to say with the cp examples?

If you put files inside the directories you'll see it fails:

Code:
mkdir -p a/b/c
mkdir -p d
touch a/{1,2} a/b/{3,4} a/b/c/{5,6}
ls  a a/b a/b/c
a:
1  2  b
a/b:
3  4  c
a/b/c:
5  6

cp a d (omitted, same result)
cp 'a' 'd' (omitted, same result)

cp -r 'a' 'd'

ls -l *
a:
total 4
-rw-r----- 1 druuna internet    0 Oct 25 22:08 1
-rw-r----- 1 druuna internet    0 Oct 25 22:08 2
drwxr-x--- 3 druuna internet 4096 Oct 25 22:08 b

d:
total 4
drwxr-x--- 3 druuna internet 4096 Oct 25 22:08 a

ls d/a/b
3  4  c
file 1 and 2 are missing from d, same is tru for the cp -ur 'a' 'd' command.

This cp -r a/* d will work. Without the single quotes!
 
Old 10-25-2009, 04:29 PM   #10
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,378

Original Poster
Rep: Reputation: Disabled
what is copying files recursively?

Okay, I'll try these procedures, but I don't understand what copying files recursively (cp -r) means. I saw it in man cp, but since I didn't understand what copying files recursively meant, I didn't know how it could help me.
 
Old 10-25-2009, 04:36 PM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

If you use: cp /somedir/* /someotherdir only the files in /somedir/ are copied, not the subdirectories and all its files.

The -r option tells cp that it should also copy subdirectories and its files.

I think you are looking for something like this: cp -ur /home/josh/* /mnt/sdb1/josh/

Hope this helps.
 
Old 10-25-2009, 04:40 PM   #12
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,378

Original Poster
Rep: Reputation: Disabled
Yes, thank you. If that's what it means, I guess I obviously need it. Since I understand only in the most abstract sense what recursion means (procedures referring to themselves), I thought it might be more complicated than copying all the subdirectories and their files.
 
Old 10-25-2009, 05:09 PM   #13
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Quote:
Originally Posted by druuna View Post
What are you trying to say with the cp examples?
That this statement
Quote:
I do suspect that newbiesforever's initial command (cp -u '/home/josh' '/mnt/sdb1/josh') would have worked without the single quotes (ie: cp -u /home/josh /mnt/sdb1/josh).
is incorrect.

Code:
alucard@organa:~$ mkdir -p a/b/c
alucard@organa:~$ touch a/b/c/{d,e}
alucard@organa:~$ mkdir f
alucard@organa:~$ cp -u a f
cp: omitting directory `a'
alucard@organa:~$ cp -u 'a' 'f'
cp: omitting directory `a'
alucard@organa:~$

Other than that I think we're saying the same thing.
 
Old 10-25-2009, 05:23 PM   #14
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,378

Original Poster
Rep: Reputation: Disabled
cp -r appears to have worked, judging by the new dates of files and folders in the backup copy--they are reflecting the date and time they were changed. But in the console window, the output stopped displaying for some reason. After displaying
Quote:
cp -ur '/home/josh' '/mnt/sdb1'
...it never continued, but never returned to the command prompt either.

Last edited by newbiesforever; 10-25-2009 at 05:25 PM.
 
Old 10-25-2009, 06:09 PM   #15
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
It was probably still going. Give it -v too. And I like -a as well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT! Is there any command to get a history command lines and time in SUSE Linux.? igsoper Linux - Software 5 06-25-2009 02:14 AM
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 06:30 PM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 06:02 AM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration