I'm not sure if it's worth working around that. A directory containing files will get its timestamp from the files, but an empty directory will keep its original timestamp, and that timestamp will bubble up. This doesn't actually fully ignore timestamps of directories since they must be counted when the timestamps bubble up. depth tells find to handle subdirectories before their parents, so that the bubbling up actually works. (See BashFAQ 099.) Zsh does make it rather easy, though, the trick above is from Is it possible to reference the most recently modified file in a command line argument? $ find -printf "%TT %p\n" | sort -nįinding the newest file by timestamp is somewhat tricky in general, if there are filenames with whitespace/newlines or such. x/b was the newest, its timestamp is copied to. $ find -depth -type d -execdir zsh -c 'touch "$1" -r "$1"/*(om)' zsh \ If you can use Zsh, this seems to do what you wish: $ mkdir -p x/y touch x/y/a x/b sleep. I would like one line or short script that I can run from the command line to set directory timestamps based on the timestamps of their contents. The only portion that I'm struggling with is bubbling time stamps from the files up to parent directories. I also have a script that sets the permissions on all files and directories to a known state. I already have a script that sets the timestamps of files based on when they were committed to git. To ensure that rsync is consistent and idempotent from the various places, I need to ensure that the time stamps and permissions of everything are in a known state. The directory is checked into git and could get rsynced from any place that has the repository checked out. The reason that I'm doing this is for a directory that gets copied with rsync. Time stamps bubble up to multiple levels of parent directories.The current timestamps on the directories are completely ignored and the new time stamps are set only based on the contents.I'd like to change the timestamps on the three directories to be: root Here is a one liner to generate that: mkdir -p root/sub1 root/sub2 & touch -d '' root/sub2/file5 & touch -d '' root/sub2/ & touch -d '' root/sub1/file4 & touch -d '' root/sub1/file3 & touch -d '' root/sub1/ & touch -d '' root/file2 & touch -d '' root/file1 & touch -d '' root/ use error_chain::error_chain įor entry in glob_with("/media/img_*.How do I change the timestamp of a directory and all the sub-folders within that directory to reflect the modification times of the contained files?įor example with this directory structure: root use error_chain::error_chain įind all files with given pattern ignoring filename case.įind all image files in the /media/ directory matching the img_*.png pattern.Ī custom MatchOptions struct is passed to the glob_with function making the glob pattern case insensitive while keeping the other options Default. Matches all PNGs in media and it's subdirectories. For example, to search for a file named document.pdf in the /home/linuxize directory, you would use the following command: find /home/linuxize -type f -name document. In this case, the ** pattern matches the current directory and all subdirectories. To find a file by its name, use the -name option followed by the name of the file you are searching for. Recursively find all PNG files in the current directory. "Entries modified in the last 24 hours in bytes.", total_size) SystemTimeError(std::time::SystemTimeError) Duration::as_secs converts the time to seconds andĬompared with 24 hours (24 * 60 * 60 seconds). Metadata::modified returns the SystemTime::elapsed time since recurse > Whether to recursively manage the contents of. Then for each entries in fs::read_dir, extracts theĭirEntry::path and gets the metadata via fs::Metadata. If Puppet is managing any parent directories of a file, the file resource. Gets the current working directory by calling env::current_dir, Directory Traversal File names that have been modified in the last 24 hours
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |