LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 03-18-2006, 06:15 PM   #1
Jim Deakin
LQ Newbie
 
Registered: Dec 2005
Posts: 5

Rep: Reputation: 0
'mv' retaining file attributes?


I know that if you use cp, you can use '-a' or '-p' to preserve attributes and datestamps, but is there an alternative to mv that does the same? I can't find any mv options that do it. Maybe a script?

Thanks in advance
 
Old 03-18-2006, 10:38 PM   #2
pcweirdo
Member
 
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58

Rep: Reputation: 15
mv only changes the file name and which directory it is in. The file attributes are not touched.
Code:
pcweirdo@baghdad ~ $ ls -lt 180527
-rw-r--r--  1 pcweirdo root 3723 Jan  9 23:19 180527
pcweirdo@baghdad ~ $ stat 180527
  File: `180527'
  Size: 3723            Blocks: 8          IO Block: 4096   regular file
Device: 341h/833d       Inode: 9977863     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  500/pcweirdo)   Gid: (    0/    root)
Access: 2006-01-09 23:19:33.000000000 +1100
Modify: 2006-01-09 23:19:33.000000000 +1100
Change: 2006-01-09 23:25:33.000000000 +1100
pcweirdo@baghdad ~ $ mv -v 180527 180527-x
`180527' -> `180527-x'
pcweirdo@baghdad ~ $ ls -lt 180527-x
-rw-r--r--  1 pcweirdo root 3723 Jan  9 23:19 180527-x
pcweirdo@baghdad ~ $ stat 180527-x
  File: `180527-x'
  Size: 3723            Blocks: 8          IO Block: 4096   regular file
Device: 341h/833d       Inode: 9977863     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  500/pcweirdo)   Gid: (    0/    root)
Access: 2006-01-09 23:19:33.000000000 +1100
Modify: 2006-01-09 23:19:33.000000000 +1100
Change: 2006-03-19 15:37:09.000000000 +1100
pcweirdo@baghdad ~ $ date
Sun Mar 19 15:37:22 EST 2006
I'm especially pleased about the inode number and access times.

If you don't trust it, or your version of mv is different to my one (or I just fail miserably at this kind of analysis), have a script do this:
  1. Run 'ls -l' or more likely 'stat' on the file to get its attributes.
  2. Move the file using vanilla 'mv'.
  3. Use chmod, chown, chnappy, and a bunch of other fun apps to set the attributes as per the results of (1) above.
I recommend Perl or PHP for this.

I'm glad you're into the -a and -p options; I like them too.

-pcweirdo.
 
Old 03-19-2006, 12:02 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
by default, mv does not change attributes or date stamps.
Actually, it is useful to think of mv as a "rename" command---ie you rename "file" to "dir/file"

and of cousre mv is used rename in place---as in:
mv file newfile

Last edited by pixellany; 03-19-2006 at 12:05 AM.
 
Old 03-19-2006, 12:20 AM   #4
pcweirdo
Member
 
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58

Rep: Reputation: 15
Gee, that's a good summary.

-pcweirdo.
 
Old 03-19-2006, 05:24 AM   #5
Jim Deakin
LQ Newbie
 
Registered: Dec 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for that
I'd just been moving some files for someone with zero Linux knowledge, and they'd mentioned in an aside that the dates had changed both for copies and moves. They were lying about the moves!
Next time I'll check what they're claiming first, Thanks for all the extra info though
 
Old 03-19-2006, 11:14 AM   #6
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,401

Rep: Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119
The rsync command is quite handy for this. It does a good job, can retain a lot of attribute information, and (despite its name) copies just fine from one system to itself.
 
  


Reply


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
FAT file attributes lillig Linux - General 5 03-28-2013 11:42 AM
Changing File Attributes terdbird Slackware 6 04-23-2005 03:39 AM
uploaded file on vsftpd has wrong file attributes rune.kg Linux - Newbie 2 03-06-2004 09:23 AM
file attributes binky22 Linux - Newbie 2 09-26-2003 04:17 PM
Changing file attributes from C sourceman Linux - General 3 04-23-2002 07:37 PM


All times are GMT -5. The time now is 01:46 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