Ubuntu how to remove file, link, folder

Ubuntu remove single file

rm myfile.txt is enough for removing single file "myfile.txt" from folder /home/user/folder using terminal:

  • if your user has permissions and you are in another folder
rm /home/user/folder/myfile.txt
  • using super user with check:
  • go in the folder of the file
  • check all files by ls -s
  • delete the file with super user rights
  • check files after deletion
cd /home/user/folder/
ls -s
sudo rm myfile.txt
ls -s

Removing single symbolic link can be done by : rm mylink or unlink. The command unlink uses rm and do the same thing:

rm /home/user/folder/mylink
unlink /home/user/folder/mylink

Ubuntu remove folder

If you want to delete folder in ubuntu you can do it by: rm -r -f /home/user/folder/

direct delete

sudo rm -r -f /home/user/folder/
  • go in the parent folder
  • check all files by ls -lha
  • delete the folder
    • -r or recursive - delete the folder and subfolders(non-empty or empty)
    • -f or force
  • check files after deletion

go to the folder

cd /home/user/
sudo ls -lha folder/
sudo rm -r -f folder/