- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- find command: How to find the oldest file in a fol...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 05:28 AM
тАО03-18-2010 05:28 AM
How to find the oldest file in a folder only with a method based on the find command ?
bests regards
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 06:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 06:52 AM
тАО03-18-2010 06:52 AM
Re: find command: How to find the oldest file in a folder
ls -lrt | head -2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 07:03 AM
тАО03-18-2010 07:03 AM
Re: find command: How to find the oldest file in a folder
Try it with "-1rt" instead of "-lrt".
one ell
Unless you really want more than the name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 07:05 AM
тАО03-18-2010 07:05 AM
Re: find command: How to find the oldest file in a folder
since my previous ls -lrt | head -2 list the file or directory that is the oldest or the 2 oldest if you modify head to -3 or -4 and so on
to list the oldest file only
#ls -lrt | grep -v ^d | head -2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 07:21 AM
тАО03-18-2010 07:21 AM
Re: find command: How to find the oldest file in a folder
As usual, what we really need most is a
complete description of the problem to be
solved.
> [...] | head -2
Still shows "total xxxx" along with the
desired information. "| tail -1" could solve
that, but then why use "head" at all?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 08:40 AM
тАО03-18-2010 08:40 AM
Re: find command: How to find the oldest file in a folder
#ls -gt | grep -v ^d | tail -1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 10:04 AM
тАО03-18-2010 10:04 AM
Re: find command: How to find the oldest file in a folder
your method for that work if the file name
contains space characters?)
Everything's complicated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2010 01:15 PM
тАО03-18-2010 01:15 PM
Re: find command: How to find the oldest file in a folder
Since this is the Linux forum, I'm going to assume that you are using the GNU 'find'. Hence, "only with a method based on the find command" you could do:
# find /path -type f -printf "%T@ %h/%f\n"|sort -k1n,1|awk 'NR==1 {print $NF}'
The name of the oldest file in '/path' will be returned with its full path and name.
Of course, I took the liberty of using 'sort' and 'awk' in a pipeline too :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2010 09:25 AM
тАО03-26-2010 09:25 AM
Re: find command: How to find the oldest file in a folder
Thanks guys