Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 11-21-2008, 09:12 AM   #1
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?

Old 11-21-2008, 09:41 AM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
Senior Member
Registered: Jul 2003
Location: Wellington, NZ
Distribution: mainly slackware
Posts: 1,289

Rep: Reputation: 52
Make a file:
vim /usr/local/bin/mmmv
that contains this:
cp -p $1 $2
rm $1
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
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!


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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:40 PM.

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