1

I connect via lftp -u username, sftp://server.name.com:/directory to a sftp-server, which works correctly.

Anyhow, I want to use find. -name *someWildcardExpression -type f -delete in order to delete all files in the directory as well as subdirectories. Actually, find finds all relevant files. However, it also tries to access directories created by the arguments passed to find:

lftp [email protected]:/directory> find . -name *someWildcardExpression -type f

# Output
./
./file_a.csv.gz.gpg
./subdir/
./subdir/file_a.csv.gz.gpg
./subdir/file_b.csv.gz.gpg
./subdir/file_c.csv.gz.gpg
find: No such file (/directory/-name)
find: No such file (/directory/*someWildcardExpression )
find: No such file (/directory/-type)
find: No such file (/directory/f)

This does not seem right. Am I using the find-command wrong, or is this a bug?

2
  • Try find . -regex '*someWildcardExpression' -type f (attention before using -delete).
    – harrymc
    Commented Feb 25, 2021 at 16:35
  • Unfortunately, this also results in the analog error: find: No such file (/directory/-regex)
    – Markus
    Commented Feb 25, 2021 at 17:03

1 Answer 1

2

Am I using the find-command wrong, or is this a bug?

You're using it wrong because it's not the find-command you think it is. You're inside lftp, not in a general-purpose shell. You're not invoking find(1) compatible with POSIX find, whose manual you can read by running man 1 find in a shell. You're invoking a part of lftp whose manual reads:

find [OPTS] directory...

List files in the directory (current directory by default) recursively. This can help with servers lacking ls -R support. You can redirect output of this command.

Options:

-d MD, --max-depth=MD specify maximum scan depth
-l, --ls use long listing format

There are no other options. That's why every "option" you used was treated like a directory.

lftp allows you to run an arbitrary shell command by prepending the command with !, but it will run the command locally (where lftp runs), not on the server. It seems you want to run find on the server.

This is what you can do:

  1. Use find inside lftp without syntax it doesn't understand, parse its output locally to imitate -name *someWildcardExpression -type f. You probably can imitate -name by matching the string after the last non-trailing / in each line. You cannot fully imitate -type f, but it seems you can imitate ! -type d (it seems directories are printed with a trailing slash), ask yourself if it's enough.
  2. If you can ssh to the server, use it to run the server's find(1).
  3. Use sshfs to make the remote directory appear local, then invoke local find(1).

You must log in to answer this question.

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