How to delete files in linux/unix

To delete (or remove) files with the command line is the most commonly used function in linux/unix.

We can use the rm command or the unlink command.

In this tutorial, we will show you how to use the rm and unlink commands to remove files in Linux/Unix.

The unlink command allows you to remove only a single file, while with rm you can remove multiple files at once.

To delete a single file, use the rm or unlink command followed by the file name:
➜   unlink filename

➜   rm filename

To delete multiple files at once, use the rm command followed by the file names separated by space.
➜   rm filename1 filename2 ...
Use wildcards (*) and regular extensions to match multiple files.

For example, to delete all .log files in the current directory, use the following command:

➜   rm *.log
Use curly bracket expressions to delete multiple files in batch
➜  rm {2..4}.log

Use the rm -f option to force delete files without prompting for confirmation
➜  rm -f filename

Use the rm -i option to confirm each file before deleting it
➜  rm -i filename

Add a Comment

Your email address will not be published.