Site icon DesignLinux

Unlink Command in Linux (Remove File)

Unlink Command in Linux (Remove File)

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 unlink command.

Removing File with unlink

Following is the syntax for the unlink command:

unlink FILENAME

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 unlink command, --help which displays the command help and --version which shows the version information.

The 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 unlink.

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 root:

unlink /etc/nginx/sites-enabled/example.com

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 directory_name
unlink: cannot unlink 'directory_name': Is a directory

Conclusion

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.

Exit mobile version