Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need help with bash, for each directory in ...
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Need help with bash, for each directory in ...

xrzxrz Member
edited September 2016 in Help

How can i only "for each dir" which has date of modify or date of creation dir TODAY?

!/bin/bash

for dir in /home/blubbluh/*
do
if [ -d "${dir}" ]; then
somecommandblahbleh
done

THX!

Comments

  • FalzoFalzo Member
    edited September 2016

    man find

    PS: are you even aware under what circumstances a directory mtime or ctime is updated and when not?

    Thanked by 1xrz
  • xrzxrz Member
    edited September 2016

    tried (http://stackoverflow.com/a/552750) -120 minutes aka 2 hours but not works .. still getting all dirs

    !/bin/bash

    for dir in /home/blubbluh/*
    do
    if [ -d "${dir}" ]; then
    if test find "${dir}" -mmin -120
    then
    somecommandblahbleh
    fi
    fi
    done

  • FalzoFalzo Member
    edited September 2016

    sorry to say, but you need to learn/read/try more by yourself ;-) so I wont deliver complete solutions anymore ^^

    as a hint: you can achieve what you want to do with a single find command (and get rid of that whole for do crap).

    some more hints:

    find -type d

    this simply will find all directories beneath the given path

    find -cmin -120

    this will give back only files/dirs with a change time within the last 120 minutes. read about differences between mmin and cmin (or mtime/ctime)... especially when this will happen to be updated on a dir. also mind the difference of using + or - modifier for the time given.

    find -exec somecommand {} \;

    this will execute a specified command on every single result of the search

    after that combine this three stepwise into one single command. maybe use a non modifying command first as a dryrun method. append something like -print to get more output ;-)

    Thanked by 2yomero rincewind
  • Should have deferred to @Falzo but couldnt help it

    find /home/blahblah -type d -and \( -daystart -ctime 0 -or -mtime 0 \) -exec blehblehbleh \;
    
    Thanked by 1Falzo
Sign In or Register to comment.