How do I change folder timestamps recursively to the newest file?
You can use touch -r to use another file’s timestamp instead of the current time (or touch –reference=FILE) Here are two solutions. In each solution, the first command changes the modification time of the directory to that of the newest file immediately under it, and the second command looks at the whole directory tree recursively.
How to find the latest modified file in a directory?
For a huge tree, it might be hard for sort to keep everything in memory. %T@ gives you the modification time like a unix timestamp, sort -n sorts numerically, tail -1 takes the last line (highest timestamp), cut -f2 -d” ” cuts away the first field (the timestamp) from the output.
How to list files by modification date recursively?
How to list files sorted by modification date recursively (no stat command available!) Here is one version that works with filenames that may contain spaces, newlines, and glob characters as well: find -printf prints the file modification time ( Epoch value) followed by a space and \\0 terminated filenames.
Where does the timestamp go in a directory?
To clarify, if I touch a file or modify its contents a few subdirectory levels down, that timestamp should be displayed next to the first-level directory name. Say I have a directory structured like this:
How to find and list the latest modified files?
You can obviously get the latest access time using a “tail -1”. You can have find recursively print the name and access time of all files in your subdirectory and then sort based on access time and the tail the biggest entry: And there you have it…
How to recursively change the permissions of a file?
The chmod command with the -R options allows you to recursively change the file’s permissions. To recursively set permissions of files based on their type, use chmod in combination with the find command. If you have any questions or feedback, feel free to leave a comment.
How can I find the timestamp of a file?
If that’s what you mean, there’s two steps. stat -c ‘%Y’ filename will output the timestamp of filename, and stat -c ‘%Y %n’ * will output the timestamp and filename of every file in the folder, so this will find the filename of the most recently modified file in the current folder:
Why do I need quotes to update folder timestamps?
The quotes allow directory entries containing spaces and tabs to work correctly. The FD makes it find non-empty directories, including those starting with ., the od makes it search in the depth-first manner, so that the parent folder timestamps get updated properly.