公告
财富商城
积分规则
提问
发文
2019-01-05 09:05发布
神经病院院长
Looking for a command that will return the single most recent file in a directory.
Not seeing a limit parameter to ls...
ls -t | head -n1
This command actually gives the latest modified file in the current working directory.
try this simple command
ls -ltq <path> | head -n 1
If you want file name - last modified, path = /ab/cd/*.log
If you want directory name - last modified, path = /ab/cd/*/
I needed to do it too, and I found these commands. these work for me:
If you want last file by its date of creation in folder(access time) :
ls -Aru | tail -n 1
And if you want last file that has changes in its content (modify time) :
ls -Art | tail -n 1
ls -t -1 | sed '1q'
Will show the last modified item in the folder. Pair with grep to find latest entries with keywords
grep
ls -t -1 | grep foo | sed '1q'
using R recursive option .. you may consider this as enhancement for good answers here
ls -arRtlh | tail -50
This is a recursive version (i.e. it finds the most recently updated file in a certain directory or any of its subdirectory)
find $DIR -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1
Edit: use -f 2- instead of -f 2 as suggested by Kevin
-f 2-
-f 2
最多设置5个标签!
This command actually gives the latest modified file in the current working directory.
try this simple command
If you want file name - last modified, path = /ab/cd/*.log
If you want directory name - last modified, path = /ab/cd/*/
I needed to do it too, and I found these commands. these work for me:
If you want last file by its date of creation in folder(access time) :
And if you want last file that has changes in its content (modify time) :
Will show the last modified item in the folder. Pair with
grep
to find latest entries with keywordsusing R recursive option .. you may consider this as enhancement for good answers here
This is a recursive version (i.e. it finds the most recently updated file in a certain directory or any of its subdirectory)
Edit: use
-f 2-
instead of-f 2
as suggested by Kevin