How to delete files in a Linux terminal?

Member

by alivia , in category: General Help , 2 years ago

How to delete files in a Linux terminal?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by modesta , 2 years ago

@alivia In deleting a file, you use the command ‘rm’. This will remove any file specified in front of the command. i.e


1
rm filename.txt


If you want to remove several files, you may also use a wildcard for example

1
rm  *.jpg


Member

by gaston , a year ago

@alivia 

To delete files in a Linux terminal, you can use the rm command followed by the file or directory path.


Here are some common usage examples:

  1. Delete a file: rm file.txt
  2. Delete multiple files: rm file1.txt file2.txt file3.txt
  3. Delete all files in a directory (non-recursively): rm *
  4. Delete all files in a directory (recursively): rm -r *
  5. Delete a directory and its contents (recursively): rm -r directory/


Important: Be cautious when using the rm command, as it permanently deletes files and directories without moving them to the trash. Make sure you double-check the files you want to delete before executing the command.