Notice
Recent Posts
Recent Comments
Today
Total
05-06 03:37
Archives
관리 메뉴

Jeongchul Kim

리눅스 unlink, remove - 리눅스 시스템 프로그래밍 본문

Linux

리눅스 unlink, remove - 리눅스 시스템 프로그래밍

김 정출 2016. 2. 29. 11:37


리눅스 unlink, remove - 리눅스 시스템 프로그래밍


unlink와 remove의 기능은 pathname으로 지정한 파일을 삭제하는 것입니다.

unlink는 비어 있는 디렉터리에 대해서는 삭제 기능을 수행할 수 없습니다.

그러나 remove는 비어 있는 디렉터리를 삭제할 수 있습니다.

하지만 둘 다 파일을 가지고 있는 디렉터리는 삭제할 수 없습니다.


int unlink(const char* pathname);

int remove(const char* pathname);


> pathname : 삭제할 파일의 경로

> return 값 :  삭제가 성공할 경우 0이 반환되며, 실패할 경우 -1이 반환됩니다.



#include <unistd.h>

#include <fcntl.h>

#include <stdio.h>

int main()

{

if(unlink("unlink.txt") == -1) {

perror("unlink.txt delete failed!");

return 1;

}

if(remove("remove.txt") == -1) {

perror("remove.txt delete failed!");

return 1;

}

}




Comments