|  両方とも前のリビジョン 前のリビジョン 次のリビジョン |  前のリビジョン | 
| linux:commands:file_directory [2024/05/28 16:57]  – [シンボルリンクをはる[ln]]  ともやん | linux:commands:file_directory [2025/02/28 04:49] (現在)  – [ファイルのみ、ディレクトリのみに[chmod]]  ともやん | 
|---|
| ===== 文字列を含むファイルを検索[grep] ===== | ===== 文字列を含むファイルを検索[grep] ===== | 
| dhcp-range を含むファイルをルート配下のサブディレクトリすべて検索する。ただし、バイナリファイルと /proc ディレクトリは除外する。\\ | dhcp-range を含むファイルをルート配下のサブディレクトリすべて検索する。ただし、バイナリファイルと /proc ディレクトリは除外する。\\ | 
| <code>  | <WRAP color_term>  | 
| $ sudo grep -rI dhcp-range / --exclude-dir=dir  | <WRAP color_command><html><pre>  | 
| </code> | <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">grep</font> <font color="#A347BA">-rI</font> dhcp-range <u style="text-decoration-style:solid">/</u> <font color="#A347BA">--exclude-dir=dir</font>  | 
|   | </pre></html></WRAP>  | 
|   | </WRAP>  | 
|   |   | 
|   | <WRAP mincode> | 
| **-r** サブディレクトリも対象とする。\\ | **-r** サブディレクトリも対象とする。\\ | 
| **-I** バイナリファイルは除外する。\\ | **-I** バイナリファイルは除外する。\\ | 
| **--exclude-dir** 指定されたディレクトリは除外する。\\ | **--exclude-dir** 指定されたディレクトリは除外する。\\ | 
|   | </WRAP> | 
 |  | 
| ===== ファイルの圧縮/解凍[tar] ===== | ===== ファイルの圧縮/解凍[tar] ===== | 
| </code> | </code> | 
 |  | 
| ===== ファイルのみ、ディレクトリのみに[chmod] =====  | ===== ファイルのみ、ディレクトリのみに[find, xargs, chmod] =====  | 
| ファイルのみ  | 参考: [[so>questions/76331097/how-can-i-make-xargs-execute-for-all-files-found-by-find-command-in-bash-scr|linux - How can I make 'xargs' execute for all files found by 'find' command in bash script? - Stack Overflow]] [[gtr>https://stackoverflow.com/questions/76331097/how-can-i-make-xargs-execute-for-all-files-found-by-find-command-in-bash-scr|翻訳]]\\  | 
| <code>  |  [[https://www.linuxtoday.com/blog/xargs-find-commands/|How to Use the xargs and find commands | Linux Today]] [[gtr>https://www.linuxtoday.com/blog/xargs-find-commands/|翻訳]]\\  | 
| $ sudo sh -c 'find . -type f -print | xargs chmod 644'  |   | 
| </code> | ファイルのみ - ❌ダメな例💩🤪\\  | 
|   | <WRAP color_term>  | 
|   | <WRAP color_command><html><pre>  | 
|   | <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">sh</font> <font color="#A347BA">-c</font> <font color="#A2734C">'find . -type f -print | xargs chmod 644'</font>  | 
|   | </pre></html></WRAP>  | 
|   | <WRAP color_result><html><pre>  | 
|   | chmod: './lib/plugins/indexmenu/scripts/fancytree/readme/icons_layout__from' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | chmod: 'ods.png' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | chmod: './lib/plugins/indexmenu/scripts/fancytree/skin-xp/icons-rtl__old__blue' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | chmod: 'laxy' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | chmod: 'expanders.gif' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | chmod: './lib/plugins/indexmenu/scripts/fancytree/skin-xp/icons__old__blue' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | chmod: 'lazy' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | chmod: 'expanders.gif' にアクセスできません: そのようなファイルやディレクトリはありません  | 
|   | </pre></html></WRAP>  | 
|   | </WRAP>  | 
|   |   | 
|   | ファイルのみ - 🙆🏻♀️良い例🥰\\  | 
|   | <WRAP round tip 90%>  | 
|   | 空白文字を含むファイル名は問題を引き起こす可能性がある🤔\\  | 
|   | xargs と find は、空白文字ではなくヌル文字で区切る GNU 拡張機能を使用し、この問題に対処できる😉\\  | 
|   | </WRAP>  | 
|   | <WRAP color_term>  | 
|   | <WRAP color_command><html><pre>  | 
|   | <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">sh</font> <font color="#A347BA">-c</font> <font color="#A2734C">'find . -type f -print0 | xargs -0 chmod 644'</font>  | 
|   | </pre></html></WRAP>  | 
|   | </WRAP> | 
 |  | 
| ディレクトリのみ | ディレクトリのみ | 
| <code>  | <WRAP color_term>  | 
| $ sudo sh -c 'find . -type d -print | xargs chmod 755'  | <WRAP color_command><html><pre>  | 
| </code> | <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">sh</font> <font color="#A347BA">-c</font> <font color="#A2734C">'find . -type d -print0 | xargs -0 chmod 755'</font>  | 
|   | </pre></html></WRAP>  | 
|   | </WRAP> | 
 |  | 
| ===== 巨大ファイルを作成[dd] ===== | ===== 巨大ファイルを作成[dd] ===== |