Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ディレクトリにあるc.txtとしbます。unlink c.txt簡単です。システム{XXX, c.txt}は directory のエントリを削除するだけbです。bしかし、が のサブディレクトリでa、 のリンクを解除したい場合はどうbなりますか? 手順は同じですか、それとももっと複雑ですか?
c.txt
b
unlink c.txt
{XXX, c.txt}
a
unlink(2)ファイルのみを削除できますが、rmdir(2)空のディレクトリのみを削除できます。
unlink(2)
rmdir(2)
ディレクトリを再帰的に削除したい場合は、両方のシステムコールを賢く使用する必要があります。たとえば、これは を使用してnftwおり、これopendirは/を使用してreaddirいます。
nftw
opendir
readdir
リンク解除のマニュアルページから:
When the utility is called as unlink, only one argument, which must not be a directory, may be supplied.
そのため、unlink を使用する場合、ディレクトリをパラメーターとして渡すことはできません。