差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
| linux:commands:file_directory [2021/11/15 21:30] – ともやん | linux:commands:file_directory [2025/02/28 04:49] (現在) – [ファイルのみ、ディレクトリのみに[chmod]] ともやん | ||
|---|---|---|---|
| 行 2: | 行 2: | ||
| ===== ファイル検索[find] ===== | ===== ファイル検索[find] ===== | ||
| - | filename.txt というファイルを | + | / (ルートディレクトリ)配下の |
| - | <code> | + | <WRAP color_term> |
| - | $ find / -name filename.txt | + | <WRAP color_command>< |
| + | <font color="# | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| / | / | ||
| / | / | ||
| - | </ | + | </pre></ |
| + | </ | ||
| + | |||
| + | . (カレントディレクトリ)配下の *.orig というファイルをすべて検索する...🤔\\ | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | ./ | ||
| + | ./ | ||
| + | ./ | ||
| + | ./ | ||
| + | ./ | ||
| + | ./ | ||
| + | ./ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | それらを削除する😱\\ | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | </ | ||
| + | </ | ||
| + | ※注意: パイプで xargs に渡すだけだと、パスにスペースを含むファイルが削除できない🤪\\ | ||
| + | |||
| + | < | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | </ | ||
| + | </WRAP> | ||
| ===== 文字列を含むファイルを検索[grep] ===== | ===== 文字列を含むファイルを検索[grep] ===== | ||
| dhcp-range を含むファイルをルート配下のサブディレクトリすべて検索する。ただし、バイナリファイルと /proc ディレクトリは除外する。\\ | dhcp-range を含むファイルをルート配下のサブディレクトリすべて検索する。ただし、バイナリファイルと /proc ディレクトリは除外する。\\ | ||
| - | <code> | + | <WRAP color_term> |
| - | $ sudo grep -rI dhcp-range / --exclude-dir=dir | + | <WRAP color_command>< |
| - | </code> | + | <font color="# |
| + | </pre></ | ||
| + | </ | ||
| + | |||
| + | <WRAP mincode> | ||
| **-r** サブディレクトリも対象とする。\\ | **-r** サブディレクトリも対象とする。\\ | ||
| **-I** バイナリファイルは除外する。\\ | **-I** バイナリファイルは除外する。\\ | ||
| **--exclude-dir** 指定されたディレクトリは除外する。\\ | **--exclude-dir** 指定されたディレクトリは除外する。\\ | ||
| + | </ | ||
| + | |||
| ===== ファイルの圧縮/ | ===== ファイルの圧縮/ | ||
| - | ==== tar.gz、.tgz | + | ==== tar.xz ==== |
| - | **tar.gz、.tgz(圧縮)** | + | **tar.xz(圧縮)** |
| - | <code> | + | <WRAP color_term> |
| - | $ tar zcvf filename.tar.gz targetdir/ | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| - | **tar.gz、.tgz(解凍)** | + | </pre></ |
| - | <code> | + | </WRAP> |
| - | $ tar zxvf filename.tar.gz | + | **tar.xz(解凍)** |
| - | </code> | + | <WRAP color_term> |
| + | <WRAP color_command>< | ||
| + | <b class=GRN> | ||
| + | </ | ||
| + | </WRAP> | ||
| ==== tar.bz2 ==== | ==== tar.bz2 ==== | ||
| - | **bzip2** コマンドが必要\\ | + | **bzip2** コマンドのインストールが必要\\ |
| - | <code> | + | <WRAP color_term> |
| - | $ sudo dnf install bzip2 -y | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| + | </pre></ | ||
| + | </ | ||
| **tar.bz2(圧縮)** | **tar.bz2(圧縮)** | ||
| - | <code> | + | <WRAP color_term> |
| - | $ tar jcvf filename.tar.bz2 targetdir/ | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| + | </pre></ | ||
| + | </ | ||
| **tar.bz2(解凍)** | **tar.bz2(解凍)** | ||
| - | <code> | + | <WRAP color_term> |
| - | $ tar jxvf filename.tar.bz2 | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| + | </pre></ | ||
| + | </ | ||
| **-C** オプションで出力先ディレクトリを指定\\ | **-C** オプションで出力先ディレクトリを指定\\ | ||
| - | <code> | + | <WRAP color_term> |
| - | $ tar jxvf filename.tar.bz2 -C ~/work | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| + | </pre></ | ||
| + | </WRAP> | ||
| - | ==== tar.xz ==== | + | ==== tar.gz、.tgz |
| - | **tar.xz(圧縮)** | + | **tar.gz、.tgz(圧縮)** |
| - | <code> | + | <WRAP color_term> |
| - | $ tar Jcvf filename.tar.xz targetdir/ | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| - | **tar.xz(解凍)** | + | </pre></ |
| - | <code> | + | </WRAP> |
| - | $ tar Jxvf filename.tar.xz | + | **tar.gz、.tgz(解凍)** |
| - | </code> | + | <WRAP color_term> |
| + | <WRAP color_command>< | ||
| + | <b class=GRN> | ||
| + | </ | ||
| + | </WRAP> | ||
| ==== split (ファイルの分割) ==== | ==== split (ファイルの分割) ==== | ||
| 行 97: | 行 157: | ||
| 566a4e3f15a20b86ee1777664fcbda02df57ec6ad4a65a0340e8c9cd6c558cbe | 566a4e3f15a20b86ee1777664fcbda02df57ec6ad4a65a0340e8c9cd6c558cbe | ||
| </ | </ | ||
| + | </ | ||
| ==== 特定のディレクトリやファイルを除外 ==== | ==== 特定のディレクトリやファイルを除外 ==== | ||
| 行 192: | 行 253: | ||
| </ | </ | ||
| - | ===== ディレクトリの容量 ===== | + | ===== ディレクトリの容量 |
| + | du コマンドのヘルプ\\ | ||
| + | < | ||
| + | <panel id=" | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <span style=" | ||
| + | </ | ||
| + | <WRAP color_result_long>< | ||
| + | 使用法: du [OPTION]... [FILE]... | ||
| + | または: du [OPTION]... --files0-from=F | ||
| + | 各ファイルのデバイス使用量を集計します。ディレクトリは再帰的に処理されます。 | ||
| + | |||
| + | 長いオプションで必須となっている引数は短いオプションでも必須です。 | ||
| + | -0, --null | ||
| + | -a, --all | ||
| + | --apparent-size | ||
| + | サイズは通常小さくなるが、(スパース) ファイル内のホール、 | ||
| + | 内部フラグメンテーション、間接ブロックなどの理由で | ||
| + | 大きくなることもある。 | ||
| + | -B, --block-size=SIZE | ||
| + | | ||
| + | -b, --bytes | ||
| + | -c, --total | ||
| + | -D, --dereference-args | ||
| + | のみをたどる | ||
| + | -d, --max-depth=N | ||
| + | (--all 指定時はファイルも) 合計を表示する。 | ||
| + | --max-depth=0 は --summarize と同じ | ||
| + | --files0-from=F | ||
| + | ファイルからデバイス使用量を読み取る | ||
| + | F に - が指定された場合標準入力から読み込む | ||
| + | -H --dereference-args (-D) と同様 | ||
| + | -h, --human-readable | ||
| + | --inodes | ||
| + | -k --block-size=1K と同様 | ||
| + | -L, --dereference | ||
| + | -l, --count-links | ||
| + | -m --block-size=1M と同様 | ||
| + | -P, --no-dereference | ||
| + | -S, --separate-dirs | ||
| + | --si -h と同様だが、1024 ではなく 1000 の累乗を表示する | ||
| + | -s, --summarize | ||
| + | -t, --threshold=SIZE | ||
| + | SIZE が負の場合は SIZE より大きなエントリを無視する | ||
| + | --time | ||
| + | のファイルでの、最終更新時間を表示する | ||
| + | --time=WORD | ||
| + | 次を指定できる: | ||
| + | --time-style=STYLE | ||
| + | 次を指定できる: | ||
| + | FORMAT は & | ||
| + | -X, --exclude-from=FILE | ||
| + | --exclude=PATTERN | ||
| + | -x, --one-file-system | ||
| + | --help | ||
| + | --version | ||
| + | |||
| + | --block-size で指定した SIZE, DU_BLOCK_SIZE, | ||
| + | のうち、最初に指定されているサイズ単位で値が表示されます。それ以外の場合、デフォ | ||
| + | ルトの単位は 1024 バイトになります (POSIXLY_CORRECT が設定されている場合 512 バ | ||
| + | イト)。 | ||
| + | |||
| + | SIZE 引数は整数で、追加で単位を指定できます | ||
| + | (例えば 10M は 10*1024*1024 です)。 | ||
| + | 単位には K, M, G, T, P, E, Z, Y (1024 の累乗) や | ||
| + | KB, MB, ... (1000 の累乗) が使用できます。 | ||
| + | 二進接頭辞も使用することもできます: | ||
| + | |||
| + | GNU coreutils のオンラインヘルプ: | ||
| + | 翻訳に関するバグは & | ||
| + | 詳細な文書 & | ||
| + | (ローカルでは info & | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| dir_name の容量表示\\ | dir_name の容量表示\\ | ||
| <WRAP prewrap 100%> | <WRAP prewrap 100%> | ||
| 行 210: | 行 348: | ||
| </ | </ | ||
| </ | </ | ||
| + | |||
| + | dir_name 配下のすべてのサブディレクトリとファイル容量表示(降順, | ||
| + | ※ファイルのみの表示はできない😅\\ | ||
| + | < | ||
| + | $ du -kha dir_name/* --exclude={exclude_dir1, | ||
| + | </ | ||
| + | find コマンドならファイルのみサイズ表示できる🤤\\ | ||
| + | < | ||
| + | $ find ./dir_name -ls | sort -rh -k 7 | head -50 | ||
| + | $ find ./dir_name -printf "%s %M %n %u %g %b %TD %TR %p\n" | sort -hr | head -50 | ||
| + | </ | ||
| 容量の昇順ソート\\ | 容量の昇順ソート\\ | ||
| 行 231: | 行 380: | ||
| </ | </ | ||
| - | du コマンドのヘルプ\\ | + | [[https://kazmax.zpp.jp/cmd/d/du.1.html|du |
| - | <WRAP prewrap 100%> | + | [[http://tech.clickyourstyle.com/ |
| - | < | + | [[https://orebibou.com/ja/home/201507/ |
| - | $ du --help | + | [[https://atmarkit.itmedia.co.jp/ait/articles/ |
| - | </code> | + | [[https:// |
| - | </WRAP> | + | |
| - | <WRAP prewrap 100% # | + | |
| - | < | + | |
| - | Usage: du [OPTION]... [FILE]... | + | |
| - | or: | + | |
| - | Summarize disk usage of the set of FILEs, recursively for directories. | + | |
| - | + | ||
| - | Mandatory arguments to long options are mandatory for short options too. | + | |
| - | -0, --null | + | |
| - | -a, --all write counts for all files, not just directories | + | |
| - | --apparent-size | + | |
| - | the apparent size is usually smaller, it may be | + | |
| - | larger due to holes in (' | + | |
| - | fragmentation, | + | |
| - | -B, --block-size=SIZE | + | |
| - | ' | + | |
| - | see SIZE format below | + | |
| - | -b, --bytes | + | |
| - | -c, --total | + | |
| - | -D, --dereference-args | + | |
| - | command line | + | |
| - | -d, --max-depth=N | + | |
| - | only if it is N or fewer levels below the command | + | |
| - | line argument; | + | |
| - | --summarize | + | |
| - | --files0-from=F | + | |
| - | NUL-terminated file names specified in file F; | + | |
| - | if F is -, then read names from standard input | + | |
| - | -H equivalent to --dereference-args (-D) | + | |
| - | -h, --human-readable | + | |
| - | | + | |
| - | -k like --block-size=1K | + | |
| - | -L, --dereference | + | |
| - | -l, --count-links | + | |
| - | -m like --block-size=1M | + | |
| - | -P, --no-dereference | + | |
| - | | + | |
| - | | + | |
| - | -s, --summarize | + | |
| - | -t, --threshold=SIZE | + | |
| - | or entries greater than SIZE if negative | + | |
| - | --time | + | |
| - | directory, or any of its subdirectories | + | |
| - | --time=WORD | + | |
| - | atime, access, use, ctime or status | + | |
| - | --time-style=STYLE | + | |
| - | full-iso, long-iso, iso, or +FORMAT; | + | |
| - | FORMAT is interpreted like in ' | + | |
| - | -X, --exclude-from=FILE | + | |
| - | --exclude=PATTERN | + | |
| - | -x, --one-file-system | + | |
| - | --help | + | |
| - | --version | + | |
| - | + | ||
| - | Display values are in units of the first available SIZE from --block-size, | + | |
| - | and the DU_BLOCK_SIZE, | + | |
| - | Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). | + | |
| - | + | ||
| - | The SIZE argument is an integer and optional unit (example: 10K is 10*1024). | + | |
| - | Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). | + | |
| - | Binary prefixes can be used, too: KiB=K, MiB=M, and so on. | + | |
| - | + | ||
| - | GNU coreutils online help: <https://www.gnu.org/software/coreutils/> | + | |
| - | Report any translation bugs to <https://translationproject.org/team/> | + | |
| - | Full documentation <https:// | + | |
| - | or available locally via: info ' | + | |
| - | </ | + | |
| - | </ | + | |
| - | ===== シンボルリンクをはる[ln] ===== | + | ===== シンボルリンクを張る[ln] ===== |
| < | < | ||
| $ ln -s [src] [dist] | $ ln -s [src] [dist] | ||
| 行 358: | 行 439: | ||
| </ | </ | ||
| - | ===== ファイルのみ、ディレクトリのみに[chmod] ===== | + | ===== ファイルのみ、ディレクトリのみに[find, xargs, |
| - | ファイルのみ | + | 参考: [[so> |
| - | <code> | + | [[https:// |
| - | $ sudo sh -c 'find . -type f -print | xargs chmod 644' | + | |
| - | </code> | + | ファイルのみ |
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | chmod: & | ||
| + | chmod: & | ||
| + | chmod: & | ||
| + | chmod: & | ||
| + | chmod: & | ||
| + | chmod: & | ||
| + | chmod: & | ||
| + | chmod: & | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ファイルのみ - 🙆🏻♀️良い例🥰\\ | ||
| + | <WRAP round tip 90%> | ||
| + | 空白文字を含むファイル名は問題を引き起こす可能性がある🤔\\ | ||
| + | xargs と find は、空白文字ではなくヌル文字で区切る GNU 拡張機能を使用し、この問題に対処できる😉\\ | ||
| + | </ | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | </ | ||
| + | </WRAP> | ||
| ディレクトリのみ | ディレクトリのみ | ||
| - | <code> | + | <WRAP color_term> |
| - | $ sudo sh -c 'find . -type d -print | xargs chmod 755' | + | <WRAP color_command>< |
| - | </code> | + | <font color="# |
| + | </ | ||
| + | </WRAP> | ||
| ===== 巨大ファイルを作成[dd] ===== | ===== 巨大ファイルを作成[dd] ===== | ||
| 行 387: | 行 496: | ||
| ===== 参考文献 ===== | ===== 参考文献 ===== | ||
| [[http:// | [[http:// | ||
| + | [[so> | ||