Solved

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

Posted on 2013-10-24
3
646 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
Comment Utility
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
Comment Utility
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
Comment Utility
good
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now