Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recursive list files with size and last modified time?

Tags:

linux

bash

Given a directory i'm looking for a bash one-liner to get a recursive list of all files with their size and modified time tab separated for easy parsing. Something like:

cows/betsy       145700    2011-03-02 08:27
horses/silver    109895    2011-06-04 17:43
like image 370
whatupdave Avatar asked Aug 06 '11 03:08

whatupdave


People also ask

How do I find most recently modified files in Linux?

Finding Files Modified on a Specific Date in Linux: You can use the ls command to list files including their modification date by adding the -lt flag as shown in the example below. The flag -l is used to format the output as a log. The flag -t is used to list last modified files, newer first.

How do I recursively list files?

Try any one of the following commands to see recursive directory listing: ls -R : Use the ls command to get recursive directory listing on Linux. find /dir/ -print : Run the find command to see recursive directory listing in Linux.

Where can I find recently modified files in Unix?

Use “-mtime n” command to return a list of files that were last modified “n” hours ago. See the format below for a better understanding. -mtime +10: This will find all files that were modified 10 days ago. -mtime -10: It will find all files that were modified in the last 10 days.


1 Answers

You can use stat(1) to get the information you want, if you don't want the full ls -l output, and you can use find(1) to get a recursive directory listing. Combining them into one line, you could do this:

# Find all regular files under the current directory and print out their
# filenames, sizes, and last modified times
find . -type f -exec stat -f '%N %z %Sm' '{}' +

If you want to make the output more parseable, you can use %m instead of %Sm to get the last modified time as a time_t instead of as a human-readable date.

like image 135
Adam Rosenfield Avatar answered Oct 05 '22 18:10

Adam Rosenfield