0

In a Unix Shell you can use the following to print a list of all files and subfolders recursively:

cd some/path/to/folder
du -a

and you can list file information (such as permissions and timestamps) with the following:

stat filename.ext

Is there a way you can combine the commands to list all the files and subfolders of a directory recursively (with relative path) followed by the modified time? For example:

a_file.txt: 06/27/19 - 08:34:16
a_subfolder: 07/30/18 - 18:23:14

Bonus: Something that will work for both Linux and OSX, and output to a txt file

  • 1
    Does your find support -printf? – Kamil Maciorowski Oct 6 at 12:29
  • @KamilMaciorowski I believe it works, would prefer commands that work in a generic Unix Shell (so that it works for both OS X and Linux) – Mick Oct 6 at 12:44
2

You can provide a format to stat: stat -c '%n: %y' somefile will print the name and last modification time of somefile (%n actually replicates the parameter passed as a filename).

find [...search parameters...] -exec somecommand {} \; iterates alld files and directories and executes somecommand on every file/directory that matches, passing the file/directory name as a parameter.

Putting it all together:

find . -exec stat -c "%n: %y" {} \;

... will iterate all the files and directories under the current directory, and print their name and last modification date.

  • Brilliant, that did the trick! – Mick Oct 6 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.