0

I have following line in a script:

find ~ Templates -maxdepth 0 -type d -empty

which works fine, as expected. However when I copy my script to samba share and run it from there (bash myscript.sh), find doesn't find the directory:

find: ‘Templates’: No such file or directory 

$PATH variables are the same, in strace I couldn't find reason for this either.

Anybody knows why find behaves this way ? Is it a bug or am I not using find command as I am supposed to ?

using Ubuntu 19.10 and bash 5.0

  • 1
    Is there a Templates subdirectory visible from the point where you are running the script? – roaima Mar 16 at 20:03
  • 1
    @jesse_b that's normal - the error message does indeed include those paired quotes – roaima Mar 16 at 20:04
  • with find command no-I get same error, but when I do 'ls ~/Templates' from same remote directory I can see it, only find command doesn't see it – mauek unak Mar 16 at 20:06
  • 1
    But you haven't used ~/Templates in your command – roaima Mar 16 at 20:07
  • 1
    > because Templates is directory I am searching for in a '~' or user's home directory you should say it in your question cause at the moment noone knows what is your goal. – tansy Mar 17 at 21:45
2

You are getting the message find: ‘Templates’: No such file or directory because there is no Templates subdirectory

  • either - from the point you are running the script
  • or - in the directory to which some un-mentioned cd in your script has switched

I'm wondering if this is all a typo and you meant ~/Templates. Either way, you should not use ~ in a script but instead use "$HOME", so the resulting path would be "$HOME/Templates".

| improve this answer | |
  • I tried use $HOME instead of ~, no difference, command 'find ~ *' run from samba directory returns content of current samba location, not my home directory, which I don't think is correct, since I asked for content of home directory, not the current one with 'find . *' – mauek unak Mar 29 at 16:05
  • @mauekunak of course find ~ * will list the contents of your home directory and then the current directory. For some reason you seem to be ignoring the directory separator /. – roaima Mar 29 at 20:21
  • that was it, I was missing slash character the whole time, now it works, thank you ! – mauek unak Mar 30 at 5:06
0

"no, because Templates is directory I am searching for in a '~' or user's home directory"

find ~ -maxdepth 0 -type d -empty -name Templates
| improve this answer | |
0

What makes you believe that samba has the same environmental variables as linux?

Use real/full path to directory you want to search as ~ is not directory, it's probaly empty - that's why find treats Templates as path not search pattern (find: ‘Templates’: No such file or directory).

Can you start shell in your samba directory and see what it is with $ pwd? You can also check whole environment with $ set;

Using Samba book variables chapter says that home directory is %H not ~.

small experiment:

$ ls -l | grep -E '^d'  # to show there is 1 directory (tmp), which is not empty but doesnt have `Templates`
drwxr-xr-x 2  user  group  24576 Mar 16 16:16 tmp
$ find Templates -maxdepth 0 -type d -empty  # as if <path> (`~`) was empty
find: Templates: No such file or directory

$ find tmp Templates -maxdepth 0 -type d -empty  # as if `~` was `tmp`
find: Templates: No such file or directory

Either ~ is empty (first find ... with "empty" path.) or you don't have Templates in searched path (second find).

$ touch Templates
$ find tmp Templates -maxdepth 0 -type d -empty  # as if `~` was `tmp`

$ rm Templates; mkdir Templates
$ find tmp Templates -maxdepth 0 -type d -empty  # as if `~` was `tmp`
Templates

If

Templates is directory I am searching for in a '~' or user's home directory

then

$ find ~ -maxdepth 1 -type d -empty -name Templates
~/Templates

Should solve the problem.

-maxdepth 0 only applies the tests and actions to the command line arguments (according to man find; check also this answer)

| improve this answer | |
  • 1
    In many shells ~ represents the user's "$HOME" directory. And %H is for the server-side configuration file, not the client. – roaima Mar 16 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.