1. 概述
在本教程中,我們將學(xué)習(xí)touch命令。簡(jiǎn)而言之,這個(gè)命令允許我們更新文件或目錄的最后修改時(shí)間和最后訪問(wèn)時(shí)間。
因此,我們將重點(diǎn)關(guān)注如何使用該命令及其各種選項(xiàng)。
請(qǐng)注意,我們使用 Bash 測(cè)試了此處顯示的所有命令;但是,它們應(yīng)該與任何兼容 POSIX 的 shell 一起使用。
2. 默認(rèn)行為
通過(guò)執(zhí)行touch,文件系統(tǒng)上的一個(gè)或多個(gè)文件或目錄將被更新,以便將它們的上次修改時(shí)間和上次訪問(wèn)時(shí)間設(shè)置為當(dāng)前系統(tǒng)時(shí)間。
那么,假設(shè)今天的日期是 2020 年 2 月 1 日,時(shí)間是上午 7:00。
如上所述,該命令將更新example-file.txt文件的兩個(gè)時(shí)間戳:
ls -l example-file.txt
-rw-r--r-- 1 baeldung baeldung 0 Jan 1 20:00 example-file.txt
# touch example-file.txt
# ls -l example-file.txt
-rw-r--r-- 1 baeldung baeldung 0 Feb 1 07:00 example-file.txtspan>
2.1.?創(chuàng)建新文件
此外,當(dāng)指定的文件不存在時(shí),該命令將創(chuàng)建一個(gè)空文件并相應(yīng)地設(shè)置時(shí)間:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-651146.html
ls -l sample-file.txt
ls: sample-file.txt: No such file or directory
# touch sample-file.txt
# ls -l sample-file.txt
-rw-r--r-- 1 baeldung baeldung 0 Feb 1 07:00 sample-file.txt
如果創(chuàng)建新文件,則新創(chuàng)建文件的權(quán)限將默認(rèn)為給定文件系統(tǒng)的標(biāo)準(zhǔn)權(quán)限。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-651146.html
到了這里,關(guān)于Linux touch 命令指南大全的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!