+1 vote
in Operating Systems by (88.7k points)
I want to delete all files except the one that starts with 'Hello_' in folder '/backup' using bash command. Can you provide me with the bash command that can do it?

1 Answer

+2 votes
by (362k points)
selected by
 
Best answer

To delete all files in the folder /backup/ except the ones starting with 'Hello_', you can use the following Bash command:

find /backup/ -type f ! -name 'Hello_*' -delete

  • "find /backup/" searches in the /backup/ directory.
  • "-type f" ensures only files (not directories) are targeted.
  • ! -name 'Hello_*' excludes files that start with 'Hello_'.
  • -delete deletes all files that do not match 'Hello_'.

...