Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

unlink(2) [v7 man page]

UNLINK(2)							System Calls Manual							 UNLINK(2)

unlink - remove directory entry SYNOPSIS
unlink(name) char *name; DESCRIPTION
Name points to a null-terminated string. Unlink removes the entry for the file pointed to by name from its directory. If this entry was the last link to the file, the contents of the file are freed and the file is destroyed. If, however, the file was open in any process, the actual destruction is delayed until it is closed, even though the directory entry has disappeared. SEE ALSO
rm(1), link(2) DIAGNOSTICS
Zero is normally returned; -1 indicates that the file does not exist, that its directory cannot be written, or that the file contains pure procedure text that is currently in use. Write permission is not required on the file itself. It is also illegal to unlink a directory (except for the super-user). ASSEMBLER
(unlink = 10.) sys unlink; name UNLINK(2)

Check Out this Related Man Page

UNLINK(2)						      BSD System Calls Manual							 UNLINK(2)

unlink -- remove directory entry SYNOPSIS
#include <unistd.h> int unlink(const char *path); DESCRIPTION
The unlink() function removes the link named by path from its directory and decrements the link count of the file which was referenced by the link. If that decrement reduces the link count of the file to zero, and no process has the file open, then all resources associated with the file are reclaimed. If one or more process have the file open when the last link is removed, the link is removed, but the removal of the file is delayed until all references to it have been closed. RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
The unlink() succeeds unless: [ENOTDIR] A component of the path prefix is not a directory. [ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters. [ENOENT] The named file does not exist. [EACCES] Search permission is denied for a component of the path prefix. [EACCES] Write permission is denied on the directory containing the link to be removed. [ELOOP] Too many symbolic links were encountered in translating the pathname. [EPERM] The named file is a directory and the effective user ID of the process is not the super-user. [EPERM] The directory containing the file is marked sticky, and neither the containing directory nor the file to be removed are owned by the effective user ID. [EBUSY] The entry to be unlinked is the mount point for a mounted file system. [EIO] An I/O error occurred while deleting the directory entry or deallocating the inode. [EROFS] The named file resides on a read-only file system. [EFAULT] Path points outside the process's allocated address space. SEE ALSO
close(2), link(2), rmdir(2) symlink(7) HISTORY
An unlink() function call appeared in Version 6 AT&T UNIX. 4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution
Man Page

15 More Discussions You Might Find Interesting

1. Programming

using C to copy a file ...

Hi mates, I have created a shell of my own and one of the built in functions is COPY. This command is supposed to check the availability of a command in a specific direcotry and if the command is available chnage its extension to old. my problem is that how can i search for that specific file in... (1 Reply)
Discussion started by: abdul
1 Replies

2. Programming

need help with file manipulation

I've been able to open and write data to files but I need to know how to search a file for a hex string and replace it. (2 Replies)
Discussion started by: angelfly
2 Replies

3. UNIX for Advanced & Expert Users

link and unlink , urgently...

Hi all I did something incorrectly about link command. I try to make a link from a sub-dir to root dir, but I use the following command: link / zzz the result is sub-dir "zzz" was linked to "/" Then I want to remove the "zzz" by using unlink command: unlink zzz It say that "Device... (1 Reply)
Discussion started by: umonk
1 Replies

4. Programming

What does unlink"tmep.log" do?

Hi, I saw this C program on Unix with unlink("tmp.log"); unlink("time.log"); at the end of the file. What's the purpose of doing this? Thanks a lot! (1 Reply)
Discussion started by: whatisthis
1 Replies

5. UNIX for Dummies Questions & Answers

mv: cannot unlink ????

Hello all, I have a script which runs every 15 minutes and moves all but latest 10 files from a directory (A) to Directory (B). Most of the times this job runs fine but sometimes it is giving "mv: cannot unlink {Target Directory name } : Permissions denied." Any help about this error msg... (1 Reply)
Discussion started by: super_duper_guy
1 Replies

6. Shell Programming and Scripting

perl unlink question

Hi, I have a two lines of code both intend to perform the same task. unlink $CtrFile; system ("rm $CtrFile"); Both of which try to delete a certain file. However when I use the unlink command the file does not get deleted. When I use the "rm" system... (2 Replies)
Discussion started by: jerardfjay
2 Replies

7. Solaris

Accidentally did a unlink inet

I was trying to remove a symbolic link of /etc/hosts to /etc/inet/hosts well i forgot the command and in the /etc directory i did unlink inet and now i can not get into inet and it does not exist in /etc 1) what do i do to fix the inet directory 2) how do i link /etc/hosts to... (1 Reply)
Discussion started by: deaconf19
1 Replies

