The unlink is a command-line utility for removing a single file. It calls directly interfaces with the unlink system function, which removes a specified file. This tutorial shows you how to remove a file in Linux using
Removing File with unlink
Following is the syntax for the
Here, you should replace FILENAME with your real file name. This command will not show any output and returns zero on success.
You can use only two options along with
--help which displays the command help and
--version which shows the version information.
unlink command accept only single arguments, means you can remove only one file. You will get “unlink: extra operand” error if you pass multiple arguments.
The destination target will not deleted when removing symbolic links with
You should have writing permission on parent directory of the symlink. Otherwise, you will get “Operation not permitted” error.
For instance, if you try to remove the example.com under the
/etc/nginx/sites-enabled directly which is owned by
It will show the following error message:
unlink: cannot unlink '/etc/nginx/sites-enabled/example.com': Permission denied
You cannot delete a directory using unlink command. You will get error if you try to remove a directory:
unlink: cannot unlink 'directory_name': Is a directory
This tutorial shown you how to remove file using unlink command. You should take before removing any files.
If you have any questions or suggestion, leave a comment below.