finding the 5 newest files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding the 5 newest files in a directory
# 1  
Old 08-02-2010
finding the 5 newest files in a directory

I have a folder that has new files created everyday, is there a way i can filter them so that only the 5 newest files are displayed? I'm hoping this can be done by a one liner without a script.

for example my directory contains
Code:
-rw-r--r-- 1 root root 0 Jun 24 08:34 file112
-rw-r--r-- 1 root root 0 Jun 28 08:34 file12
-rw-r--r-- 1 root root 0 Jul 25 08:34 file1
-rw-r--r-- 1 root root 0 Jul 26 08:34 file2
-rw-r--r-- 1 root root 0 Jul 27 08:34 file3
-rw-r--r-- 1 root root 0 Jul 28 08:34 file4
-rw-r--r-- 1 root root 0 Aug  2 20:59 file200

I want to be able to be able to just list the 5 newest files.

As a alternative I guess I can filter them by time, is there a way to just show the file name without the ./ in front?
Code:
find -type f -mtime -6
./file4
./file200

Thanks.
# 2  
Old 08-02-2010
Hi

Code:
ls -1t | head -5

Guru.
# 3  
Old 08-03-2010
THANKS!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Finding files older than x days within directory with spaces

Hi, I am trying to run a command that finds all files over x amount of days, issue is one of the directories has spaces within it. find /files/target directory/*/* -type f -mtime +60 When running the above the usual error message is thrown back + find '/files/target\' 'directory/*/*' -type... (1 Reply)
Discussion started by: Ads89
1 Replies

2. Shell Programming and Scripting

Finding files in directory with similar names

So, I have a directory tree that has many files named thusly: X_REVY.PDF I need to find any files that have the same X portion (which can be nearly anything) as any another file (in any directory) but have different Y portions (which can be any number from 1-99). I then need it to return... (3 Replies)
Discussion started by: Kamezero
3 Replies

3. Shell Programming and Scripting

Writing Script to Copy Newest Directory

I am trying to write a script that once executed it will search within a directory and copy only the newest directory that has not been copied before to a new location. Kind of like what ROBOCOPY /M does in windows? The directories are not left in the new location so using a sync action won't... (2 Replies)
Discussion started by: Keriderf
2 Replies

4. Shell Programming and Scripting

Finding the executable files of a directory using Grep

Hi guys, Can you please help me print all the executable files of a directory(in this case /home) using grep? All i know is that this command should do it but it doesnt... ls -l ~ | grep -..x it shows me the following mesage grep: invalid option -- '.' Χρήση: grep ... ΥΠΟΔΕΙΓΜΑ ... (3 Replies)
Discussion started by: jimas13
3 Replies

5. Shell Programming and Scripting

Get the newest file in a directory.

I am new to shell scripting so i need some help need how to go about with this problem. I have a directory which contains files in the following format. The files are in a diretory called /incoming/external/data AA_20100806.dat AA_20100807.dat AA_20100808.dat ... (4 Replies)
Discussion started by: ziggy25
4 Replies

6. Shell Programming and Scripting

Finding files in directory

Hi, I need help in writing shell script to accomplish the following. 1.I've one text file which contains list of batch numbers like b1.dat,b2.dat,b3.dat... 2.I've the same files along with other files present in some directory.i.e 1.dat,2.dat,3.dat,4.dat,5.dat... present in some directory.... (3 Replies)
Discussion started by: narranil2
3 Replies

7. Shell Programming and Scripting

Finding all the files in a directory

I need to find all the files with a given file name present in the sub directories and execute a script on each file For example In the directory source , I need to find all the files named test and execute the script run.sh Can anyone please help me on this (4 Replies)
Discussion started by: prav076
4 Replies

8. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

9. Shell Programming and Scripting

finding 0 byte files in current directory only

Hi Gurus, I have a directory A, which has some 0 byte files in it. This directory also has a subdirectory B which also has some 0 byte files in it. The problem: I only need to find out the names of the 0 byte files in the directory A. I'm using the following command find . -name *.zip... (6 Replies)
Discussion started by: ramky79
6 Replies

10. Shell Programming and Scripting

Script to cd into newest (dated) FTP directory

I have written the following simple bash script. It logs onto an FTP site and then CDs into a directory that corresponds to the last business day. So for example the directory I would access today is 20060110 (2006 jan 10). I am currently taking today's date and subtracting 1, putting this... (3 Replies)
Discussion started by: steved
3 Replies
Login or Register to Ask a Question