linux:commands:file_directory

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
linux:commands:file_directory [2021/06/09 16:46] – [split (ファイルの分割)] ともやんlinux:commands:file_directory [2024/04/15 05:35] (現在) – [ファイル検索[find]] ともやん
行 2: 行 2:
  
 ===== ファイル検索[find] ===== ===== ファイル検索[find] =====
-filename.txt というファイルを / (ルートディレクトリ)配下のすべてのファイルから検索する +/ (ルートディレクトリ)配下の filename.txt というファイルをすべて検索する...🤔\\ 
-<code+<WRAP color_term
-$ find / -name filename.txt+<WRAP color_command><html><pre> 
 +<font color="#FF8700"><b>$</b></font> <font color="#26A269">find</font> <u style="text-decoration-style:single">/</u> <font color="#A347BA">-name</font> filename.txt 
 +</pre></html></WRAP> 
 +<WRAP color_result><html><pre>
 /home/tomoyan/filename.txt /home/tomoyan/filename.txt
 /home/tomoyan/Documents/filename.txt /home/tomoyan/Documents/filename.txt
-</code>+</pre></html></WRAP> 
 +</WRAP> 
 + 
 +. (カレントディレクトリ)配下の *.orig というファイルをすべて検索する...🤔\\ 
 +<WRAP color_term> 
 +<WRAP color_command><html><pre> 
 +<font color="#FF8700"><b>$</b></font> <font color="#26A269">find</font> <u style="text-decoration-style:single">.</u> <font color="#A347BA">-name</font> <font color="#12488B"><b>*</b></font>.orig <font color="#A347BA">-type</font>
 +</pre></html></WRAP> 
 +<WRAP color_result><html><pre> 
 +./kernel_b/nvidia-drm/nvidia-drm-drv.c.orig 
 +./kernel_b/nvidia/nv-acpi.c.orig 
 +./kernel_b/conftest.sh.orig 
 +./kernel/nvidia/nv-acpi.c.orig 
 +./kernel/nvidia-drm/nvidia-drm-drv.c.orig 
 +./kernel/Kbuild.orig 
 +./kernel/conftest.sh.orig 
 +</pre></html></WRAP> 
 +</WRAP> 
 + 
 +それらを削除する😱\\ 
 +<WRAP color_term> 
 +<WRAP color_command><html><pre> 
 +<font color="#FF8700"><b>$</b></font> <font color="#26A269">find</font> <u style="text-decoration-style:single">.</u> <font color="#A347BA">-name</font> <font color="#12488B"><b>*</b></font>.orig <font color="#A347BA">-type</font> f <font color="#12488B"><b>|</b></font> <font color="#26A269">xargs</font> rm <font color="#A347BA">-rf</font> 
 +</pre></html></WRAP> 
 +</WRAP>
  
 ===== 文字列を含むファイルを検索[grep] ===== ===== 文字列を含むファイルを検索[grep] =====
行 17: 行 44:
 **-I** バイナリファイルは除外する。\\ **-I** バイナリファイルは除外する。\\
 **--exclude-dir** 指定されたディレクトリは除外する。\\ **--exclude-dir** 指定されたディレクトリは除外する。\\
 +
 ===== ファイルの圧縮/解凍[tar] ===== ===== ファイルの圧縮/解凍[tar] =====
  
-==== tar.gz、.tgz ==== +==== tar.xz ==== 
-**tar.gz、.tgz(圧縮)** +**tar.xz(圧縮)** 
-<code+<WRAP color_term
-$ tar zcvf filename.tar.gz targetdir/ +<WRAP color_command><html><pre> 
-</code+<b class=GRN>$</b> <b class=HIY>tar</b> Jcvf filename.tar.xz targetdir/ 
-**tar.gz、.tgz(解凍)** +</pre></html></WRAP> 
-<code+</WRAP
-$ tar zxvf filename.tar.gz +**tar.xz(解凍)** 
-</code>+<WRAP color_term
 +<WRAP color_command><html><pre> 
 +<b class=GRN>$</b> <b class=HIY>tar</b> Jxvf filename.tar.xz 
 +</pre></html></WRAP> 
 +</WRAP>
  
 ==== tar.bz2 ==== ==== tar.bz2 ====
