Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

'find' not seeing matching files

  • 05-07-2007 04:11PM
    #1
    Registered Users, Registered Users 2 Posts: 427 ✭✭


    I have a script that contains a section to look at a specific folder and find all files with the extension xml.tmpl and do some processing to each file. This used to work without a problem but for the last few weeks has been acting strange-sometimes it finds all of them, sometimes only a few and sometimes none.

    The .xml.tmpl files in the folders are currently a mix of -rwxrwxr-x and -rw-rw-r-- but there is only working (it's -rwxrwxr-x)

    The command I am using is:
    find $LOCATION/ -type f -name *.tmpl

    Anyone have any ideas why it might be returning just the one?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 240 ✭✭saltie


    Most likely your $LOCATION variable is not being set correctly. Where do you set it, in the shell or script?


  • Registered Users, Registered Users 2 Posts: 427 ✭✭eve


    $LOCATION is fine. It's set as an evironment variable and when I run it off the command line I get the one file that is actually being converted correctly.


  • Registered Users, Registered Users 2 Posts: 354 ✭✭AndrewMc


    Can you run "ls -l" on the files concerned and show the output?


  • Registered Users, Registered Users 2 Posts: 427 ✭✭eve


    Here's a sample of some of them. The details of the one that is working is at the end. I've had to change the names of the files.

    -rwxrwxr-x 1 user user 2135 Apr 19 18:57 FILE_1.xml.tmpl
    -rw-rw-r-- 1 user user 2208 Jun 28 09:35 FILE_2.xml.tmpl
    -rwxrwxr-x 1 user user 2334 Apr 19 18:57 FILE_3.xml.tmpl
    -rwxrwxr-x 1 user user 2326 Apr 19 18:57 FILE_4.xml.tmpl
    -rwxrwxr-x 1 user user 2133 Apr 19 18:57 FILE_5.xml.tmpl
    -rwxrwxr-x 1 user user 2087 Apr 19 18:57 FILE_6.xml.tmpl
    -rw-rw-r-- 1 user user 2056 Apr 19 18:57 FILE_7.xml.tmpl
    -rwxrwxr-x 1 user user 2771 Apr 19 18:57 FILE_8.xml.tmpl
    -rwxrwxr-x 1 user user 2645 Apr 19 18:57 FILE_9.xml.tmpl
    -rwxrwxr-x 1 user user 2939 Jun 28 09:35 FILE_10.xml.tmpl
    -rwxrwxr-x 1 user user 2063 Apr 19 18:57 FILE_11.xml.tmpl
    -rw-rw-r-- 1 user user 2205 Jul 5 15:51 working.xml
    -rwxrwxr-x 1 user user 2269 Apr 19 18:57 working.xml.tmpl


  • Registered Users, Registered Users 2 Posts: 427 ✭✭eve


    A very strange thing that I am hoping has fixed the problem. There was a copy of working.xml.tmpl in the root of the user where the script was being run. When I removed this is seems to find all the .xml.tmpl's in the $LOCATION directory.

    I'm hoping thats the end of it.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    eve wrote:
    find $LOCATION/ -type f -name *.tmpl

    The * is the problem and it is caused by shell substitution. It is worth understanding how this works.... You said that there was a .tmpl file in the directory you were running from so what happens is this: The shell looks in the current directory and substitutes *.tmpl for "yourfilename.tmpl" and the actual find command really looks like:

    find /the/location/ -type f -name yourfilename.tmpl

    It can't find that, because yourfilename.tmpl doesn't exist at /the/location (or whatever that env $LOCATION var points to).

    To fix it, you need to wrap the *.tmpl in quotes, like this:

    find $LOCATION/ -type f -name "*.tmpl"

    This stops the shell from performing substitution on *.tmpl, so the actual find command is now:

    find /the/location/ -type f -name "*.tmpl"

    Another example. When you run "rm *" what's really happening is:

    rm file1.txt file2.txt file3.txt etc. (for all files in the current directory).

    I hope that makes sense. It's an important concept in unix like machines and can help you in lots of positive ways. e.g. if I want to edit a file called "myVeryFunny_long file.txt", and there's only one .txt file in the directory, I can say "vi *.txt" and the shell does the subsitution for me. likewise "vi my*" would work, etc.


Advertisement