how to display the last 10 modified files of a folder?
Hi All,
I need to know the last 10 modified files in a folder. Can any one help me regarding this? Thanks in advance for your help... |
There is a lot of ways of doing this. Is the output supposed to be processed by a script of some sort? If not, you could simply do something like this:
Code:
ls -l --sort=time | head -n 11 Code:
ls -l --sort=time | head -n 11 | tail There is probably more elegant ways to do this. This is something I cooked up in a few seconds without much thinking :P |
I'd do this as a noob too, so for sure it does exist a better solution :
Code:
find /tmp -type f -mtime 10 | ls -ltsha | tail -n 10 /tmp : search in /tmp directory -type f : search for files (and not for directories) -mtime 10: limit to files that have been modified in the last 10 days ls: show this list result tail -n 10: keep only the 10 last ones more details about find command: Quote:
|
Code:
ls -ltr | tail -10 |
Hi,
The command posted by ghostdog74 works, but it might have an unwanted side effect: It will also show possible directories. The OP doesn't mention this, but if only files are wanted and directories need to be left out: find . -maxdepth 1 -type f | xargs ls -ltr | tail -10 Hope this helps. |
To filter out directories, use the -p option to add a trailing slash to them, then grep it out. And instead of -l (ell) use -1 (one) to get a list of the filenames only. Grep can also output a specified number of lines with -m, so you can avoid running it through head or tail.
Code:
ls -1tp | grep -v -m 10 "/$" |
I think ghostdogs solution was slick.
druuna: Everything is a file :P I usually like ls better, so I took the freedom to modify ghostdogs version to remove directories: Code:
ls -ltr | grep -v ^d | tail -10 |
@David the H.: Nice, but....
- It will show links (don't know if the OP wants that). - It will not show dot files (again, don't know if OP wants these). I guess the OP has enough possibilities by now to suit his demands :) |
Quote:
Code:
`-F' |
All times are GMT -5. The time now is 01:44 AM. |