Find the answer to your Linux question:
Results 1 to 2 of 2
As a "newbie" in this scripting world I would like to ask some advices what kind of shell script would perform fastest search files from the system that have some ...
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    2

    Question Shell script for searching and listing.

    As a "newbie" in this scripting world I would like to ask some advices what kind of shell script would perform fastest search files from the system that have some specific extension, such *.jpg or something similar.

    How could I give extension as a parameter and then script would take this given extension as parameter and would after that walk through the system and write these listed/ finded files directly to the file like $hostname.$extension.log.

    I was wondering something like this.

    #!/bin/bash

    EXTENSION=$1
    HOSTNAME=$HOST
    HOMEFOLDER=/home/

    echo "Give extension:" + read $1

    if [ $1 eq 0 ]
    then
    echo "extension missing"
    else if [$1 eq 1]
    then
    echo "Starting to find files that have $1 extension"

    find / -name $1 > $HOMEFOLDER/$1.log

    fi

    So Would this do this task and find all given extensions from the system?

    Any suggestions?

    Thanks.

  2. #2
    Linux Guru
    Join Date
    Jan 2009
    Location
    Dover, NH
    Posts
    1,633
    I'm not a script expert, so though I'm a little puzzled at the variable declarations, I'll leave that alone at this time (maybe someone else can answer that one).

    Find looks okay from a compatibility perspective, but if you want it to a) not spit permission errors at you (when run as a user) and b) run much faster, then I suggest instead of using find, you use locate. You'll need to install one of the packages that includes locate as a program. Locate keeps a cache that's updated once a day, so the results are not necessarily accurate if you've made changes since the last update, though you can update the database manually if you need.

Posting Permissions

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