-**bzip2** コマンドが必要\\ +**bzip2** コマンドのインストールが必要\\ 
-<code+<WRAP color_term
-$ sudo dnf install bzip2 -y +<WRAP color_command><html><pre> 
-</code>+<b class=GRN>$</b> <b class=HIY>sudo</b> dnf install bzip2 <b class=HIK>-y</b> 
 +</pre></html></WRAP> 
 +</WRAP> 
 **tar.bz2(圧縮)** **tar.bz2(圧縮)**
-<code+<WRAP color_term
-$ tar jcvf filename.tar.bz2 targetdir/ +<WRAP color_command><html><pre> 
-</code>+<b class=GRN>$</b> <b class=HIY>tar</b> jcvf filename.tar.bz2 targetdir/ 
 +</pre></html></WRAP> 
 +</WRAP> 
 **tar.bz2(解凍)** **tar.bz2(解凍)**
-<code+<WRAP color_term
-$ tar jxvf filename.tar.bz2 +<WRAP color_command><html><pre> 
-</code>+<b class=GRN>$</b> <b class=HIY>tar</b> jxvf filename.tar.bz2 
 +</pre></html></WRAP> 
 +</WRAP> 
 **-C** オプションで出力先ディレクトリを指定\\ **-C** オプションで出力先ディレクトリを指定\\
-<code+<WRAP color_term
-$ tar jxvf filename.tar.bz2 -C ~/work +<WRAP color_command><html><pre> 
-</code>+<b class=GRN>$</b> <b class=HIY>tar</b> jxvf filename.tar.bz2 <b class=HIK>-C</b> ~/work 
 +</pre></html></WRAP> 
 +</WRAP>
  
-==== tar.xz ==== +==== tar.gz、.tgz ==== 
-**tar.xz(圧縮)** +**tar.gz、.tgz(圧縮)** 
-<code+<WRAP color_term
-$ tar Jcvf filename.tar.xz targetdir/ +<WRAP color_command><html><pre> 
-</code+<b class=GRN>$</b> <b class=HIY>tar</b> zcvf filename.tar.gz targetdir/ 
-**tar.xz(解凍)** +</pre></html></WRAP> 
-<code+</WRAP
-$ tar Jxvf filename.tar.xz +**tar.gz、.tgz(解凍)** 
-</code>+<WRAP color_term
 +<WRAP color_command><html><pre> 
 +<b class=GRN>$</b> <b class=HIY>tar</b> zxvf filename.tar.gz 
 +</pre></html></WRAP> 
 +</WRAP>
  
 ==== split (ファイルの分割) ==== ==== split (ファイルの分割) ====
行 97: 行 144:
 566a4e3f15a20b86ee1777664fcbda02df57ec6ad4a65a0340e8c9cd6c558cbe  filename-1.tar.bz2 566a4e3f15a20b86ee1777664fcbda02df57ec6ad4a65a0340e8c9cd6c558cbe  filename-1.tar.bz2
 </code> </code>
 +</WRAP>
  
 ==== 特定のディレクトリやファイルを除外 ==== ==== 特定のディレクトリやファイルを除外 ====
行 192: 行 240:
 </code> </code>
  
-===== ディレクトリの容量 =====+===== ディレクトリの容量 [du] ===== 
 +du コマンドのヘルプ\\ 
 +<accordion id="du_help" collapsed="false"> 
 +<panel id="du_help_panel" type="default" title="+ ヘルプ [--help]"> 
 +<WRAP color_term> 
 +<WRAP color_command><html><pre> 
 +<span style="color:#FF8700"><b>$</b></span> <span style="color:#26A269">du</span> <span style="color:#A347BA">--help</span> 
 +</pre></html></WRAP> 
 +<WRAP color_result_long><html><pre> 
 +使用法: du [OPTION]... [FILE]... 
 +または: du [OPTION]... --files0-from=F 
 +各ファイルのデバイス使用量を集計します。ディレクトリは再帰的に処理されます。 
 + 
 +長いオプションで必須となっている引数は短いオプションでも必須です。 
 +  -0, --null            出力行の区切りとして改行文字ではなく NUL を使用する 
 +  -a, --all             ディレクトリだけでなく、全てのファイルについて表示する 
 +      --apparent-size   デバイス使用量ではなく実際のサイズを表示する。実際の 
 +                          サイズは通常小さくなるが、(スパース) ファイル内のホール、 
 +                          内部フラグメンテーション、間接ブロックなどの理由で 
 +                          大きくなることもある。 
 +  -B, --block-size=SIZE  SIZE の倍数として表示する。例: &apos;-BM&apos; は 
 +                           1,048,576 バイト単位でサイズを表示する 
 +  -b, --bytes           &apos;--apparent-size --block-size=1&apos; と同じ 
 +  -c, --total           総合計量を表示する 
 +  -D, --dereference-args  コマンドラインで指定されたシンボリック 
 +                          のみをたどる 
 +  -d, --max-depth=N     コマンド実行場所から N 階層以内のディレクトリの 
 +                          (--all 指定時はファイルも) 合計を表示する。 
 +                          --max-depth=0 は --summarize と同じ 
 +      --files0-from=F   ファイル F で指定された NUL で区切られた名前の 
 +                          ファイルからデバイス使用量を読み取る 
 +                          F に - が指定された場合標準入力から読み込む 
 +  -H                    --dereference-args (-D) と同様 
 +  -h, --human-readable  人間が読みやすい形式でサイズを表示する (例: 1K 234M 2G) 
 +      --inodes          ブロック使用量ではなく inode 使用量を表示する 
 +  -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 より小さいエントリを無視する。 
 +                          SIZE が負の場合は SIZE より大きなエントリを無視する 
 +      --time           ディレクトリとその子ディレクトリに含まれる全て 
 +                          のファイルでの、最終更新時間を表示する 
 +      --time=WORD       更新時間の代わりに WORD の時間を表示する。WORD には 
 +                          次を指定できる: atime, access, use, ctime, status 
 +      --time-style=STYLE  時間を STYLE の形式で表示する。STYLE には 
 +                          次を指定できる: full-iso, long-iso, iso, +FORMAT 
 +                          FORMAT は &apos;date&apos; と同様に解釈される 
 +  -X, --exclude-from=FILE  FILE 内のいずれかのパターンに一致するファイルを除外する 
 +      --exclude=PATTERN    PATTERN に一致するファイルを除外する 
 +  -x, --one-file-system    異なるファイルシステム上のディレクトリはスキップする 
 +      --help        display this help and exit 
 +      --version     output version information and exit 
 + 
 +--block-size で指定した SIZE, DU_BLOCK_SIZE, BLOCK_SIZE およびBLOCKSIZE 環境変数 
 +のうち、最初に指定されているサイズ単位で値が表示されます。それ以外の場合、デフォ 
 +ルトの単位は 1024 バイトになります (POSIXLY_CORRECT が設定されている場合 512 バ 
 +イト)。 
 + 
 +SIZE 引数は整数で、追加で単位を指定できます 
 +(例えば 10M は 10*1024*1024 です)。 
 +単位には K, M, G, T, P, E, Z, Y (1024 の累乗) や 
 +KB, MB, ... (1000 の累乗) が使用できます。 
 +二進接頭辞も使用することもできます: KiB=K, MiB=M など。 
 + 
 +GNU coreutils のオンラインヘルプ: &lt;https://www.gnu.org/software/coreutils/&gt; 
 +翻訳に関するバグは &lt;https://translationproject.org/team/ja.html&gt; に連絡してください。 
 +詳細な文書 &lt;https://www.gnu.org/software/coreutils/du&gt; 
 +(ローカルでは info &apos;(coreutils) du invocation&apos; で参照可能)。 
 +</pre></html></WRAP> 
 +</WRAP> 
 +</panel> 
 +</accordion> 
 + 
 +dir_name の容量表示\\
 <WRAP prewrap 100%> <WRAP prewrap 100%>
 <code> <code>
行 200: 行 326:
 </WRAP> </WRAP>
  
-du コマンドヘルプ\\+dir_name 配下サブディレクトリ毎の容量表示\\
 <WRAP prewrap 100%> <WRAP prewrap 100%>
 <code> <code>
-$ du --help+$ du --s dir_name/
 +1.6G    dir1 
 +0.2G    dir2 
 +0.3G    dir3
 </code> </code>
 </WRAP> </WRAP>
-<WRAP prewrap 100% #result_long>+ 
 +dir_name 配下のすべてのサブディレクトリとファイル容量表示(降順, 上位50件)\\ 
 +※ファイルのみの表示はできない😅\\
 <code> <code>
-Usage: du [OPTION]... [FILE]... +du -kha dir_name/* --exclude={exclude_dir1,exclude_dir2,exclude_dir3} | sort -rn | head -50 
-  or:  du [OPTION]... --files0-from=F +</code> 
-Summarize disk usage of the set of FILEs, recursively for directories.+find コマンドならファイルのみサイズ表示できる🤤\\ 
 +<code> 
 +$ 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 
 +</code>
  
-Mandatory arguments to long options are mandatory for short options too. +容量の昇順ソート\\ 
-  -0, --null            end each output line with NUL, not newline +<WRAP prewrap 100%> 
-  -a, --all             write counts for all files, not just directories +<code> 
-      --apparent-size   print apparent sizes, rather than disk usage; although +$ du --s dir_name/* | sort -h 
-                          the apparent size is usually smaller, it may be +0.2G    dir2 
-                          larger due to holes in ('sparse') files, internal +0.3G    dir3 
-                          fragmentation, indirect blocks, and the like +1.6G    dir1 
-  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g., +</code> 
-                           '-BM' prints sizes in units of 1,048,576 bytes; +</WRAP>
-                           see SIZE format below +
-  -b, --bytes           equivalent to '--apparent-size --block-size=1' +
-  -c, --total           produce a grand total +
-  -D, --dereference-args  dereference only symlinks that are listed on the +
-                          command line +
-  -d, --max-depth=N     print the total for a directory (or file, with --all) +
-                          only if it is N or fewer levels below the command +
-                          line argument;  --max-depth=is the same as +
-                          --summarize +
-      --files0-from=F   summarize disk usage of the +
-                          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  print sizes in human readable format (e.g., 1K 234M 2G) +
-      --inodes          list inode usage information instead of block usage +
-  -k                    like --block-size=1K +
-  -L, --dereference     dereference all symbolic links +
-  -l, --count-links     count sizes many times if hard linked +
-  -m                    like --block-size=1M +
-  -P, --no-dereference  don't follow any symbolic links (this is the default) +
-  -S, --separate-dirs   for directories do not include size of subdirectories +
-      --si              like -h, but use powers of 1000 not 1024 +
-  -s, --summarize       display only a total for each argument +
-  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive, +
-                          or entries greater than SIZE if negative +
-      --time            show time of the last modification of any file in the +
-                          directory, or any of its subdirectories +
-      --time=WORD       show time as WORD instead of modification time: +
-                          atime, access, use, ctime or status +
-      --time-style=STYLE  show times using STYLE, which can be: +
-                            full-iso, long-iso, iso, or +FORMAT; +
-                            FORMAT is interpreted like in 'date' +
-  -X, --exclude-from=FILE  exclude files that match any pattern in FILE +
-      --exclude=PATTERN    exclude files that match PATTERN +
-  -x, --one-file-system    skip directories on different file systems +
-      --help     display this help and exit +
-      --version  output version information and exit+
  
-Display values are in units of the first available SIZE from --block-size, +容量の降順ソート\\ 
-and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. +<WRAP prewrap 100%
-Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). +<code
- +$ du -h -s dir_name/* | sort -hr 
-The SIZE argument is an integer and optional unit (example: 10K is 10*1024). +1.6G    dir1 
-Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). +0.3G    dir3 
-Binary prefixes can be used, too: KiB=K, MiB=M, and so on. +0.2G    dir2
- +
-GNU coreutils online help: <https://www.gnu.org/software/coreutils/+
-Report any translation bugs to <https://translationproject.org/team/+
-Full documentation <https://www.gnu.org/software/coreutils/du> +
-or available locally via: info '(coreutils) du invocation'+
 </code> </code>
 </WRAP> </WRAP>
 +
 +[[https://kazmax.zpp.jp/cmd/d/du.1.html|du - コマンド (プログラム) の説明 - Linux コマンド集 一覧表]]\\
 +[[http://tech.clickyourstyle.com/articles/260|ファイズの大きいファイルを特定する:du, find, sort:Technical tips:Media hub]]\\
 +[[https://orebibou.com/ja/home/201507/20150721_001/|duコマンドで覚えておきたい使い方8個 | 俺的備忘録 〜なんかいろいろ〜]]\\
 +[[https://atmarkit.itmedia.co.jp/ait/articles/1607/20/news024.html|【 find 】コマンド(応用編その2)――検索したファイルを指定したフォーマットで表示する]]\\
 +[[https://www.rough-and-cheap.jp/linux/find_result_formatting/|findした結果を指定したフォーマットで表示したい | 雑廉堂の雑記帳]]\\
  
 ===== シンボルリンクをはる[ln] ===== ===== シンボルリンクをはる[ln] =====
  • linux/commands/file_directory.1623224763.txt.gz
  • 最終更新: 2021/06/09 16:46
  • by ともやん