Solved

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

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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…
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é.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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