LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2003, 07:15 AM   #1
StarTux
Newbie
 
Registered: Feb 2003
Location: Maastricht, The Netherlands.
Distribution: SuSE & Red Hat & Slackware
Posts: 8

Rep: Reputation: 0
Comparing files on creation time


Hi,

I seem to have a small problem, which I can't seem to solve in an easy way. What I would like to do is this:

In my script I want to know if a certain file is on the computer. I can find the file by: variable=`find ~ -name MyFile -follow >> MyFileLocation.text`

Here I start looking in the home directory of the user executing the script, and I make sure no symlinks are listed, and I would like to put the path+filename in a variable.

The problem is, if there are more than 1 files of the name MyFile, they will all be listed. I would like to have only the most recent file. I don't know how many times this file is located on the computer (I would like to use this script a bit flexible)


Any help is supurbly appriciated.
 
Old 08-29-2003, 09:25 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
I can find the file by: variable=`find ~ -name MyFile -follow >> MyFileLocation.text`
If redirect the output of the find command to a file (>>MyFileLocation.text), then the output is not going to be in the varaible anymore. I'd recommend not to redirect the output to a file. Just store it in the variable. If you really want the path in the file, you can do:
Code:
echo $variabele >>MyFileLocation.text`
or, another way to have the path in both the variable and the file:
Code:
variable=`find ~ -name MyFile -follow | tee -a MyFileLocation.text`
Quote:
The problem is, if there are more than 1 files of the name MyFile, they will all be listed. I would like to have only the most recent file.
This will put the path to the most recent modified file in $variable :
Code:
variable=`find $HOME -name MyFile -follow | xargs ls -t | head -1`
 
Old 08-29-2003, 01:08 PM   #3
StarTux
Newbie
 
Registered: Feb 2003
Location: Maastricht, The Netherlands.
Distribution: SuSE & Red Hat & Slackware
Posts: 8

Original Poster
Rep: Reputation: 0
THANKS!

Thanks Hko,

I will try this out. I didn't look at xargs well enough. Also thanks for the tip on the variable, I wasn't precises enough in explaining the problem. What I do in the script, is to declare a number of variables, which I use throughout the script. I also write them in a log file, for un-install information.

again, thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing 2 Files for Duplicates Mr_H Linux - Newbie 5 11-09-2005 12:43 PM
comparing lots of files Frustin Linux - General 4 09-22-2005 02:54 PM
Using diff for comparing 2 files beep Programming 5 01-21-2005 12:51 PM
Comparing files contents? hhegab Linux - Newbie 3 07-01-2004 12:45 AM
Comparing 2 Files xianzai Programming 2 05-23-2004 11:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration