get specific file from sorted files
meybe this is too simple but im new on unix.
i have a directory like /h开发者_如何学运维ome and in this directory i have 5 files like ;
/home/file1.csv
/home/file2.csv
/home/file3.csv
/home/file4.csv
/home/file5.csv
i want to display a file like , they must be ordered by date and i can display for example 3.file from that order ..
I'm not very sure if you want it to be ordered newest first or oldest first.
ls -t | head -3
will print the newest 3 files, and
ls -rt | head -3
will print the oldest 3 files.
And if you want to sort the result in access time (the commands above sort them in modification time), please use the following commands respectively.
ls -u | head -3
ls -ru | head -3
The above mentioned method by aifreedom is better than what I had earlier (shifted to the bottom)
@denso, to ignore the directories, you can do this.
ls -p | grep -v \/ | head -3
ls -p lists everything in the current directory with the directories followed by a "/" grep -v \*symbol* takes a stream and filters out the inputs containing symbol (here, the words containing /) head -3 will provide the first 3 from the list.
_old_
I don't know if there is an easier way to do this, but this works
ls -t | xargs | awk '{ print $3 }'
精彩评论