當前位置:首頁 » 操作系統 » 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-09-14 07:48:54 瀏覽:976
sqlsaserver 發布:2025-09-14 07:44:42 瀏覽:961
pythonif寫一行 發布:2025-09-14 07:41:39 瀏覽:994
lua存儲數據 發布:2025-09-14 07:33:05 瀏覽:111
教你如何選配置車 發布:2025-09-14 07:32:21 瀏覽:417
行李箱自帶的密碼是多少 發布:2025-09-14 07:27:40 瀏覽:278
ps2020版本怎麼調整存儲盤 發布:2025-09-14 07:20:28 瀏覽:860
奧迪a6哪個配置最保值 發布:2025-09-14 07:11:53 瀏覽:986
android查看文件 發布:2025-09-14 07:00:37 瀏覽:291
carlyle壓縮機 發布:2025-09-14 06:16:51 瀏覽:978