unlink

unlink LIST
unlinkThis function deletes a list of files.[256] The function returns the number of filenames successfully deleted. Here are some examples:
$count = unlink("a", "b", "c");
unlink @goners;
unlink glob("*.orig");The unlink function will not
delete directories unless you are the superuser and the supply –U command-line option to Perl. Even if these
conditions are met, be warned that unlinking a directory can inflict
Serious Damage on your filesystem. Use rmdir instead.
Here’s a simple rm command with very simple error checking:
#!/usr/bin/perl
@cannot = grep {not unlink} @ARGV;
die "$0: could not unlink all of @cannot" if @cannot;[256] Actually, under a POSIX filesystem, it removes the directory entries (filenames) that refer to the real files. Since a file may be referenced (linked) from more than one directory, the file isn’t removed until the last reference to it is removed.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access