Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-07-2009, 12:03 AM   #1
Senior Member
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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

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
Old 07-07-2009, 12:11 AM   #2
Senior Member
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,462
Blog Entries: 6

Rep: Reputation: 51
use this:
basename find /var/log -mtime +2 -exec ls -lt {} \;
Old 07-07-2009, 12:13 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
To format the output of find in various ways, look at using -printf.
find /var/log -mtime +2 -printf '%f\n'
Old 07-07-2009, 12:15 AM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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/^.*\///'


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to do search & replace on a text file--need to extract URLs from a sitemap file Mountain Linux - General 4 08-07-2015 11:52 AM
How to search "file:///" in internet search engines? tirengarfio General 4 05-23-2009 08:56 PM
How to read string in 1 file and search in another file? ameyapandit Programming 7 07-11-2008 01:05 PM
Find File broken, need search utility, where does WineX install, KDE file roller? Ohmn Mandriva 6 07-05-2004 11:34 PM
How to 'apt-cache search' & 'apt-file search' by distribution? davidas Debian 3 04-19-2004 02:56 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:14 AM.

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