`

command line tools for linux

 
阅读更多
du -sh `ls .`

for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11
dir | gvim -



#output to vim 
#the - option tells vim to open stdin
dir | gvim -
#inside vim
:r !<cmd>
:r !dir



df -k .

Show size of current directory in
du -sh `ls .`
du -h | tail -n 1
du -h | grep -v '/' | awk '{print $1}'
ls | wc -l
ls -l | grep ^- | wc -l
ls -l | grep ^d | wc -l
ls -l | grep ^l | wc -l
for t in files links directories; do echo `find . -type ${t:0:1} | wc -l` $t; done 2> /dev/null

du -a | cut -d/ -f2 | sort | uniq -c | sort -nr
find . -type f | wc -l
ind . -type d | wc -l
find . -maxdepth 1 -type d | wc -l






df -h | grep /dev/hda1 | cut -c 41-43
du -ch | grep total











How to find - Size of a directory & Free disk space

This article explains 2 simple commands that most people want to know when they start using Linux. They are finding the size of a directory and finding the amount of free disk space that exists on your machine. The command you would use to find the directory size is ' du '. And to find the free disk space you could use ' df '.

All the information present in this article is available in the man pages for du and df. In case you get bored reading the man pages and you want to get your work done quickly, then this article is for you.

-

'du' - Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.


$ du /home/david
The above command would give you the directory size of the directory /home/david


$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.


$ du -ah
This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.


$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

30M .
30M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.


$ du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.

Note : In case you are not familiar with pipes (which makes the above command possible) refer to Article No. 24 . Also grep is one of the most important commands in Unix. Refer to Article No. 25 to know more about grep.


$ du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.


$ du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.


$ du --exculde=mp3
The above command would display the size of the current directory along with all its subdirectories, but it would exclude all the files having the given pattern present in their filenames. Thus in the above case if there happens to be any mp3 files within the current directory or any of its subdirectories, their size would not be included while calculating the total directory size.

-

'df' - finding the disk free space / disk usage

$ df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.


$ df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.

Most of the users don't use the other parameters that can be passed to 'df'. So I shall not be discussing them.

I shall in turn show you an example that I use on my machine. I have actually stored this as a script named 'usage' since I use it often.

Example :

I have my Linux installed on /dev/hda1 and I have mounted my Windows partitions as well (by default every time Linux boots). So 'df' by default shows me the disk usage of my Linux as well as Windows partitions. And I am only interested in the disk usage of the Linux partitions. This is what I use :

$ df -h | grep /dev/hda1 | cut -c 41-43

This command displays the following on my machine

45%

Basically this command makes 'df' display the disk usages of all the partitions and then extracts the lines with /dev/hda1 since I am only interested in that. Then it cuts the characters from the 41st to the 43rd column since they are the columns that display the usage in % , which is what I want.

Note : In case you are not familiar with pipes (which is used in the above command) then refer to Article No. 24 . 'cut' is another tool available in Unix. The above usage of cut gets the the characters that are present in the specified columns. If you are interested in knowing how to mount you Windows partitions under Linux, please refer to Article No. 3 .

There are a few more options that can be used with 'du' and 'df' . You could find them in the man pages.
分享到:
评论

相关推荐

    Android 命令行工具(commandlinetools-linux-11076708-latest.zip)

    Android 命令行工具(commandlinetools-linux-11076708_latest.zip)适用于Linux系统。 如果不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android ...

    Android 命令行工具(commandlinetools-linux-8092744_latest.zip)

    Android 命令行工具(commandlinetools-linux-8092744_latest.zip)适用于Linux系统。 如果不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android ...

    Android(commandlinetools-linux-8512546_latest.zip)

    Android 命令行工具(commandlinetools-linux-8512546_latest.zip)适用于Linux系统。 如果不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android ...

    Android命令行工具Command line tools-linux-7302050

    If you do not need Android Studio, you can download the basic Android command line tools below. You can use the included sdkmanager to download other SDK packages. These tools are included in Android...

    commandlinetools-linux-7583922_latest.zip

    标题中的"commandlinetools-linux-7583922_latest.zip"指的是Android的命令行工具包,这是Google提供的一套用于管理Android SDK的工具集合。这些工具允许开发者在命令行界面执行各种任务,包括但不限于安装、更新、...

    HarmonyOS(commandline-tools-linux-2.0.0.2.zip)

    在给定的压缩包"HarmonyOS(commandline-tools-linux-2.0.0.2.zip)"中,包含的是HarmonyOS的命令行工具,主要用于开发者在Linux环境下对系统进行构建、编译、调试等操作。这些工具是开发和维护HarmonyOS应用程序不...

    commandline-tools-linux-x64-5.0.3.900.zip.003

    Command Line Tools(commandline-tools-linux-x64-5.0.3.900.zip)适用于Linux系统,集合了HarmonyOS应用开发所用到的系列工具,包括代码检查codelinter、三方库包管理ohpm、命令行解析hstack、编译构建hvigorw。...

    commandlinetools-linux-10406996-latest.zip

    Android 命令行工具(commandlinetools-linux-10406996_latest.zip)适用于Linux系统。 如果不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android ...

    commandlinetools-linux-9477386-latest.zip

    Android 命令行工具(commandlinetools-linux-9477386_latest.zip)适用于Linux系统。 如果不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android ...

    HUAWEI DevEco Studio (commandlinetools-linux-tool-1.0.0.400.zip)

    HUAWEI DevEco Studio (Command Line Tools)适用于Linux系统 ,Command Line Tools是一系列开发工具的集合,可通过其中的sdkmgr工具查看、安装/更新和卸载多个HarmonyOS SDK包。支持通过自动化构建脚本调用。

    commandlinetools-win-6609375_latest.zip

    标题中的"commandlinetools-win-6609375_latest.zip"表明这是一个针对Windows平台的Android SDK命令行工具的压缩包,版本号为6609375的最新版。这些工具是Android开发者必备的,它们允许开发者在没有图形用户界面的...

    Android 命令行工具(commandlinetools-win-11076708-latest.zip)

    Android 命令行工具(commandlinetools-win-11076708_latest.zip)适用于Windows系统。 如果不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android ...

    Android命令行工具Command line tools-mac-7302050_latest.zip

    If you do not need Android Studio, you can download the basic Android command line tools below. You can use the included sdkmanager to download other SDK packages. These tools are included in Android...

    Android 命令行工具commandlinetools-linux-7583922_latest.zip

    如果您不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android Studio 中。Android 命令行工具适用于Linux系统。

    Cesium Command Line Tools - 有损/无损图像压缩工具_c语言_代码_下载

    命令行参数 -q, --quality [value]{必需} 设置图像的质量。值越高,结果越好。请注意,值为 0 表示 无损压缩,不会修改原始图像,但会压缩较少。允许的范围是 [0。100]。 有损压缩的常见值为 80。...

    commandlinetools-linux-9123335-latest.zip

    Android 命令行工具(commandlinetools-linux-9123335-latest.zip)适用于Linux系统。如果不需要 Android Studio,可以下载 Android 命令行工具。可以使用包含sdkmanager的下载其他 SDK 包。该工具包含在 Android ...

    linux_command_tools

    标题“Linux Command Tools”指的是一个特别设计的工具,它允许用户在Windows操作系统环境下直接执行Linux命令,无需安装完整的Linux发行版。这个工具对于那些经常在Windows和Linux系统间切换的用户来说非常方便,...

    commandlinetools-win-7583922_latest.zip

    标题中的"commandlinetools-win-7583922_latest.zip"表明这是一个针对Windows平台的Android命令行工具包的最新版本。这个压缩包包含了用于Android开发和管理的一系列命令行工具,由谷歌官方提供,是Android SDK的一...

    Linux_command_line, Linux命令和 shell 脚本简介.zip

    Linux_command_line, Linux命令和 shell 脚本简介 LinuxLinux命令和 shell 脚本简介为更完整的资源列表,包括初学者的教程, Linux Linux curated资源列表有关资源的更多信息,请访问脚本教程。 Linux介绍插件什么是...

Global site tag (gtag.js) - Google Analytics