5

What are the system calls that can be used to delete a file on Linux? I am not referring to just the system calls used by the libc-wrapper(which in-turn are used by command line tools).

Other than unlink and unlinkat what are the system calls that could be used to delete files on a Linux machine?

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
  • I don't understand what you're searching for! What's your need, what are you trying to do? Or why do `unlink`not be enough? – F. Hauri - Give Up GitHub Feb 24 '16 at 19:04
  • I'm trying to monitor all file deletions across my system for a pet project. Most applications use `unlink` and `unlinkat`, but I want to know if there are other system calls that can be used to delete files. –  Feb 24 '16 at 21:10
  • I don't really understand why there are 2 votes to close this question, it is related to programming. –  Feb 24 '16 at 21:11
  • @uki If you want to monitor filesystem events in general, consider using the [`inotify`](http://man7.org/linux/man-pages/man7/inotify.7.html) API. –  Feb 24 '16 at 22:47

1 Answers1

4

rename() and renameat() can be used to delete a file by renaming another file over it.

If you consider making a file empty to be a form of deletion, a variety of system calls, including truncate() and open() with O_TRUNC, can do that.