![]() |
|
#1
|
|||
|
|||
Getting all updated files today on linux/unix systemI am trying to write a C program to get all files on the system that were updated today. The idea has been to use
ls -liAR from / to get a whole list of files and then parse that information and have to get the path, and append any file with date matching the value of date | cut -b 5-10 Does anyone else have an idea of an easier way to do this? |
|
#2
|
|||
|
|||
Re: getting all updated files today on linux/unix systemQuote:
Are you writing a C program or a shell script? Or can you use a common utility like find? It beats the heck of cobbling up some C program full of opendir(), readdir(), stat(), etc. (This is, of course only my opinion, but I am unanimous in that. See footnote.) For just about any shell and any vintage of UNIX/Linux, try man find So, for example: If you are in some directory and you want to find all files in that directory and its subdirectories that have been modified (or created) since midnight system time: Code:
(Note that the "-print" isn't necessary with any recent versions of find that you are likely to "find" on Linux systems, but I usually put it there for old times' sake.) Of course, instead of "." you could use any path you want to. If you want to get a list of files that were modified or created within the last 24 hours, then Code:
Of course if you want to see the directory listing that actually shows the timestamps you could do something like Code:
Then feed that output (pipe it) to cut or awk or perl (or ...whatever...) if you need to process it some more. Various options for find take care of following (or not following) symbolic links, limiting depth of search of directory trees, etc. Regards, Dave Footnote: "The opinions expressed here are not necessarily my own. It's these dang voices in my head." ---davekw7x Last edited by davekw7x : 12-Dec-2006 at 15:40.
|
|
#3
|
|||
|
|||
Re: getting all updated files today on linux/unix systemDave,
Thank you for your reply. This idea of using the find command is a very good idea.. unfortunately the -daystart option is not available to me since this is an AIX system.. but it isn't imperative to this problem.. I am sure I can figure something out with the ideas you have presented. I really am just trying to back up files that have been modified/created since the last run of this program/script. I know I was making this more difficult than need be, I usually do. |
|
#4
|
|||
|
|||
Re: getting all updated files today on linux/unix systemQuote:
Then, however you get the list of files, make sure that your list excludes directories, since a directory will have a new timestamp if any one or more of its files have been changed. (I am assuming that you want to archive only the specific files that have changed, not the entire directory.) Also, if you are starting from the root of the file system (that is '/'), make sure you exclude /dev and /proc, since the contents of those "file systems" aren't really files and you really (really) don't want to back them up. If you are going to use tar to do the backups, note that it has an option that will only select files newer than a file that you can specify. So: create a brand new file. Call it "backup_date", for example. (So its timestamp will be "now".) It can be empty, or you can actually write the date into it. Backup everything that you want. Then, the next time you want to back things up, you rename the "backup_date" file to "last_backup". Create a brand new file named "backup_date". Use tar to archive all files that are newer than "last_backup" Experiment with the process, and after you get things the way that you like, you can create a simple shell script to do the deed. You may want create a cron job to do it automatically at a time that you aren't normally operating each day. Regards, Dave |
|
#5
|
|||
|
|||
Re: getting all updated files today on linux/unix systemHi again Dave.
I've put the program together and it works rather well.... except for what you said about excluding directories and /proc/ and /dev/ I've been searching the man page on find and I haven't been able to discern how to exclude these. Can you help? I am backing up every file on the system to a remote mirror system via scp. Everything is working well except that one thing: find / -mtime 1 finds me the modified files within the last 24 hours on this AIX system, but includes the directories we don't want. What do I need to add to rectify this? Thanks very much again for your time. |
|
#6
|
|||
|
|||
Re: getting all updated files today on linux/unix systemQuote:
The approach depends on what you are going to do with the list. (As I mentioned, I might use tar rather than find.) However, if you are going to use find, and you like everything about it except that you want to exclude the directory trees beginning with "./proc" and "./dev", then use your favorite filter. (Awk, sed, perl, ...) For me, sed comes to mind, and you can experiment with this (see footnote) Code:
You pipe it to sed. There are two sed expressions. Every time sed finds a line that starts with ./proc it deletes the line. Every time sed finds a line that starts with ./dev it deletes that line. Send this output to whatever program (pipe it) or file (by redirection) that you want to see the remaining stuff. If the sed stuff becomes more complicated and you want to put expressions in a file instead of the '-e " "' stuff on the command line, you can do that also. For testing, make a small tree somewhere below your home directory. Call it testtree, for example. Create a couple of directories named ~/testtree/dev and ~/testtree/proc and copy something there. Create some other directories too. Copy some old files into various places in your test tree (use "cp -p" to preserve the old time stamps) Copy some without the "-p" to create new timestamps (or "touch" them to update the timestamp). Test it there first (use find ~/testtree -mdate 1 ...whatever...) before going to the big / root directory. Regards, Dave Footnote: "They put 1000 chimpanzees in a room with 1000 computer keyboards and arranged for rewards to be given when they typed anything. After only a few minutes, the result was that every single one of them came up with numerous Linux command lines." ---davekw7x Last edited by davekw7x : 13-Dec-2006 at 14:03.
|
|
#7
|
|||
|
|||
Re: getting all updated files today on linux/unix systemQuote:
The previous post showed a little sed thingie that can filter the output of "find" to inhibit listing all files in the directory tree that start with either "./proc" or "./dev" Since you are making a list of things to back up, I'm guessing that you don't want to backup an entire directory; only the hew files that are in that directory. For this, you can use a bash script (assuming you have bash --- otherwise use sh or ksh or whatever to do the equivalent). Just for test purposes here's a little bash script that prints out all files from the "find" list that are directories: Code:
Of course you want the things that are not directories, so you could use Code:
Then instead of the "echo $i is not a directory" line, you can "echo $i" and pipe the result to sed or whatever filter you need to use in order to get the final list. Or you could put it all in the script: Code:
The important point is that you can test each piece separately (in a small directory tree) before committing to the whole / root enchilada. Regards, Dave Note to moderator (I know you are there; I can hear you breathing): The Original Post had the phrase "C program" and it was posted on the C Programming Forum, but absolutely nothing in the entire thread has anything to do with C. Therefore, maybe the thread should be moved to the Linux forum (and you might as well delete this footnote if you do move it.) Dave |
|
#8
|
|||
|
|||
Re: getting all updated files today on linux/unix systemQuote:
After all of the fun with find, sed, and bash, I kind of hate to point out the "easy" way. If it is available on your systems, check out rsync. All of the good stuff has already been done (and worlds than I could cobble together in a couple of sessions here, but not as much fun --- at least it has been fun for me). Regards, Dave |
|
#9
|
|||
|
|||
Re: getting all updated files today on linux/unix systemNo rsync on the system.
The reason I originally spoke of C program is because that is how the idea was presented to me originally by someone else. That script is very nice for printing to stdout but it doesn't let me redirect to a file correctly, which is what I really could use. It only prints one line when redirected. Am I missing something obvious? You spoke of fun.. I think learning is always fun, and you are a very patient and kind person for giong through this with me. I am glad you are enjoying it. Thanks again. |
|
#10
|
|||
|
|||
Re: getting all updated files today on linux/unix systemNever mind.. I am stupid.. I realised that I was overwriting the redirected output each time the loop ran.
I believe i have solved the issue now I will deal with the end of it tomorrow because they're closing up shop here for the night! Thanks Dave and I will let you know how it turns out |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Download files in c for windows operating system | oozsakarya | C Programming Language | 5 | 20-Jun-2006 03:33 |
| C++ for moving files across network? | dlp | C++ Forum | 1 | 25-May-2006 12:22 |
| Bloodshed Dev C++ Project Options | JdS | C++ Forum | 6 | 11-Nov-2005 17:23 |
| corrupt HD / File system | Hood | Computer Software Forum - Windows | 11 | 20-Jun-2005 20:33 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The