特定のフォルダにあるファイルとディレクトリのサイズを取得するLinuxコマンド? [closed] 質問する

特定のフォルダにあるファイルとディレクトリのサイズを取得するLinuxコマンド? [closed] 質問する

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)、サイズが人間が読める形式で表示されます ( kbmbgb、...)

詳細については、以下man lsを参照してください。man du

おすすめ記事