• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Unlink Command in Linux (Remove File)

Written by Admin, Updated On June 11, 2020
terminal, unlink
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.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Skype on Ubuntu 20.04 LTS
Next Article   How to Delete (Remove) Symbolic Links in Linux

Related Posts

  • How to Use sed to Find and Replace String in Files

    How to Use sed to Find and Replace String in Files

    December 18, 2020
  • Linux Head Command

    Linux Head Command

    December 16, 2020
  • Rename Files and Directories in Linux

    How to Rename Files and Directories in Linux

    December 15, 2020

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook