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

7
  • 1
    Is there a Templates subdirectory visible from the point where you are running the script? Mar 16, 2020 at 20:03
  • 1
    @jesse_b that's normal - the error message does indeed include those paired quotes Mar 16, 2020 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, 2020 at 20:06
  • 1
    But you haven't used ~/Templates in your command Mar 16, 2020 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, 2020 at 21:45

3 Answers 3

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".

3
  • 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, 2020 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 /. Mar 29, 2020 at 20:21
  • that was it, I was missing slash character the whole time, now it works, thank you !
    – mauek unak
    Mar 30, 2020 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
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)

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .