Linux でファイルとディレクトリのサイズを確認するにはどうすればよいですか? を使用するとdf -m
、最上位レベルのすべてのディレクトリのサイズが表示されますが、ディレクトリ内のディレクトリとファイルのサイズを確認するにはどうすればよいでしょうか?
ベストアンサー1
ls
ファイルにはコマンドを使用し、du
ディレクトリにはコマンドを使用します。
ファイルサイズの確認
ls -l filename #Displays Size of the specified file
ls -l * #Displays Size of All the files in the current directory
ls -al * #Displays Size of All the files including hidden files in the current directory
ls -al dir/ #Displays Size of All the files including hidden files in the 'dir' directory
ls
コマンドはディレクトリの実際のサイズをリストしません(なぜ?)。したがって、du
この目的には を使用します。
ディレクトリサイズの確認
du -sh directory_name #Gives you the summarized(-s) size of the directory in human readable(-h) format
du -bsh * #Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format
上記のコマンドのいずれかにオプションを含めると-h
(例:ls -lh *
またはdu -sh
)、サイズが人間が読める形式で表示されます ( kb
、mb
、gb
、...)
詳細については、以下man ls
を参照してください。man du