當前位置:首頁 » 操作系統 » 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 10:08:32 瀏覽:548
電容觸摸安卓一體機市場前景如何 發布:2025-07-11 10:08:27 瀏覽:839
c程序的編譯單位是 發布:2025-07-11 10:07:42 瀏覽:900
怎麼看網站的伺服器 發布:2025-07-11 10:03:16 瀏覽:603
紅米手機wlan輸入密碼在哪裡 發布:2025-07-11 10:02:32 瀏覽:432
懶人學編程 發布:2025-07-11 09:44:58 瀏覽:333
android命令行簽名 發布:2025-07-11 09:44:15 瀏覽:881
應用密碼怎麼取消密碼 發布:2025-07-11 09:28:33 瀏覽:797
pythonubuntumysql 發布:2025-07-11 09:23:47 瀏覽:531
硬碟屬於外部存儲器嗎 發布:2025-07-11 09:09:39 瀏覽:936