This post will guide you how to delete or remove files on your Ubuntu/Debian Linux. How do I remove directories under your Ubuntu/Debian Linux. How to quickly delete a file under a directory in Ubuntu/Debian Linux.
Delete a Files On Ubuntu/Debian
You need to user the rm command to remove files on Ubuntu/Debian linux. Assuming that you want to delete a file called ubuntutmp.txt under /myfio directory, you just need to execute the rm command with the file name that you want to remove in command line interface of your Ubuntu/Debian system.
Just do the following steps:
#1 open a terminal or command line interface on your Ubuntu/Debian Linux
#2 type the following command to remove ubuntutmp.txt file
$ sudo rm ubuntutmp.txt
Delete Multiple Files on Ubuntu/Debian
If you want to remove multiple files on a directory, you can can use the rm command to achieve it. you just need to pass the file names to rm command and separated by space. For example, you want to delete two files under the /mylinux directory, type the following command:
$ sudo rm myubuntu1.txt myubuntu2.txt
Note: before removing the files, you need to change the current directory to /mylinux directory. type:
$ cd /mylinux
or you can also use the absolute path while you delete file, type:
$ sudo rm /mylinux/myubunt1.txt /mylinux/myubuntu2.txt
Confirm each file before removal on Ubuntu/Debian
if you want to get the confirmation for each file while removing, you can use the rm command with -i option, type:
$ sudo rm -i myubuntu.txt
Outputs:
[osetc@osetc_x8664 ~]$ sudo rm -i myubuntu.txt rm: remove regular empty file ‘myubuntu.txt’? y [osetc@osetc_x8664 ~]$
Show report of each file removed
if you want to get the report of each file removed, you need to use the rm command with -v option, type:
$ sudo rm -v myubuntu.txt
outputs:
[osetc@osetc_x8664 ~]$ sudo rm -v myubuntu.txt rm: remove regular empty file ‘myubuntu.txt’? y removed ‘myubuntu.txt’
Remove Directory on Ubuntu/Debian
if you want to use the rm command to remove a directory , you need to use the -d option, type:
$ rm -d dubuntu
Outputs:
[osetc@osetc_x8664 ~]$ sudo rm dubuntu rm: cannot remove ‘dubuntu’: Is a directory [osetc@osetc_x8664 ~]$ sudo rm -d dubuntu rm: remove directory ‘dubuntu’? y
Remove all files under a directory(Recursive) on Ubuntu/Debian
if you want to remove a directory and its files or its sub-directory, and you need to use the rm command with -rf option, type:
$ sudo rm -rf myubuntu
if you want to get more information about rm command, you can directory run “rm –help” or “man rm” command.
type:
$ rm --help
outputs:
[osetc@osetc_x8664 ~]$ rm --help Usage: rm [OPTION]... FILE... Remove (unlink) the FILE(s). -f, --force ignore nonexistent files and arguments, never prompt -i prompt before every removal -I prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes --interactive[=WHEN] prompt according to WHEN: never, once (-I), or always (-i); without WHEN, prompt always --one-file-system when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument --no-preserve-osetc do not treat '/' specially --preserve-osetc do not remove '/' (default) -r, -R, --recursive remove directories and their contents recursively -d, --dir remove empty directories -v, --verbose explain what is being done --help display this help and exit --version output version information and exit
Or
$ man rm