df

磁盘分区使用情况

  1. df -h


du

mac:
image.png
centOS:
image.png

显示某个文件的大小:

  1. du -h <file>

显示某个目录的大小:

  1. du -h -d 0 <directory>
  2. 等价于
  3. du -sh <directory>

显示某个目录下所有文件/子目录的大小的列表:

  1. du -hc -d 0 <directory>/*

显示某个目录下所有子目录的大小的列表:

  1. du -hc -d 1 <directory>

递归显示某个目录下所有子目录的大小:

  1. du -ah <directory>

ls

Linux “ls -l”文件列表权限详解

  1. drwxr-x--- 2 root adm 4096 2013-08-07 11:03 apache2
  2. drwxr-xr-x 2 root root 4096 2013-08-07 09:43 apparmor
  3. drwxr-xr-x 2 root root 4096 2013-08-07 09:44 apt
  4. -rw-r----- 1 syslog adm 16802 2013-08-07 14:30 auth.log
  5. -rw-r--r-- 1 root root 642 2013-08-07 11:03 boot.log
  6. drwxr-xr-x 2 root root 4096 2013-08-06 18:34 ConsoleKit
  7. drwxr-xr-x 2 root root 4096 2013-08-07 09:44 cups
  8. -rw-r----- 1 syslog adm 10824 2013-08-07 11:08 daemon.log
  9. drwxr-xr-x 2 root root 4096 2013-08-07 09:45 dbconfig-common
  10. -rw-r----- 1 syslog adm 21582 2013-08-07 11:03 debug
  11. drwxr-xr-x 2 root root 4096 2013-08-07 09:45 dist-upgrade
  12. -rw-r--r-- 1 root adm 59891 2013-08-07 11:03 dmesg
  13. 第一列 drwxr-x---” 表示文件的类型 和文件权限
  14. 第二列: 2”是纯数字 ,表示文件链接个数
  15. 第三列 root 表示文件的所有者
  16. 第四列:“adm 表示为文件的所在群组
  17. 第五列:“4096”,表示为文件长度(大小)
  18. 第六列:“2013-08-07 11:03”,表示文件最后更新(修改)时间
  19. 第七列:“apache2 表示文件的名称

文件类型:
d :目录
- :文件
l :链接
s :socket
p :named pipe
b :block device
c :character device
文件权限:
r :含义为 “可读”,用数字 4 表示
w:含义为 “可写”用数字 2 表示
X(小X):含义为“可执行”用数字 1 表示
-:含义为“无权限”用数字0 表示
X (大X):含义为只有目标文件对某些用户是可执行的或该目标文件是目录时才追加x 属性。
s:含义为 在文件执行时把进程的属主或组ID置为该文件的文件属主。方式“u+s”设置文件的用 户ID位,“g+s”设置组ID位。
t :含义为保存程序的文本到交换设备上

修改权限:chmod

  1. chmod 777 auth.log #含义为给auth.log文件赋予任何可读,可写,可执行权限

修改所有者:chown

  1. 命令 chown 用户名 文件,例如
  2. chown mysql auth.log #含义为 把 文件 auth.log 的所有者更改为 mysql

修改所在组:chgrp

  1. chgrp [-R] 群组名称 文件名称
  2. 例如
  3. chgrp -R mysql apache2 #含义为 ,把 目录apache2 的所在组更改为mysql

Linux下用户组、文件权限详解

软链接vs硬连接

Some nice intuition that might help, using any Linux(ish) console.
Create two files:

  1. $ touch blah1; touch blah2

Enter some Data into them:

  1. $ echo "Cat" > blah1
  2. $ echo "Dog" > blah2

(Actually, I could have used echo in the first place, as it creates the files if they don’t exist… but never mind that.)
And as expected:

  1. $cat blah1; cat blah2
  2. Cat
  3. Dog

Let’s create hard and soft links:

  1. $ ln blah1 blah1-hard
  2. $ ln -s blah2 blah2-soft

Let’s see what just happened:

  1. $ ls -l
  2. blah1
  3. blah1-hard
  4. blah2
  5. blah2-soft -> blah2

Changing the name of blah1 does not matter:

  1. $ mv blah1 blah1-new
  2. $ cat blah1-hard
  3. Cat

blah1-hard points to the inode, the contents, of the file - that wasn’t changed.

  1. $ mv blah2 blah2-new
  2. $ ls blah2-soft
  3. blah2-soft
  4. $ cat blah2-soft
  5. cat: blah2-soft: No such file or directory

The contents of the file could not be found because the soft link points to the name, that was changed, and not to the contents. Likewise, If blah1 is deleted, blah1-hard still holds the contents; if blah2 is deleted, blah2-soft is just a link to a non-existing file.
更详细的link

查看磁盘列表

diskutil list

外接硬盘挂载点目录

/Volumes/

测试磁盘读写速度

dd if=/dev/zero of=test.out bs=1m count=1000

linux根目录下的文件夹详解