?
Solved

move file from one folder to another folder in unix/linux

Posted on 2013-10-24
3
Medium Priority
?
710 Views
Last Modified: 2014-02-15
Hi


I am having two folder like folder A and Folder B.we having some files in folder A with timestamp.i would like to sort the file in folder A by timestamp and move the file from Folder A to Folder B on basis of FIFO.

1.Sorting the files in a folder by timestamp
2.Picking (FIFO) and dropping it in another folder location on Unix/Linux System.

Thanks
0
Comment
Question by:nicemanish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Assisted Solution

by:w_richard
w_richard earned 750 total points
ID: 39597548
Using cp or cp -r will copy files from one place to another, but can / will still alter those files as far as the file system is concerned. A file is more than its contents after all. There is metadata for that file that is used by the files system, like creation time, access time, owner, permissions, etc. cp will not perserve this information.

You can also look at the cpio and rsync commands, depending on what exactly your needs are. - See more at: http://www.linux.com/learn/answers/view/514-move-all-files-from-a-directory-to-another-one#sthash.pgsdME6Q.dpuf
0
 
LVL 13

Accepted Solution

by:
Daniel Helgenberger earned 750 total points
ID: 39597902
I am a little bit puzzled about what you need in the end:
- A bash script?
- Something which runs once or continuously?
- What are the relevant timestamps, creation, modified, accessed time from file system, in the Inode? If not, where can I get the mysterious timestamp.i from?
- And why is the order important? The move will happen nearly instantaneous and preserve all file attributes, including all timestamps.

Anyway:
As for the bash script, the FIFO by filesystem modification time can be achieved with ls -tr:
for i in $(ls -rt1 FolderA/); do mv FolderA/$i FolderB/; done

Open in new window


For continuous move, have a look in incrond/inotify. This can move files like cron, for instance when created in FolderA. This is much like cron works but with file system events.
http://inotify.aiken.cz/?section=incron&page=about&lang=en

Also, a cron job with the script above works.
0
 

Author Closing Comment

by:nicemanish
ID: 39861472
good
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month12 days, left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question