Operating System - HP-UX
1752595 Members
4576 Online
108788 Solutions
New Discussion юеВ

how to find the five newest modified files in /etc?

 
SOLVED
Go to solution
thebeatlesguru
Regular Advisor

how to find the five newest modified files in /etc?

can i use ls to do it?
hihi
6 REPLIES 6
Michael Tully
Honored Contributor
Solution

Re: how to find the five newest modified files in /etc?

Hi,

How about the first ten:

# cd /etc
# find . -type f -print | xargs ls -lt | head
Anyone for a Mutiny ?
thebeatlesguru
Regular Advisor

Re: how to find the five newest modified files in /etc?

can u explain it ?thank u
hihi
S.K. Chan
Honored Contributor

Re: how to find the five newest modified files in /etc?

# find . -type f -print | xargs ls -lt | head

means ..
- find only files from the current directory and print the path, pass it on to 'ls -lt' command which will display these files sorted by the "newest modified" and pipe it to 'head' command to only display 10 lines (ie 10 files).
By default 'head' will display 10 lines.
Michael Tully
Honored Contributor

Re: how to find the five newest modified files in /etc?

Hi,

. = from this directory tree and below
type f = normal file only
xargs = is a buffering program that relies on
the input from the output before the pipe (|)
ls -lt = display newest files
head = displays 10 lines by default.

For more info have a look at the man pages for
find
xargs
ls
head
Anyone for a Mutiny ?
Deepak Extross
Honored Contributor

Re: how to find the five newest modified files in /etc?

And if you want FIVE newest files, replace "head" with "head -5".
Darrell Allen
Honored Contributor

Re: how to find the five newest modified files in /etc?

If you only want to check the /etc directory (and not it's sub-directories) use:

ll -rt /etc | tail -5

-rt says to reverse the order of sort based on timestamp

You could also do ll -t /etc | head -6

-6 because the first line is the number of directory entries

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)