Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

'find' not seeing matching files

  • 05-07-2007 4: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 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