Remove File (or Delete) on linux computer system can be performed via terminal using command line. While file also can be created, renamed, modified, grown, and shrunk (truncated). In most cases, software programs that are executed on the computer handle these operations, but the user of a computer can also modify files if necessary.

For instance, files are normally removed by program in response to user commands, but the user can also delete these files directly by using a file manager program such as Windows Explorer (on Windows computers) or via terminal with command line (CLI) on linux system.

How To Remove File on Linux?

You can easily remove or delete file on linux with the following methods rm, and Information via terminal on your system with the command line.


“rm” command is used to delete objects such as files, directories, symbolic links and the contents within them from the file system. You should be careful with this, because once the file is deleted, it is hardly to recover.

To remove file on linux:

  1. Open “Terminal” on linux system
  2. Keep on the current working directory or go to the specific directory (use “cd” to change directory) that you want to remove the file inside it
  3. Use “rm” command and specify “file-name”
  4. The syntax for using the “rm” command as shown below
    rm [option] [file-name]
    • Remove a file on linux in the current directory
      rm doc.txt
    • Remove “multiple files” on linux, use “rm” command followed by the file names separated by space.
      rm doc.txt docs.pdf text.html
    • Use a “wildcard” (*) and regular expansions to match multiple files. For example, to remove all “.txt” files in the working directory.
      rm *.txt
    • Use the “rm” with the “-i” option to confirm each file before deleting it.
      rm -i doc.txt
  5. Done, now you’ve already removed the files

More Information

“rm” command related information can be obtained with “–help”.

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-root do not treat ‘/’ specially.
–preserve-root[=all] do not remove ‘/’ (default); with ‘all’, reject any command line argument on a separate device from its parent.
-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.

By default, rm does not remove directories. Use the –recursive (-r or -R) option to remove each listed directory, too, along with all of its contents.

To remove a file whose name starts with a ‘-‘, for example ‘-foo’, use one of these commands:
rm — -foo
rm ./-foo

Note that if you use rm to remove a file, it might be possible to recover some of its contents, given sufficient expertise and/or time. For greater assurance that the contents are truly unrecoverable, consider using shred.

Many computer systems use extensions in file names to help identify what they contain, also known as the file type. Extensions consist of a dot (period) at the end of a file name, followed by a few letters to identify the type of file. An extension of .txt identifies a text file; a .doc extension identifies any type of document or documentation, and so on.

Files can be located in directories. A name that refers to a file within a directory must be typically unique. In other words, there must be no identical names within a directory. However, in some operating systems, a name may include a specification of type that means a directory can contain an identical name for more than one type of object such as a directory and a file.

License: CC-BY-SA Creative Commons License