I run this command on my local machine to delete a list of files contained in a text file.
xargs rm -r < deletion_list.txt
It works as expected and deletes all of the files in the current working directory that are listed in deletion_list.txt
.
I then use sftp
to connect to a remote host and create a list of files on my local machine that I want to delete from the remote host.
While connected to the remote host, I enter these commands one by one:
Change local working directory:
lcd /home/user/files_to_delete
Create a text file in my local working directory of files in the same directory matching the specified pattern:
!ls *.txt > deletion_list.txt
This is supposed to delete files on the remote host based on the file names in deletion_list.txt
which is in my local working directory, but it results in an "Invalid Command" error:
xargs rm -r < /home/user/files_to_delete/deletion_list.txt
Why does this not work?
xargs
as a command in thesftp
session? – Kusalananda Feb 28 '20 at 23:14xargs
is not a validsftp
command (see thesftp
manual). – Kusalananda Feb 28 '20 at 23:15ssh
ortelnet
connection. – s3n0 Feb 28 '20 at 23:17!localshellcommand
? – s3n0 Feb 28 '20 at 23:35!xargs rm -r < /home/user/files_to_delete/deletion_list.txt
then I did not. If you are asking if I used a local shell command before thexargs
command, then yes, the command before it uses!ls
. – user-2147482428 Feb 28 '20 at 23:42!rm -r < /home/user/files_to_delete
, but I don't know where yourfiles_to_delete
file is located. This should call a local shell (such as/bin/bash -c "command"
). Another option would be to download the deletion file to the machine, then start deleting the files remotely. BTW, similar questions have already been solved here: https://unix.stackexchange.com/questions/165919/how-to-remove-multiple-files-using-sftp (maybe it will help you though this is not the method you require). – s3n0 Feb 29 '20 at 00:03deletion_list.txt
is the file containing the file names I want to delete, and it is in a local directory on my local machine. The files I want to actually delete are in the remote directory. So I want to delete remote files based on the local list. I've updated my question with a new command that doesn't rely onxargs
. – user-2147482428 Feb 29 '20 at 00:22!
will completely execute on the local machine. It will use local shellrm
command, not remotesftp
rm
. – Martin Prikryl Feb 29 '20 at 07:44help
or?
into the sFTP console. If you want to explain what!
is for, then you should explain whether it is a "local shell" from the point of view of a server running sFTP service, or whether it is a "local shell" from the point of view of an administrator's machine (from which the administrator has connected to the sFTP server). The term "local" is therefore very misleading from the perspective of computer networks. There is still a problem that sFTP has limited commands and cannot be used as a regular SSH regular connection. – s3n0 Feb 29 '20 at 09:52