Post by The Real BevPost by King Beowulffind [dir-to-search] -type f -mtime -1 -maxdepth 2 -exec dirname {} \; |
sort --unique
('maxdepth 2' limits to current dir and not subdirs).
That seems kind of cumbersome for casual use.
Which is why you'd wrap it into an aliais or shell script file for
casual use.
Post by The Real BevWhat I should do is just make a couple of aliases -- t for 'touch
crap' and d for 'rm -f crap' -- and use them as needed whenever I
edit anything in a subdirectory.
You don't need to create and delete a file to update the current dir's
timestamp. "touch ." (the . entry represents the current directory you
are in) will update the timestamp of the current directory.
Post by The Real BevI usually use a small number of directories, so it shouldn't be too
painful. Crude, of course, but better than nothing.
You can also use find, along with a small helper script, to scan your
hierarchy of directories and automatically touch each one with the
newest date of a containing file to create the situation you want.
Then you either run it manually to update the directory timestamps, or
you setup a cron job to launch it periodically to update all the
directory timestamps.
I.e., you'd put this into a file named "touch-dir" (note this is Bash
and GNU xargs specific):
---cut---cut---cut---cut---
#!/bin/bash
for dir in "$@" ; do
DDATE=$(find "$dir" -type f -maxdepth 1 -print0 \
| xargs -0 --no-run-if-empty stat --format=%y \
| sort -r \
| uniq \
| head -1)
if [[ ${#DDATE} -gt 0 ]] ; then
touch --date="$DDATE" "$dir"
fi
done
---cut---cut---cut---cut---
Next you would make "touch-dir" executable and put it into your ~/bin
which is on your PATH search list (what, you don't have a ~/bin
directory that is on your PATH, well, then make one and configure it to
be on your PATH).
Next you'd create another script file, named say
"update-dir-timestamps" and put this into it:
---cut---cut---cut---cut---
#!/bin/bash
find ~ -type d -xdev -print0 | xargs -0 touch-dir
---cut---cut---cut---cut---
You'd then make that executable and also put it into your ~/bin
directory.
You'd also replace ~ with the top of the directory heirarchy you want
to update (or leave ~ if you want to do your whole home directory).
Then anytime you want all the dir timestamps to match the oldest file
inside, run "update-dir-timestamps" and all of them will be updated to
match the oldest file inside.
If you want it to run automatically, then add it to your local crontab
to run on a periodioc basis.