8. UNIX for Dummies Questions & Answers

How do you delete files that are seemingly missing inodes?

I have some files that appear to have no inode numbers. To complicate the matter, the filenames have UTF8 (I think) characters. I am trying to delete them. In fact, and this might make things easier, I'm trying to delete their parent directory. I don't know what to try next, please help. ... (5 Replies)
Discussion started by: jaffachamp
5 Replies

9. Solaris

Cron could not unlink FIFO

We are using Solaris 10 on tiny box. My issue is after server panic cron is not coming up, I've tried to manually restart cron but no luck. # cron stop cron could not unlink FIFO: no such file or directory ! cannot create fifo queue Thu Dec 17 11:20:17 2009 ! ******* CRON ABORTED *******... (5 Replies)
Discussion started by: patidarv
5 Replies

10. Shell Programming and Scripting

How to Unlink all files in a directory?

I had a directory like A/B/C and these are all what I did. cd A/B/C ln -s some_path/some_sub_dir/C/* . After this, I have around say 1000 files linked to my A/B/C directory. How can unlink all those files at one shot? The unlink command requires filename as an argument but what I need is to... (1 Reply)
Discussion started by: dahlia84
1 Replies

11. Shell Programming and Scripting

Using Stats in Php

So, I have a php program that i need to delete ALL files in a directory that are older than a certain age. <?php /* Get file stat */ $stat = stat('/apps/security/ajaba'); This is as far as I've been able to get. I know in shell programming you can easily do something like this. but I'm... (2 Replies)
Discussion started by: SkySmart
2 Replies

12. UNIX for Dummies Questions & Answers

Is there a way to completely remove an inode when the Link count is 2 ?

Currently my data is organised in a volume which has a cache directory (where all the files are first created or transferred). After that there are suitable directories on the volume which in their subdirs, contain files hardlinked to files in the cache. This is done so that the same inode... (1 Reply)
Discussion started by: abcdino
1 Replies

13. UNIX for Advanced & Expert Users

du and df do not match on NFS share

Here is the scenario... NFS share that is accessed every few minutes by approx 70 systems (AIX 5.3/6.1). Filesystem space is being eaten up rapidly according to df however du numbers really never change. lsof and fuser cannot see any unlinked files on either the NFS server or remote... (3 Replies)
Discussion started by: masterpengu
3 Replies

14. Shell Programming and Scripting

Unlink and copy actual file

Hello, I have a set of directories, which has inside them, symbolic links to some files. What i would like to do is to covert the links into actual files, i.e. remove the link and copy the actual file here... I tried to see unlink command but i think all it does is delete the link, is... (2 Replies)
Discussion started by: prasbala
2 Replies

15. Shell Programming and Scripting

Unable to unlink files perl

Hi, I have a dir and some files as below (all have full perm) drwxrwxrwx 2 sam sam 4096 Aug 8 04:31 /home/sam/test $ ll /home/sam/test -rwxrwxrwx 1 sam sam 0 Aug 8 04:31 b1_2013_file.txt -rwxrwxrwx 1 sam sam 0 Aug 8 04:31 c1_2014_file.txtI want to go to this directory and delete the... (2 Replies)
Discussion started by: sam05121988
2 Replies