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`