0

this is simple CLI to remove couple file on remote machine

 ssh 182.2.34.1 "rm -f /etc/yum.repos.d/repo.1 master.er top.fg  REPO.l"

but only repo.1 file was deleted

what is wrong with my syntax

5

master.er, top.fg, and REPO.1 are being removed from current directory (which is probably your home directory). You should provide full path to the directories.

2

The command rm -f /etc/yum.repos.d/repo.1 master.er top.fg REPO.l will delete exactly those files. The files other than the first are being deleted in the current directory, which is likely to be your home directory on the remote machine.

If all four files are to be deleted from /etc/yum.repos.d, you may use

ssh 182.2.34.1 "cd /etc/yum.repos.d && rm -f repo.1 master.er top.fg REPO.l"

This will first changed the current directory, and if that is successful, it will delete the files.


Also note that you ideally should not work as root but as an unprivileged user. This may mean that your ssh command may end up looking as

ssh 182.2.34.1 "cd /etc/yum.repos.d && sudo rm -f repo.1 master.er top.fg REPO.l"

and that you execute this as a non-root user with sudo access on the remote machine (there is seldom a reason to allow SSH access by root).

The benefit of this is that you explicitly state your intention to issue an operation as root, and that the commands executed as root are logged. The logging is important if you need to recover what operations may have hosed a system.

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.