- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- cp files only preserving timestamp
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2011 07:41 AM
тАО03-22-2011 07:41 AM
I need to copy files from a directory which has some sub directories in it. The problem is that I need only files - no directories and only files of certain extension ( *.srf ). Also i need to preserve the original time-stamp.
How can this be accomplished ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2011 08:14 AM
тАО03-22-2011 08:14 AM
Re: cp files only preserving timestamp
--------------------------------------
Example: From computer to another computer
On source computer
$>find /mysource -type f -name "*.srf" | xargs -i tar cvf myfiles.tar {}
Copy tar file to other computer, then extract from the tar file.
$> cd mydestination
$> tar xvf myfiles.tar
----------------------------------------
Example same computer, two diff directories
$> cd /mydestination
$>find /mysource -type f -name "*.srf" | xargs -i tar cvf - {} | tar xvf -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2011 05:24 PM
тАО03-22-2011 05:24 PM
Re: cp files only preserving timestamp
/bin/cp -p *.srf /destination/directory/
If you want srf files from the subdirectories too, then perhaps
/usr/bin/find /directory -type f -name "*.srf" -exec /bin/cp -p {} /destination \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2011 08:05 PM
тАО03-22-2011 08:05 PM
Re: cp files only preserving timestamp
> If you want [...]
If you described better exactly what you wish
to do, then we might avoid some of the
guessing. For example:
Where are (all) the files now?
Where would you like (all) the files to be?
Which information would you like preserved?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2011 06:54 AM
тАО03-23-2011 06:54 AM
Solutioncp --preserve=timestamps /source/dir/*.srf /destination/dir/
Since there is no option "-r", directories will not be copied: the cp command will output "cp: omitting directory /source/dir/something.srf" if it finds a directory that would match the *.srf wildcard. But this is information only.
If there are more files than will fit on a single command line (i.e. the above command will produce a shell error message because wildcard expansion fails), a bit more is needed. For example:
Create a script /usr/local/bin/cpto, to allow specifying the copy destination first:
----
#!/bin/sh
DEST="$1"
shift
cp "$@" "$DEST"
----
chmod a+x /usr/local/bin/cpto
Then, perform the copy operation:
cd /source/dir
ls -l | grep '^-.*\.srf$' | awk '{print $9;}' | xargs /usr/local/bin/cpto /destination/dir
This is not limited by maximum command line length, like shell wildcard expansions are.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2011 11:55 AM
тАО03-23-2011 11:55 AM
Re: cp files only preserving timestamp
This will copy all the files and directories. I need to get only *.srf files from certain directory and it's sub directories preserving the original time-stamp.
Reagrds
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-24-2011 09:25 AM
тАО03-24-2011 09:25 AM
Re: cp files only preserving timestamp
"cp --preserve=timestamps /source/dir/*.srf /destination/dir/"
Thus, you'll have to go back to the find|xargs|tar command I posted above. The reason I recommend tar is that it does preserve timestamps on recovery. See my perfectly working 4 point suggestion with options posted above. :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-24-2011 10:51 AM
тАО03-24-2011 10:51 AM
Re: cp files only preserving timestamp
> [...]
I'll see your 4-point suggestion and raise
you my 0-point request for a problem
statement which was clear enough that a
non-psychic could understand what the actual
task was.
For example, does "I need only files - no
directories" mean that all the files from
many source directories should end up in one
destination directory? It's a mystery which
only one person can resolve. And he's not
talking. (Or, if he is, then he's not saying
anything which I can understand. But my
opinion is apparently worthless.)