當前位置:首頁 » 操作系統 » unlinklinux

unlinklinux

發布時間: 2024-11-08 02:31:30

1. linux shell中,unlink和rm命令有什麼區別

strace 跑 rm 與 unlink,結果有不同地方.

1. strace rm 1.txt 片段

access("1.txt", W_OK) = 0

unlinkat(AT_FDCWD, "1.txt", 0) = 0

復制代碼

2. strace unlink 2.txt 片段

unlink("2.txt") = 0

復制代碼

我想可以再看看 unlink 與 unlinkat 的 manpage 說明應該有答案 ?

The unlinkat() system call operates in exactly the same way as either unlink(2) or rmdir(2) (depending on

whether or not flags includes the AT_REMOVEDIR flag) except for the differences described in this manual

page.

AT_REMOVEDIR

By default, unlinkat() performs the equivalent of unlink(2) on pathname. If the AT_REMOVEDIR flag

is specified, then performs the equivalent of rmdir(2) on pathname.

復制代碼

測試用 strace rm -r testdir 方式刪除一個目錄與其下的檔案目錄,結果為:

access("testdir", W_OK) = 0

unlinkat(AT_FDCWD, "testdir", AT_REMOVEDIR) = 0

復制代碼

所以結論一般命令用 rm 或是 unlink 都可以刪除檔案,因為都是一樣的意思。系統面呼叫來說刪除檔案一般還是使用 unlink() 呼叫,只是有另外提供 unlinkat 提供相同機制,但是可以刪除檔案或是空目錄。

熱點內容
研發部門如何配置電腦 發布:2025-07-11 08:35:13 瀏覽:133
androidassets文件路徑 發布:2025-07-11 08:28:46 瀏覽:164
安卓源碼如何變成ios 發布:2025-07-11 08:20:35 瀏覽:625
純油雅閣配置怎麼選 發布:2025-07-11 08:16:37 瀏覽:320
數控圓孤編程 發布:2025-07-11 08:13:08 瀏覽:256
超級訪問羅大佑 發布:2025-07-11 07:43:33 瀏覽:387
邁騰有什麼安全配置 發布:2025-07-11 07:42:40 瀏覽:644
c語言字元逆序 發布:2025-07-11 07:41:57 瀏覽:923
怎麼配置交換機的console密碼 發布:2025-07-11 07:41:57 瀏覽:4
東芝存儲卡視頻 發布:2025-07-11 07:41:55 瀏覽:541