Useful Commands/File Processing: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
(Created page with "{| class="wikitable" ! 情境 || 指令 |- | 目錄與檔案權限分別設為 755 和 644 | <source lang="bash"> find . -type d -exec chmod 755 {} +\ find . -type f -exec chm...")
(No difference)

Revision as of 03:53, 14 August 2018

情境 指令
目錄與檔案權限分別設為 755 和 644
find . -type d -exec chmod 755 {} +\
find . -type f -exec chmod 644 {} +
大量改檔名 *.js 改名 *.html
rename 's/js$/html/' *.js
大量改檔名 *.pdf (原理為 sed)
rename 's/搜尋樣式/取代字串/' *.pdf
搜尋文字檔,複製到另一個目錄
find . -name *.txt -exec cp {} 目的目錄 \;
從所在目錄遞迴掃檔案找 'string'
grep -rn --color -C 2 'string' .
移除 7 天前的 log
find . -name '*.log' -mtime 7 -exec rm -f {} \;
移除超過 7 天的 log
find . -name '*.log' -mtime +7 -exec rm -f {} \;
移除 7 天前到現在的 log
find . -name '*.log' -mtime -7 -exec rm -f {} \;
用 regex 找檔案
find . -regex '.*[0-9]\{4\}.txt'
取檔名中數字的部分
ls file-0001.txt | sed 's/file-\([0-9]\{4\}\).txt/\1/'