How to Use unlink Command in Linux (Remove File)

How to Use unlink Command in Linux (Remove File)

In this article we are going to shows how to use unlink command in Linux. If you want to learn about unlink command in Linux with Examples then this post is ideal for you.

In the Linux, unlink is a system call and command line utility that is used to delete a single files. It calls directly interfaces with the unlink system function, which is removed a given or specified file.

Linux is an operating system, like Windows OS, iOS, and Mac OS. It is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system).

Linux OS(operating system) is also distributed under an open source license. Open source following these points :

  • Freely to run the program, for any purpose.
  • Free to study how the program works.
  • It is free to re-distribute copies so you can help your friends.
  • Free to distribute copies of your modified versions to others.

How to use unlink Command in Linux

In the Linux, the basic syntax of the unlink command is show as below:

unlink FILENAME

OR

unlink OPTION

Replace FILENAME with the file you want to remove.

Options

–helpIt is display command help message and exit.
–versionIt is shows the version information and exit.

The unlink command accept only a single argument, It means that you can pass only one file to delete. If you pass more than one files to remove then it show “unlink: extra operand” error.

To delete a specified file from your system, you should have writing permissions on the parent directory containing that file. Otherwise, you will get “Permission denied” error.

For an example, if you want to remove the file file.txt located at the /etc directory that is owned by root:

unlink /etc/file.txt
Output
unlink: cannot unlink '/etc/file.txt': Permission denied

On GNU/Linux systems, you can’t delete a directory with unlink command. If you pass a directory to delete then you will get an error:

unlink dirname
Output
unlink: cannot unlink 'dirname': Is a directory

That’s all

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top