LinuxQuestions.org
Review your favorite Linux distribution.
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 11-21-2008, 09:12 AM   #1
ddenton
Member
 
Registered: May 2007
Posts: 114

Rep: Reputation: 15
Can you move a file or directory and still retain mtime?


There's no switch in the man for mv, but I was wondering if anyone knew a novel way to retain the mtime without resorting to using cp -p?

Thanks...
 
Old 11-21-2008, 09:41 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Not w/o getting inventive, i.e, there's no switches that
allow mv to do that, but you could script a solution, grabbing
stat output for a file, mv it, and then touch the target with
the timestamp(s). Might be more hassle than cp.
 
Old 11-21-2008, 09:42 AM   #3
Tuttle
Senior Member
 
Registered: Jul 2003
Location: Wellington, NZ
Distribution: mainly slackware
Posts: 1,291

Rep: Reputation: 52
Make a file:
Code:
vim /usr/local/bin/mmmv
that contains this:
Code:
#!/bin/bash
cp -p $1 $2
rm $1
exit
do:
Code:
chmod +x /usr/local/bin/mmmv
and use mmmv instead!

Last edited by Tuttle; 11-21-2008 at 09:45 AM.
 
Old 11-21-2008, 04:54 PM   #4
ddenton
Member
 
Registered: May 2007
Posts: 114

Original Poster
Rep: Reputation: 15
Thanks Tuttle, that seems to have worked swimmingly. Also thanks to Tinkster for the reply!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to move files beyond cutoff date in subfolders and retain directory structure Erik Mesoy Linux - Newbie 2 03-16-2008 08:58 AM
Why won't it let me copy or move a file from one directory to another? dewjunkie Linux - Newbie 4 01-23-2008 12:31 AM
how do i get permission to move file into directory timalan SUSE / openSUSE 2 08-24-2005 09:25 PM
mtime/ctime changed on directory entries stardot Linux - Security 2 11-29-2004 10:44 PM
Is it possible to move file from /dev to other directory? raindrop Linux - Hardware 2 11-13-2002 05:37 PM

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

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