當前位置:首頁 » 操作系統 » 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 提供相同機制,但是可以刪除檔案或是空目錄。

熱點內容
取隨機數php 發布:2025-07-12 12:58:16 瀏覽:840
如何配置組合音響 發布:2025-07-12 12:53:54 瀏覽:93
c語言冪計算 發布:2025-07-12 12:52:36 瀏覽:566
兔費WLAN密碼多少 發布:2025-07-12 12:50:59 瀏覽:861
阿里雲分布式存儲 發布:2025-07-12 12:45:04 瀏覽:535
sql日誌壓縮 發布:2025-07-12 12:39:53 瀏覽:343
紅點角標演算法 發布:2025-07-12 12:11:16 瀏覽:844
開心消消樂伺服器繁忙什麼情況 發布:2025-07-12 12:11:14 瀏覽:239
資料庫的封鎖協議 發布:2025-07-12 12:10:35 瀏覽:725
如何配置一台長久耐用的電腦 發布:2025-07-12 11:43:03 瀏覽:602