Search code examples
unixls

UNIX - List files with a given suffix in order of last modification


I know I can use:

for file in *.csv; do echo $file; done

to list all the files the current directory with the supplied suffix.

I also know I can use:

ls -rt

to list all the files in order of when they were modified with the most-recently-modified at the bottom of the list.

I want to combine these two commands to get a list of only files with a particular suffix but sorted by when they were last modified.

Update: I found this question that looks like it offers a solution but I'm not sure what parts of the solution are applicable to my needs


Solution

  • xargs would convert the rows as command line arguments!

    for file in *.csv; do echo $file; done | xargs ls -rt
    

    Also, I would just do ls -lrt *.csv