7、终端和常用命令
1)终端:提供用户与内核交互工具。
2)Linux中【命令的格式】
3)命令的使用举例
[root@image_boundary ~]# ls -l anaconda-ks.cfg -rw------- 1 root root 1598 Sep 17 15:57 anaconda-ks.cfg
4)常见的命令
为大家奉上 linux命令大全 宝贝网站:http://man.linuxde.net/
8、磁盘命令
1)cd命令:目录切换
cd 相对路径/绝对路径。利用相对路径或绝对路径,切换到某个目录之下; cd . 表示当前路径; cd .. 返回上一层目录; cd ~ 若为root用户,就是切换到root用户的家目录【/root】; 若为普通用户,就是切换到普通用户的家目录【/home/普通用户名】; cd / 直接返回到"/"根目录; cd - 返回上一次操作目录;"(这个很好用)"
操作如下:
[root@image_boundary ~]# cd / [root@image_boundary /]# cd home [root@image_boundary home]# cd ../usr [root@image_boundary usr]# cd - /home [root@image_boundary home]# cd .. [root@image_boundary /]# pwd / [root@image_boundary ~]# su hadoop [hadoop@image_boundary root]$ cd ~ [hadoop@image_boundary ~]$ pwd /home/hadoop
2)pwd:显示当前工作目录
[root@image_boundary /]# pwd / [root@image_boundary /]# cd ~ [root@image_boundary ~]# pwd /root [hadoop@image_boundary ~]$ pwd /home/hadoop
3)ls命令:查看目录内容
-l:展示详细信息
-a:查看隐藏内容。(显示以.开头的那些文件)
-A:查看隐藏文件。(显示.开头的那些文件,与a不同的是不显示.和…)。“注意:.表示当前文件夹 …表示上一级文件夹”
-h:友好的方式展示(文件以K、M…结尾)
-R:递归展示所有文件。
常用组合操作:ls -l 可以简化为ll。ll -h 显示文件的具体信息,并以友好的方式展示。
操作如下:
[root@image_boundary ~]# ls -l 可以写成ll total 108 -rw-r--r--. 1 root root 9 Sep 17 19:10 aa.txt~ -rw-------. 1 root root 1598 Sep 17 15:57 anaconda-ks.cfg [root@image_boundary ~]# ls -lh 可以写成ll -h total 108K -rw-r--r--. 1 root root 9 Sep 17 19:10 aa.txt~ -rw-------. 1 root root 1.6K Sep 17 15:57 anaconda-ks.cfg
4)du命令:查看每个文件和目录的磁盘使用空间。(目前不知道怎么用)
-a:展示所有内容
-h:友好方式展示
-s:统计所有文件所占用空间总的大小
du -h:会递归显示当前文件夹及其子文件夹的占用空间大小。
du -h a.txt:会显示指定文件a.txt的占用空间大小。
du -h aa:会显示指定文件夹aa的占用空间大小。
du -sh:会显示当前文件夹下,所以文件的占用空间大小
操作如下:
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb [root@image_boundary Desktop]# du -sh 28K .
5)df命令:查看磁盘使用率
-h:友好方式展示
-a:显示全部的文件系统;
注意:“df -h用于显示磁盘空间的使用情况,以及剩余的磁盘空间大小。”
操作如下:
[root@image_boundary Desktop]# df -h 文件系统 容量 已用 可用 已用% 挂载点 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_image-lv_root 35G 3.6G 30G 11% / tmpfs 931M 296K 931M 1% /dev/shm /dev/sda1 477M 42M 411M 10% /boot /dev/sr0 3.7G 3.7G 0 100% /media/CentOS_6.9_Final
9、文件命令
1)mkdir:创建目录
-p:递归创建目录
操作如下:
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb [root@image_boundary Desktop]# mkdir cc [root@image_boundary Desktop]# ll total 12 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:21 cc # 不写-p会报错。 [root@image_boundary Desktop]# mkdir dd/ee mkdir: cannot create directory `dd/ee': No such file or directory # 参数-p表示递归产生一个目录。 # 创建一个递归目录dd/ee。 [root@image_boundary Desktop]# mkdir -p dd/ee [root@image_boundary Desktop]# cd dd [root@image_boundary dd]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 20:22 ee
2)touch:创建文件
[root@image_boundary Desktop]# ll total 16 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:21 cc drwxr-xr-x. 3 root root 4096 Oct 15 20:22 dd [root@image_boundary Desktop]# cd cc [root@image_boundary cc]# ll total 0 [root@image_boundary cc]# touch sum.txt [root@image_boundary cc]# ll total 4 -rw-r--r--. 1 root root 0 Oct 15 20:28 sum.txt
3)file:查看文件类型
-b:不显示文件名,只显示文件类型。
操作如下:
"file 文件名:可以显示其到底是一个文件,还是一个目录" [root@image_boundary ~]$ file aa aa: directory [root@image_boundary cc]# ll total 0 -rw-r--r--. 1 root root 0 Oct 15 20:28 sum.txt "查看当前文件夹的类型(这里指的就是cc):文件夹" [root@image_boundary cc]# file . .: directory "如果sum.txt中没有内容,显示empty" [root@image_boundary cc]# file sum.txt ./sum.txt: empty "如果sum.txt中有内容,显示sum.txt的文件类型" [root@image_boundary cc]# file sum.txt ./sum.txt: ASCII text [root@image_boundary cc]# file -b sum.txt ASCII text
4)rmdir:删除空目录
-p:递归删除空目录
操作如下:
"注意以下两个命令的区别" rmdir dd/ee/ff 表示删除dd下面ee下面的这一个空目录ff。 rmdir -p dd/ee/ff 表示同时递归删除dd/ee/ff这3个目录。
5)rm:删除文件或目录
rm 文件名
-i:询问。(这个是默认情况,不写就是表示要询问)
-r:递归删除。
-f:强制删除(不提示删除)。
“下面这条命令:慎用!!!除非真的知道你在干嘛。”
rm -rf 目录/文件
操作如下:
[root@image_boundary bb]# ll total 12 -rw-r--r--. 1 root root 149 Oct 15 20:00 a.txt -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt [root@image_boundary bb]# rm a.txt rm: remove regular file `a.txt'? n [root@image_boundary bb]# ll total 12 -rw-r--r--. 1 root root 149 Oct 15 20:00 a.txt -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt [root@image_boundary bb]# rm a.txt rm: remove regular file `a.txt'? y [root@image_boundary bb]# ll total 8 -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt "rm -rf bb会删除bb目录下所有的目录和文件,问都不问,毫不留情。一定不要轻易使用该命令" [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:53 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:30 cc [root@image_boundary Desktop]# rm -rf bb [root@image_boundary Desktop]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 20:30 cc


