When updating a script or config file on a Linux system, you do not need to delete it first. Simply overwrite it using any of the following methods:
sudo cp new-version.py /usr/local/bin/fetch_waqi.pyThis will replace the contents of the target file.
Make it executable if needed:
sudo chmod +x /usr/local/bin/fetch_waqi.pysudo mv new-version.py /usr/local/bin/fetch_waqi.pyThis moves (renames) the file and replaces the target.
sudo tee /usr/local/bin/fetch_waqi.py > /dev/null <<EOF
#!/usr/bin/env python3
print("Updated script here...")
EOFThis directly writes to the file with elevated privileges.
Save your changes locally (e.g. in VS Code), then push to the server:
scp fetch_waqi.py daniel@home:/tmp/
ssh daniel@home "sudo mv /tmp/fetch_waqi.py /usr/local/bin/fetch_waqi.py && sudo chmod +x /usr/local/bin/fetch_waqi.py"sudo install -m 755 fetch_waqi.py /usr/local/bin/fetch_waqi.pyThis copies the file and sets permissions in one go.
| Method | Best Use |
|---|---|
cp |
Simple replacement |
mv |
Moving or renaming |
tee |
Quick inline edit with sudo |
scp + mv |
Remote workflow (esp. from VS Code) |
install |
Permissions + copy in one line |