• 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 Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install PHP 8.2 on Debian 11
    How to Install PHP 8.2 on Debian 11 Linux February 24, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
© 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