當前位置:首頁 » 操作系統 » 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-05-16 06:27:53 瀏覽:239
美嘉演算法口訣 發布:2025-05-16 06:03:15 瀏覽:952
c程序編譯連接 發布:2025-05-16 06:02:36 瀏覽:964
腳本魔獸 發布:2025-05-16 06:01:52 瀏覽:330
文件夾python 發布:2025-05-16 06:01:43 瀏覽:627
電腦我的世界伺服器游戲幣 發布:2025-05-16 05:27:25 瀏覽:489
索尼手機為什麼不能用安卓10 發布:2025-05-16 05:18:46 瀏覽:784
蔚來es6選擇哪些配置實用 發布:2025-05-16 05:18:05 瀏覽:130
小米如何掃碼wifi密碼 發布:2025-05-16 05:13:38 瀏覽:807
樓層密碼是什麼意思 發布:2025-05-16 05:13:37 瀏覽:13