Howdy, Stranger!

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


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
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 Barred
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 Barred
    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.