使用pwd、cd
• pwd — Print Working Directory
– 用途:查看当前工作目录
• cd — Change Directory
– 用途:切换工作目录
– 格式:cd [目标文件夹位置]
. 表示当前目录
.. 表示父目录
~:家目录
~user表示用户user的家目录
/root:管理员的家目录
/home:存放所有普通用户的家目录
################################################################
[root@localhost /]# cd ~root
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd ~lisi
[root@localhost lisi]# pwd
/home/lisi
[root@localhost lisi]# useradd tom #创建普通用户tom
[root@localhost lisi]# cd ~tom
[root@localhost tom]# pwd
/home/tom
################################################################
• ls — List
– 格式:ls [选项]… [目录或文件名]
• 常用命令选项
– -l:以长格式显示,显示详细信息
– -A:包括名称以 . 开头的隐藏文档
– -d:显示目录本身(而不是内容)的属性
– -h:提供易读的容量单位(K、M等)
[root@localhost /]# ls -l /etc/passwd
[root@localhost /]# ls -l -h /etc/passwd
[root@localhost /]# ls -lh /etc/passwd #显示文件的详细属性
[root@localhost /]# ls -l /boot/ #显示目录内容详细属性
[root@localhost /]# ls -lh /boot/
[root@localhost /]# ls -ld / #显示目录本身的详细属性
[root@localhost /]# ls -ld /opt
[root@localhost /]# ls -ld /boot
[root@localhost /]# ls -A /root #显示目录的所有内容,包括隐藏数据
[root@localhost /]# ls -A /boot
################################################################
使用通配符
• 针对不确定的文档名称,以特殊字符表示
– :任意多个任意字符
– ?:单个字符
[root@localhost /]# ls /boot/vm* #在/boot目录显示vm开头的数据
[root@localhost /]# ls /dev/tty* #显示tty开头的数据
[root@localhost /]# ls /etc/*tab #以tab作为结尾的数据
[root@localhost /]# ls /etc/*.conf #以.conf作为结尾的数据
[root@localhost /]# ls /dev/tty?
[root@localhost /]# ls /dev/tty??
[root@localhost /]# ls /dev/tty???
[root@localhost /]# ls /etc/??tab
• 针对不确定的文档名称,以特殊字符表示
– [a-z]:多个字符或连续范围中的一个,若无则忽略
– {a,min,xy}:多组不同的字符串,全匹配
[root@localhost /]# ls /dev/tty[3-8]
[root@localhost /]# ls /dev/tty[4-7]
[[root@localhost /]# ls /dev/tty{1,21,60}
[root@localhost /]# ls /dev/tty{1,3,5,7,9}