LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   forward to another directory (https://www.linuxquestions.org/questions/linux-general-1/forward-to-another-directory-592770/)

send2rawat 10-18-2007 10:14 AM

forward to another directory
 
I have some text files in a directory.
I want to read those files one by one.
I just want that if i had read that file once then it should be transfed to another folder.

bigrigdriver 10-18-2007 12:56 PM

You could probably do it with a shell script.

In *nix, you can't tell directly the creation time of a file. But, there are three times you can determine:
1) ctime (change time) - the time when changes were made to the file's inode (ownership, permissions, etc). When the file is first created, ctime is set. If inode properties are changed after creation, ctime changes. For new files, consider ctime equal to creation time. The output of 'ls -lc' shows ctime.

2) atime (access time) - the time the file was last accessed. 'ls -lu' shows atime.

3) mtime (modification time) - the time the file was last modified. 'ls -l' shows mtime.

So, for new files in the folder, your script could compare the output of 'ls -lc' to 'ls -lu', and if atime is greater than ctime (i.e. later than ctime) then you have accessed the file; move it to another folder.

In Linux, you also have the 'stat' command, which shows all three times. So, instead of comparing 'ls -lc' to 'ls -lu', your script could use the output of stat, and if atime is greater than ctime, move the file. You would probably want to use awk to compare the date/time fileds of ctime and atime.

matthewg42 10-18-2007 01:01 PM

What is reading the files?


All times are GMT -5. The time now is 12:11 AM.