Solved

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

Posted on 2013-10-24
3
663 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

840 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