- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- System Administration
- >
- find command: How to find the oldest file in a fol...
-
- Forums
-
Blogs
- Alliances
- Around the Storage Block
- Behind the scenes @ Labs
- HPE Careers
- HPE Storage Tech Insiders
- Infrastructure Insights
- Inspiring Progress
- Internet of Things (IoT)
- My Learning Certification
- OEM Solutions
- Servers: The Right Compute
- Shifting to Software-Defined
- Telecom IQ
- Transforming IT
- Infrastructure Solutions German
- L’Avenir de l’IT
- IT e Trasformazione Digitale
- Enterprise Topics
- ИТ для нового стиля бизнеса
- Blogs
-
Quick Links
- Community
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Contact
- Email us
- Tell us what you think
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Enterprise.nxt
- Marketplace
- Aruba Airheads Community
-
Forums
-
Blogs
-
InformationEnglish
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-18-2010 06:49 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2019 Hewlett Packard Enterprise Development LP