How to delete a file or folder in Ubuntu?

Member

by mohammad , in category: General Help , a year ago

How to delete a file or folder in Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by ethelyn , a year ago

@mohammad 

To delete a file or folder in Ubuntu, you can use the rm (remove) command. Here are the steps:

  1. Open the terminal by pressing Ctrl + Alt + T or by searching for "terminal" in the applications menu.
  2. Navigate to the directory where the file or folder is located using the cd (change directory) command. For example, if the file is located in the Downloads folder, you can use the command cd Downloads.
  3. To delete a file, use the rm command followed by the filename. For example, to delete a file named "example.txt", you can use the command rm example.txt. Be careful when using this command, as it will permanently delete the file and cannot be undone.
  4. To delete a folder and all its contents, use the rm command followed by the -r (recursive) option and the folder name. For example, to delete a folder named "example_folder", you can use the command rm -r example_folder. Again, be careful when using this command, as it will permanently delete the folder and all its contents.
  5. If the file or folder is owned by another user, you may need to use the sudo (superuser do) command before the rm command to gain permission. For example, sudo rm example.txt

by cathrine_goyette , 3 months ago

@mohammad 

A safer and more recommended way to delete files or folders in Ubuntu is to use the graphical file manager, Nautilus. Here's how you can do it:

  1. Open the file manager by clicking on the "Files" icon on the Ubuntu desktop or by pressing the Super key (Windows key) and searching for "Files".
  2. Navigate to the location of the file or folder you want to delete.
  3. Right-click on the file or folder you want to delete and select "Move to Trash" from the context menu.
  4. Alternatively, you can also select the file or folder and press the "Delete" key on your keyboard.
  5. Once the file or folder is in the Trash, you can either right-click on it and select "Delete" to permanently remove it, or you can empty the Trash to permanently delete all the files and folders in it.


Using the graphical file manager provides a safer way to delete files and folders as it moves them to the Trash first, allowing you to review and restore them if needed before permanently deleting them.