Skip to content

File system command

下面是维基百科总结的 Unix command-line interface programs and shell builtins 中**File system** commands(链接: https://en.wikipedia.org/wiki/Df_(Unix) ):

command 简介
cat
chmod
chown
chgrp
cksum
cmp
cp
dd
du
df
file
fuser
ln
ls
mkdir
mv
pax
pwd
rm
rmdir
split
tee
touch
type
umask

du

du(1) - Linux man page

Summarize disk usage of each FILE, recursively for directories.

NOTE: 对象是file

Example: 查看文件夹大小-并按大小进行排序

cnblogs du-查看文件夹大小-并按大小进行排序 :

* 可以将当前目录下所有文件的大小给列出来。那要将这些列出来的文件按照从大到小的方式排序呢?

jack@jiaobuchong:~$ du -sh * | sort -nr 
833M    installed-software 
452K    Documents 
284K    learngit 
170M    Desktop 
161M    Downloads 
112K    session 

NOTE: 可以看出,上述排序是错误的,因为它没有考虑 单位

找sort 来帮个忙就可以了。呵呵!这个排序不正常哦,都是因为-h参数的原因:

jack@jiaobuchong:~$ du -s * | sort -nr  
852756  installed-software 
173868  Desktop 
164768  Downloads 
4724    Pictures 
3236    program_pratice 

NOTE: 排序支持,相当于统一了量纲

du -s * | sort -nr | head 选出排在前面的10个,

du -s * | sort -nr | tail 选出排在后面的10个。

Example: Finding largest file

cyberciti Finding largest file recursively on Linux bash shell using find :

One can only list files and skip the directories with the find command instead of using the du command, sort command and NA command combination:

$ sudo find / -type f -printf "%s\t%p\n" | sort -n | tail -1
$ find $HOME -type f -printf '%s %p\n' | sort -nr | head -10

How do I get the size of a directory on the command line?

A1

du -sh file_path

df

df(1) - Linux man page

df - report file system disk space usage

NOTE: 对象是disk