Results 1 to 4 of 4

Thread: terminal commands to locate files

  1. #1
    Join Date
    Nov 2012
    Beans
    4

    terminal commands to locate files

    I'm really new to regex and I'm still trying to get the hand of complicated scripting. Goal is to locate every file with the words iTunes with it thats over 5 mb.

    I was originally thinking of doing something like:

    stat -c %s | locate iTunes | # this would get results over 5000000 bytes grep '[0-9][0-9]'

    Obviously I'm not doing this right but I would appreciate some help on this.
    Also any resources that are particularly good in understanding regex would be really appreciated.

    Thanks

  2. #2
    Join Date
    May 2009
    Location
    Courtenay, BC, Canada
    Beans
    1,661

    Re: terminal commands to locate files

    if your files are static then locate is ok
    Code:
    locate '[iI][tT]unes*' | while read f; i=$(stat -c %s "$f"); echo "$f: $i"; done | grep "5000000$"
    if they've changed recently then use find instead
    Code:
    find /path/to/folder -iname '[iI][tT]unes*' -exec 'i=$(stat -c %s {}); if [ "$i" -gt 5000000 ]; then echo {}; fi' \;
    you might want to check my work, I'm tired

  3. #3
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: terminal commands to locate files

    one can force database refresh for locate with sudo updatedb
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  4. #4
    Join Date
    Apr 2012
    Beans
    7,256

    Re: terminal commands to locate files

    You don't need to pass the find output to stat, you can test the size as part of your find command e.g. if it is files whose name contains iTunes that you want to find (not clear from your original post)

    Code:
    find . -name '*iTunes*' -type f -size +5000000c
    Note that -name only matches the file portion of the name - not the directory path. If that's not what you want then post back with more details of exactly what you are trying to achieve.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •