Unix & Linux笔记(15)

来源:互联网 发布:java得到当前系统时间 编辑:程序博客网 时间:2024/05/16 13:46

24章 目录操作


24.1 路径名与工作目录

/usr/shar/dict/words 路径名|文件名 words


24.2 绝对路径名与相对路径名

绝对路径名
absolute pathname
相对路径名
relative pathname

Unix假定任何以/开头的路径名都是绝对路径名,没有以/开头的路径名都是相对路径名(相对于工作目录)。Unix可以用路径名代替普通文件名。


24.3 3种便利的路径名缩写:.. . ~

使用工作目录中的程序 ./plugh


24.4 在工作目录中移动:cdpwd

cd [ -LP ] [ directory | - ]cd - 类似于fg

24.5 创建新目录:mkdir

mkdir [ -p ] directory ... 如果父目录不存在,则不能创建子目录        -p parent忽略这条限制

24.6 移除目录:rmdir

rmdir [ -p ] directory....

一次只能移除一个空目录,-p消除一次的限制。

  1. 不能移除非空目录;
  2. 不能移除工作目录和根目录之间的任何目录。

rm –


24.7 移动或重命名目录:mv

mv directory target
  1. 重命名目录
  2. 移动目录
  3. 移动整个目录树

24.8 使用目录栈:pushdpopddirs

目录栈 directory stack

pushd [ directory | +n ]popd [ +n ] 删除目录dirs [ -c ] [ -l ] [ -v ]-c clear;-l list;-v verbose;

任何时候,栈顶存放的就是工作目录的名称。


24.9 最重要的程序:ls


24.10 列举目录内容:ls –CrRl

ls [ -aCdFglrRs1 ] [ name… ]    -a all    -C columns(行)    -d directory    -F Flag    -r reverse(逆序)    -R recursive(递归)    -s size    -1 list one file per line(列)

24.11 排序序列、区域设置和ls

locale LC_COLLATE=C (POSIX)

24.12 检查文件类型:ls –F

三种方法:ls –ls –colrfile

标志 含义 空 非可执行普通文件 * 可执行普通文件 / 目录 @ 符号链接 | 命名管道/FIFO

24.13 检查文件类型:ls --color

ls --color[ =always | =auto | never ] [ name… ]

在命令前面键入一个\(反斜线) 可以告诉shell忽略任何别名。


24.14 检查文件类型:file

file [ name… ]file /etc/* | less

24.15 掌握磁盘空间使用情况:ls –sdudfquota

ls -s /bin

du (disk uasge)磁盘使用

du [ -achs ] [ name… ] 如果不指定名称,du假定是工作目录。    -c count, total    -s summarize

最常用:du –cs

du -csh ~ | less

df (disk free-space)磁盘可用空间
最常用:df -h

用户配额:quota

    -g group    -u user    -s human-readable

24.16 文件有多大?块和分配单元:dumpe2fs

在文件系统中,我们将固定大小的组称为块(block),为文件分配的最小磁盘空间大小就是一个块。

磁盘存储空间也以固定大小的组块分配,我们称之为分配单元(allocation unit)或簇(cluster)。

Linux : dumpe2fsSolaris : fstyp –vFreeBSD : dumpfs

超块(superblock


24.17 使用通配符进行通配

通配符 wildcard

符号 含义 * 匹配任何0个或者多字符构成的序列 匹配任何单个的字符 [list] 匹配list中的任何字符 [^list] 匹配不在list中的任何字符 `[strings1 strings2]`

例:

ls h*Ha* Ha*y Ha*l*y

d? ————— 以d开头的两个字符的文件名
?? ————— 任何两个字符的文件名
?*y ————— 至少两个字符,并以y结尾的文件名

a.[co] —————a.ca.o
[Hh]* —————以Hh开头的文件名
[^Hh]* —————不以Hh开头的文件名

[a-z]*——– 以小写字母开头的文件名
[a-zA-Z]*[0-9] ——-以大写字母或小写字母开头并以数字结尾的文件名

三种不同类型的通配符:匹配0个或多个字符的*、匹配任何单个字符的?以及定义字符集合的[]

花括号拓展 brace expansion

ls /home/{a,b,c}cat {old,new}data{1,2,3} > mastercat {old,new}data[1-3] > mastermkdir ~/work/{a,b,c}

第一、花括号可以匹配一组拥有共同名称的文件;
第二、当创建新文件时,花括号还可以用来描述不存在的文件名。


24.18 点文件(隐藏文件):ls –

ls .[a-zA-Z]*ls -d .??*

24.19 长目录列表:ls –dhlt

修改时间
modification time
访问时间
acces time
ls -dhltu-d list directory entries instead of contents, and do not dereference symbolic links-l long list-t sort by modification time, newest first-u with -lt: sort by, and show, access time with -l: show access time and sort by name otherwise: sort by access time—— lut

以修改时间相反的顺序显示文件:ls –lrt
以访问时间相反的顺序显示文件:ls –lru

查看目录:ls -dlh
字符设备——终端 块设备——磁盘


24.20 ls使用过程中的有用别名

alias ll=’ls -l’alias la=’ls -a’alias lla=’ls -la’alias ldot=’ls -d .??*’

24.21 显示目录树:tree

tree [ -adfFrst ] [ -L level ] [ directory ]    -a all    -s size    -f full    -F Flag    -r reverse    -t sort by motification time    -i Makes tree not print the indentation lines, useful when used in conjunction with the -f option.
tree -dfi ~ | less

24.22 文件管理器

Gnome: Nautilus
KDE: Konqueror

0 0
原创粉丝点击