1.通过图形操作
2.虚拟机的光驱设备
[root@nb ~]# ls /dev/sr0
/dev/sr0
[root@nb ~]# ls /dev/cdrom
/dev/cdrom
[root@nb ~]# ls -l /dev/cdrom
lrwxrwxrwx. 1 root root 3 4月 29 09:06 /dev/cdrom -> sr0
[root@nb ~]#
3.mount挂载:将目录成为设备的访问点
[root@nb ~]# mkdir /dvd
[root@nb ~]# mount /dev/cdrom /dvd/
mount: /dvd: WARNING: device write-protected, mounted read-only.
[root@nb ~]# ls /dvd
AppStream EFI isolinux media.repo
BaseOS images LICENSE TRANS.TBL
[root@nb ~]#
4.卸载操作
[root@localhost /]# umount /dvd
[root@localhost /]#ls /dvd/ #显示内容为空
[root@localhost /]# mkdir /mydvd
[root@localhost /]# mount /dev/cdrom /mydvd
mount: /mydvd: WARNING: device write-protected, mounted read-only.
[root@localhost /]# ls /mydvd
家目录:专门记录用户个性化信息的目录
/root:管理员root的家目录
/home:存放所有普通用户家目录
~:用户家目录
[root@localhost /]# cd ~root #去往root用户的家目录
[root@localhost /]# pwd
[root@localhost /]# useradd dc #创建用户dc
[root@localhost /]# cd ~dc#去往dc用户的家目录
[root@localhost /]# pwd
[root@localhost /]# useradd tom #创建用户tom
[root@localhost /]#cd ~tom #去往tom用户的家目录
[root@localhost /]# pwd
ls — List
格式:ls [选项]... [目录或文件名]
常用命令选项:
-l:以长格式显示,显示详细信息
-h:提供易读的容量单位(K、M等)
-d:显示目录本身(而不是内容)的属性
[root@localhost /]# ls -ld /home
[root@localhost /]# ls -ld /root
[root@localhost /]# ls -ld /
[root@localhost /]# ls -l /etc/passwd
[root@localhost /]# ls -lh /etc/passwd
-A:显示所有内容,包含隐藏数据
-R:递归显示目录内容
[root@localhost /]# ls -A /root
[root@localhost /]# touch /opt/.nsd.txt
[root@localhost /]# ls /opt/
[root@localhost /]# ls -A /opt/
[root@localhost /]# ls -R /boot
通配符使用
*:任意多个任意字符
[root@localhost /]# ls /root/a*
[root@localhost /]# ls /boot/vm*
[root@localhost /]# ls /etc/*tab
[root@localhost /]# ls /etc/*.conf
[root@localhost /]# ls /etc/re*.conf
[root@localhost /]# ls /dev/tty*
[root@localhost /]# ls -d /etc/r*
[root@localhost /]# ls -d /etc/*as*
?:单个字符(必须要有一个)
[root@localhost /]# ls /etc/??tab
[root@localhost /]# ls /dev/tty?
[root@localhost /]# ls /dev/tty??
[a-z]:多个字符或连续范围中的一个,若无则忽略([]中最右边数字需为一位数即小于10)
{a,min,xy}:多组不同的字符串,全匹配(可写为{min..max})
[root@localhost /]# ls /dev/tty[3-9]
[root@localhost /]# ls /dev/tty[1-7]
[root@localhost /]# ls /dev/tty{1,17,20}
[root@localhost /]# ls /dev/tty{10,18,22,33}
[root@localhost /]# ls /dev/tty{26,19,21,30,40}
[root@localhost /]# ls /etc/{rw,fs}tab
命令的别名:简化复杂的命令
查看已设置的别名
alias
定义新的别名
alias 别名名称= '实际执行的命令行'
取消已设置的别名
unalias [别名名称]
[root@localhost /]# hostname
[root@localhost /]# alias hn='hostname' #临时定义别名
[root@localhost /]# hn
[root@localhost /]# alias #查看系统中有哪些别名
[root@localhost /]# unalias hn #删除hn别名
[root@localhost /]# hn
bash: hn: 未找到命令...
[root@localhost /]# alias myls='ls -l'
[root@localhost /]# myls /etc/passwd
mkdir — Make Directory
格式:mkdir [/路径/]目录名…
[-p]:连同父目录一并创建
]# mkdir -p /opt/aa/bb/cc/dd
]# ls -R /opt/aa #递归显示目录内容
]# mkdir -p /nsd04/test04
]# ls -R /nsd04
]# mkdir -p /cbd/abc01
]# ls -R /cbd
]# mkdir -p /xtt/stu01
]# ls -R /xtt
rm 删除 Remove
格式:rm [选项]... 文件或目录…
常用命令选项
-r、-f:递归删除(含目录)、强制删除
[root@localhost /]# ls /opt
[root@localhost /]# rm -rf /opt/1.txt
[root@localhost /]# ls /opt
[root@localhost /]# rm -rf /opt/aa
[root@localhost /]# ls /opt
mv移动:源数据消失
[root@localhost /]# rm -rf /opt/*
[root@localhost /]# mkdir /opt/nsd01
[root@localhost /]# touch /opt/1.txt
[root@localhost /]# ls /opt/
[root@localhost /]# mv /opt/1.txt /opt/nsd01
[root@localhost /]# ls /opt/
[root@localhost /]# ls /opt/nsd01
重新命名:路径不变的移动
[root@localhost /]# ls /opt/
[root@localhost /]# mv /opt/nsd01 /opt/abc
[root@localhost /]# ls /opt/
[root@localhost /]# mv /opt/abc /opt/student
[root@localhost /]# ls /opt/
[root@localhost /]# mv /opt/student /mnt/stu01
[root@localhost /]# ls /mnt/
cp:复制/拷贝
-r:复制目录
[root@localhost /]# cp /etc/passwd /opt
[root@localhost /]# ls /opt
[root@localhost /]# cp -r /boot /opt
[root@localhost /]# ls /opt
[root@localhost /]# cp -r /home /opt
[root@localhost /]# ls /opt
进行强制覆盖
]# \cp -r /boot /opt #本次操作临时取消别名
]# \cp -r /boot /opt #本次操作临时取消别名
复制可以重新命名,目标路径下数据的名称
]# cp -r /home /opt/myhome
]# ls /opt
]# cp /etc/shells /opt/r.txt
]# ls /opt
]# ls /opt
]# cp -r /boot /opt/myboot
]# ls /opt
]# cp -r /boot /opt/myboot
]# ls /opt/myboot
复制可以支持两个以上的参数,永远把最后一个参数作为目标,其他的所有的参数都作为源数据
]# mkdir /nsd05
]# ls /nsd05
]# cp -r /home /boot /etc/passwd /etc/shells /nsd05
]# ls /nsd05
复制与一个点进行连用,将数据复制到当前路径下
]# cd /etc/sysconfig/network-scripts/
]# pwd
]# cp /etc/passwd .
]# ls
]# cd /mnt
]# pwd
]# cp /etc/shells .
]# ls
grep过滤文件内容,输入包含指定字符串的行
常用命令选项
-v,取反匹配(不包含)
-i,忽略大小写
[root@localhost /]# grep root /etc/passwd
[root@localhost /]# grep -v root /etc/passwd
[root@localhost /]# grep ROOT /etc/passwd
[root@localhost /]# grep -i ROOT /etc/passwd
高级使用
^word 以字符串word开头
word$ 以字符串word结尾
[root@localhost /]# grep ^root /etc/passwd
[root@localhost /]# grep ^bin /etc/passwd
[root@localhost /]# grep root$ /etc/passwd
[root@localhost /]# grep bash$ /etc/passwd
^$:表示空行
]# cat /etc/default/useradd
]# grep ^$ /etc/default/useradd #过滤空行
]# grep -v ^$ /etc/default/useradd #过滤不要空行的内容
]# cat /etc/login.defs
]# grep ^$ /etc/login.defs #过滤空行
]# grep -v ^$ /etc/login.defs #过滤不要空行的内容