LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   search file (https://www.linuxquestions.org/questions/linux-newbie-8/search-file-738205/)

ust 07-06-2009 11:03 PM

search file
 
I use the below command to find the file elder than 2 days , it works .

find /var/log -mtime +2 -exec ls -lt {} \;


current result
==============
/var/log/file1
/var/log/file2


But I found that the result is full path , can advise if I want the result is file name only as below , what can i do ?

my desired result
=================
file1
file2

your_shadow03 07-06-2009 11:11 PM

use this:
basename find /var/log -mtime +2 -exec ls -lt {} \;

jschiwal 07-06-2009 11:13 PM

To format the output of find in various ways, look at using -printf.
find /var/log -mtime +2 -printf '%f\n'

pixellany 07-06-2009 11:15 PM

Pipe the result into SED....

eg :

sed 's%^.*/%%'

Replaces any number of characters from the beginning of the line, up to and including the last instance of "/", with an empty character. "%" is used as the delimiter to allow "/" to be in the Regex.

This will do the same thing:
sed 's/^.*\///'


All times are GMT -5. The time now is 06:08 PM.