LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-14-2007, 12:58 PM   #1
unkie888
Member
 
Registered: Aug 2007
Posts: 67

Rep: Reputation: 24
Unhappy the cp (copy) command in linux


Hi,

I think there may be something wrong with the cp command (copy).

I have a link pointing at nothing. It used to point at a file called "no" but that file is now gone.

I wish to copy the link exactly as is, preserving ownership and timestamp.

According to the Man page, cp -a should do this, however imagine my surprise when the timestamp changed.

[root]# cp -a x.x y.y
[root]# ls -lrt x.x
lrwxrwxrwx 1 root root 2 Aug 14 17:28 x.x -> no
[root]# ls -lrt y.y
lrwxrwxrwx 1 root root 2 Aug 14 18:49 y.y -> no
 
Old 08-14-2007, 01:34 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
Hmmm - it worked on my FC4 box.

What distribution and kernel are you running?
cat /etc/issue
uname -a

It may be you have an old binutils that needs to be updated.

Also type "which cp" to see where it is finding the cp command. If it shows an alias that may be your issue. If it shows a file then type "file <pathto/cp> to verify it is a binary rather than a script.
 
1 members found this post helpful.
Old 08-14-2007, 02:09 PM   #3
unkie888
Member
 
Registered: Aug 2007
Posts: 67

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by jlightner View Post
Hmmm - it worked on my FC4 box.

What distribution and kernel are you running?
cat /etc/issue
uname -a

It may be you have an old binutils that needs to be updated.

Also type "which cp" to see where it is finding the cp command. If it shows an alias that may be your issue. If it shows a file then type "file <pathto/cp> to verify it is a binary rather than a script.
[root]# uname -a
Linux bk1.localdomain 2.6.20-1.2320.fc5 #1 Tue Jun 12 18:50:38 EDT 2007 i686 i686 i386 GNU/Linux
[root]# cat /etc/issue
Fedora Core release 5 (Bordeaux)
Kernel \r on an \m

I installed FC5 from a CD then did yum update kernel.

I have also tried it calling /bin/cp directly - it is a binary.

[root]# file /bin/cp
/bin/cp: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
 
Old 08-14-2007, 02:14 PM   #4
unkie888
Member
 
Registered: Aug 2007
Posts: 67

Original Poster
Rep: Reputation: 24
Set timestamp on a link (that's not pointing at anything)

Ok...

Is there a way to set a timestamp on a link?

Basically I just need to get the mtime on the copy to be the same as the mtime on the original...

any suggestions ??

 
Old 08-14-2007, 02:19 PM   #5
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 60
You might also look in /~/.bashrc or some such file to see if cp is aliased in some fashion.

For instance $ which ls ... on my system returns:
/bin/ls ... no suggestion of trickery, ...

...but /~/.bashrc contains the line:
alias ls='ls --color=auto'

Big difference.
 
Old 08-14-2007, 02:34 PM   #6
unkie888
Member
 
Registered: Aug 2007
Posts: 67

Original Poster
Rep: Reputation: 24
hi rickh,

it was aliased to "cp -i" but it shouldn't matter - and i tried calling /bin/cp directly as well.

maybe i can forget cp and just set the link somehow??

touch doesn't seem to work either... ???

[root]# touch -c -m -t 200708141750 y.y
[root]# ls -lrt y.y
lrwxrwxrwx 1 root root 2 Aug 14 20:27 y.y -> no
 
Old 01-10-2009, 11:46 AM   #7
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: PCLinuxOS 2010.12, Debian Lenny
Posts: 387

Rep: Reputation: 38
Quote:
Originally Posted by unkie888 View Post
hi rickh,

it was aliased to "cp -i" but it shouldn't matter - and i tried calling /bin/cp directly as well.

maybe i can forget cp and just set the link somehow??

touch doesn't seem to work either... ???

[root]# touch -c -m -t 200708141750 y.y
[root]# ls -lrt y.y
lrwxrwxrwx 1 root root 2 Aug 14 20:27 y.y -> no
I see your dilemma, my system does the same thing.

Kubuntu 8.04

Did you find a work around ?
 
Old 01-10-2009, 03:18 PM   #8
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,473

Rep: Reputation: Disabled
From the GNU manual at http://www.gnu.org/software/coreutil...vocation.html:

Quote:
In general, it is not possible to preserve these attributes when the affected file is a symbolic link
So, you may be out of luck.

Brian
 
1 members found this post helpful.
  


Reply

Tags
copy, cp, link, timestamp


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Sun's 'Project Copy Linux' not a Linux copy LXer Syndicated Linux News 0 07-29-2007 08:46 AM
copy command munna_dude Linux - General 19 06-21-2007 06:57 AM
Help on copy command Nishant Desai Linux - Software 3 09-20-2006 02:50 AM
help with command copy in xterm harys Linux - Software 1 04-07-2006 10:58 AM
Copy Command rlkiddjr Linux - General 2 05-07-2002 01:37 PM


All times are GMT -5. The time now is 01:56 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration