LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compare 2 files name (https://www.linuxquestions.org/questions/linux-newbie-8/compare-2-files-name-793835/)

specialized 03-07-2010 03:49 PM

compare 2 files name
 
i want to compare 2 name files, for instance.....

i got the package foo1.tgz and the foo2.tgz. and i want a script in bash that detects foo2 is newer than foo1 and delete foo1

can be done?? for manage a collection of slackware packages and bla bla

acid_kewpie 03-07-2010 04:18 PM

sure it's possible by using find and such, but you've not given enough description about what you really want to achieve, how is said script meant to know which files to compare etc.?

cloudmilk 03-07-2010 04:20 PM

Try :

find $folder -type f -name foo*.tgz -not -newer foo2.tgz -exec ls -l {}\;

Once the result fits your needs, replace
ls -l {} \;
by
rm -f {} \;

That works with 1 file you've just added, but parsing a whole directory and determine the root name of each file to delete older ones is another story, the naming convention must be strict.
Let us know.


All times are GMT -5. The time now is 12:23 PM.