Solved

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

Posted on 2013-10-24
3
657 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
3 Comments
 
LVL 3

Assisted Solution

by:w_richard
w_richard earned 250 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 250 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

810 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