LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   the cp (copy) command in linux (https://www.linuxquestions.org/questions/linux-newbie-8/the-cp-copy-command-in-linux-577052/)

unkie888 08-14-2007 12:58 PM

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

MensaWater 08-14-2007 01:34 PM

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.

unkie888 08-14-2007 02:09 PM

Quote:

Originally Posted by jlightner (Post 2858790)
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

unkie888 08-14-2007 02:14 PM

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 ??

:scratch:

rickh 08-14-2007 02:19 PM

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.

unkie888 08-14-2007 02:34 PM

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

DaveQB 01-10-2009 11:46 AM

Quote:

Originally Posted by unkie888 (Post 2858860)
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 ?

BCarey 01-10-2009 03:18 PM

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


All times are GMT -5. The time now is 09:29 PM.