鸟哥私房菜学习笔记

news/2024/5/20 14:22:39 标签: linux, 运维, 服务器

2.1.3 各硬件设备在Linux中的文件名
设备 设备在Linux内的文件名
SCSI/SATA/USB硬盘机----------->/dev/sd[a-p]
USB闪存盘 ------------>/dev/sd[a-p] (与SATA相同)
VirtI/O界面--------->/dev/vd[a-p] (用于虚拟机内)
软盘机--------->/dev/fd[0-7]
打印机--------->/dev/lp[0-2] (25针打印机) /dev/usb/lp[0-15] (USB 接口)
鼠标-------->/dev/input/mouse[0-15] (通用) /dev/psaux (PS/2界面) /dev/mouse (当前鼠标)
CDROM/DVDROM---------->/dev/scd[0-1] (通用) /dev/sr[0-1] (通用,CentOS 较常见) /dev/cdrom (当前 CDROM)
磁带机----------->/dev/ht0 (IDE 界面) /dev/st0 (SATA/SCSI界面) /dev/tape (当前磁带)
IDE硬盘机 ------------>/dev/hd[a-d] (旧式系统才有)

例题:假设你的主机为虚拟机,里面仅有一颗VirtIO接口的磁盘,请问他在Linux操作系统里面的设备文件名为何?
答:参考 2.1.3 小节的介绍,虚拟机使用 VirtIO 界面时,磁盘文件名应该是 /dev/vda 才对!

例题:如果你的PC上面有两个SATA磁盘以及一个USB磁盘,而主板上面有六个SATA的插槽。这两个SATA磁盘分别安插在主板上的SATA1, SATA5插槽上, 请问这三个磁盘在Linux中的设备文件名为何?
答:由于是使用侦测到的顺序来决定设备文件名,并非与实际插槽代号有关,因此设备的文件名如下:
1.SATA1插槽上的文件名:/dev/sda
2.SATA5插槽上的文件名:/dev/sdb
3.USB磁盘(开机完成后才被系统捉到):/dev/sdc

man

代号 代表内容
1 使用者在shell环境中可以操作的指令或可可执行文件
2 系统核心可调用的函数与工具等
3 一些常用的函数(function)与函数库(library),大部分为C的函数库(libc)
4 设备文件的说明,通常在/dev下的文件
5 配置文件或者是某些文件的格式
6 游戏(games)
7 惯例与协定等,例如Linux文件系统、网络协定、ASCII code等等的说明
8 系统管理员可用的管理指令
9 跟kernel有关的文件

例题:你可否查出来,系统中还有哪些跟“man”这个指令有关的说明文档呢?


xz@xiaqiu:~/study/niao-linux$ man -f man
man (1)              - an interface to the system reference manuals
man (7)              - macros to format man pages
xz@xiaqiu:~/study/niao-linux$ 
xz@xiaqiu:~/study/niao-linux$ man 1 man
xz@xiaqiu:~/study/niao-linux$ man 7 man

搜寻的顺序是记录在/etc/man_db.conf 这个配置文件当中

例题:找出系统的说明文档中,只要有man这个关键字就将该说明列出来。答:
##man -k man


xz@xiaqiu:~/study/niao-linux$ man -k man
accessdb (8)         - 以易读的格式转储 man-db 数据库的内容
catman (8)           - 创建或更新预格式化的手册页
lexgrog (1)          - 解析 man 手册页的头部信息
man (1)              - an interface to the system reference manuals
man-recode (1)       - convert manual pages to another encoding
manconv (1)          - 将手册页从一种编码转换到另一种
mandb (8)            - 创建或更新手册页索引缓存
manpath (1)          - 确定手册页的搜索路径
manpath (5)          - 格式化 /etc/manpath.config 文件
... ...

whatis man


xz@xiaqiu:~/study/niao-linux$ whatis man
man (1)              - an interface to the system reference manuals
man (7)              - macros to format man pages
xz@xiaqiu:~/study/niao-linux$ 

apropos man


xz@xiaqiu:~/study/niao-linux$ apropos man
accessdb (8)         - 以易读的格式转储 man-db 数据库的内容
catman (8)           - 创建或更新预格式化的手册页
lexgrog (1)          - 解析 man 手册页的头部信息
man (1)              - an interface to the system reference manuals
man-recode (1)       - convert manual pages to another encoding
manconv (1)          - 将手册页从一种编码转换到另一种
mandb (8)            - 创建或更新手册页索引缓存
manpath (1)          - 确定手册页的搜索路径
manpath (5)          - 格式化 /etc/manpath.config 文件
Alien::Build::CommandSequence (3pm) - Alien::Build command sequence
Alien::Build::Manual::Alien (3pm) - General alien author 
...

mandb


xz@xiaqiu:~/study/niao-linux$ mandb
mandb: 警告:已经设定了 $MANPATH,在后面加上 /etc/manpath.config
正在处理 /home/xz/Android/jdk1.8.0_201/man 下的手册页...
正在为路径 /home/xz/Android/jdk1.8.0_201/man/man1 更新索引缓存。请等待...完成。
正在 /home/xz/Android/jdk1.8.0_201/man 下查找孤立 cat 页面...
正在处理 /home/xz/Android/jdk1.8.0_201/man/ja_JP.UTF-8 下的手册页...
正在为路径 /home/xz/Android/jdk1.8.0_201/man/ja_JP.UTF-8/man1 更新索引缓存。请等待...完成。
正在 /home/xz/Android/jdk1.8.0_201/man/ja_JP.UTF-8 下查找孤立 cat 页面...
正在删除 /home/xz/Android/jdk1.8.0_201/man/ja 里的旧数据库条目...
正在处理 /home/xz/Android/jdk1.8.0_201/man/ja 下的手册页...
正在处理 /home/xz/Android/jdk1.8.0_201/man/cat1 下的手册页...
2 个 man 子目录包含更新的手册页。
添加了 90 个手册页。
添加了 0 个孤立 cat 页面。
删除了 0 条旧数据库条目。
xz@xiaqiu:~/study/niao-linux$ 

info info


xz@xiaqiu:~/study/niao-linux$ info info
ext: Stand-alone Info,  Up: (dir)

Stand-alone GNU Info
********************

This documentation describes the stand-alone Info reader which you can
use to read Info documentation.

   If you are new to the Info reader, then you can get started by typing
'H' for a list of basic key bindings.  You can read through the rest of
this manual by typing <SPC> and <DEL> (or <Space> and <Backspace>) to
move forwards and backwards in it.

* Menu:

* Stand-alone Info::            What is Info?
* Invoking Info::               Options you can pass on the command line.
* Cursor Commands::             Commands which move the cursor within a node.
* Scrolling Commands::          Commands for reading the text within a node.
* Node Commands::               Commands for selecting a new node.
* Searching Commands::          Commands for searching an Info file.
* Index Commands::              Commands for looking 

简单文书编辑器: nano

将数据同步写入硬盘中的指令: sync

惯用的关机指令: shutdown

重新开机,关机: reboot, halt, poweroff

chgrp :改变文件所属群组

chown :改变文件拥有者

chmod :改变文件的权限, SUID, SGID, SBIT等等的特性

改变所属群组, chgrp

/bin

系统有很多放置可执行文件的目录,但/bin比较特殊。因为/bin放置的是在单人维护模式下还能够被操作的指令。 在/bin下面的指令可以被root与一般帐号所使用,主要有:cat, chmod, chown, date, mv, mkdir, cp, bash等等常用的指令。

/boot

这个目录主要在放置开机会使用到的文件,包括Linux核心文件以及开机菜单与开机所需配置文件等等。 Linux kernel常用的文件名为:vmlinuz,如果使用的是grub2这个开机管理程序, 则还会存在/boot/grub2/这个目录喔!

/dev

在Linux系统上,任何设备与周边设备都是以文件的型态存在于这个目录当中的。 你只要通过存取这个目录下面的某个文件,就等于存取某个设备啰~ 比要重要的文件有/dev/null, /dev/zero, /dev/tty, /dev/loop, /dev/sd等等

/etc

系统主要的配置文件几乎都放置在这个目录内,例如人员的帐号密码档、 各种服务的启始档等等。一般来说,这个目录下的各文件属性是可以让一般使用者查阅的, 但是只有root有权力修改。FHS建议不要放置可可执行文件(binary)在这个目录中喔。比较重要的文件有: /etc/modprobe.d/, /etc/passwd, /etc/fstab, /etc/issue 等等。另外 FHS 还规范几个重要的目录最好要存在 /etc/ 目录下喔:/etc/opt(必要):这个目录在放置第三方协力软件 /opt 的相关配置文件 /etc/X11/(建议):与 X Window 有关的各种配置文件都在这里,尤其是 xorg.conf 这个 X Server 的配置文件。 /etc/sgml/(建议):与 SGML 格式有关的各项配置文件 /etc/xml/(建议):与 XML 格式有关的各项配置文件

/lib

系统的函数库非常的多,而/lib放置的则是在开机时会用到的函数库, 以及在/bin或/sbin下面的指令会调用的函数库而已。 什么是函数库呢?你可以将他想成是“外挂”,某些指令必须要有这些“外挂”才能够顺利完成程序的执行之意。 另外 FSH 还要求下面的目录必须要存在:/lib/modules/:这个目录主要放置可抽换式的核心相关模块(驱动程序)喔!

/media

media是“媒体”的英文,顾名思义,这个/media下面放置的就是可移除的设备啦! 包括软盘、光盘、DVD等等设备都暂时挂载于此。常见的文件名有:/media/floppy, /media/cdrom等等。

/mnt

如果你想要暂时挂载某些额外的设备,一般建议你可以放置到这个目录中。 在古早时候,这个目录的用途与/media相同啦!只是有了/media之后,这个目录就用来暂时挂载用了。

/opt

这个是给第三方协力软件放置的目录。什么是第三方协力软件啊? 举例来说,KDE这个桌面管理系统是一个独立的计划,不过他可以安装到Linux系统中,因此KDE的软件就建议放置到此目录下了。 另外,如果你想要自行安装额外的软件(非原本的distribution提供的),那么也能够将你的软件安装到这里来。 不过,以前的Linux系统中,我们还是习惯放置在/usr/local目录下呢!

/run

早期的 FHS 规定系统开机后所产生的各项信息应该要放置到 /var/run 目录下,新版的 FHS 则规范到 /run 下面。 由于 /run 可以使用内存来仿真,因此性能上会好很多!

/sbin

Linux有非常多指令是用来设置系统环境的,这些指令只有root才能够利用来“设置”系统,其他使用者最多只能用来“查询”而已。 放在/sbin下面的为开机过程中所需要的,里面包括了开机、修复、还原系统所需要的指令。 至于某些服务器软件程序,一般则放置到/usr/sbin/当中。至于本机自行安装的软件所产生的系统可执行文件(system binary), 则放置到/usr/local/sbin/当中了。常见的指令包括:fdisk, fsck, ifconfig, mkfs等等。

/srv

srv可以视为“service”的缩写,是一些网络服务启动之后,这些服务所需要取用的数据目录。 常见的服务例如WWW, FTP等等。举例来说,WWW服务器需要的网页数据就可以放置在/srv/www/里面。 不过,系统的服务数据如果尚未要提供给网际网络任何人浏览的话,默认还是建议放置到 /var/lib 下面即可。

/tmp

这是让一般使用者或者是正在执行的程序暂时放置文件的地方。 这个目录是任何人都能够存取的,所以你需要定期的清理一下。当然,重要数据不可放置在此目录啊! 因为FHS甚至建议在开机时,应该要将/tmp下的数据都删除唷!

/home

这是系统默认的使用者主文件夹(home directory)。在你新增一个一般使用者帐号时, 默认的使用者主文件夹都会规范到这里来。比较重要的是,主文件夹有两种代号喔:~:代表目前这个使用者的主文件夹 ~dmtsai :则代表 dmtsai 的主文件夹!

/lib

用来存放与 /lib 不同的格式的二进制函数库,例如支持 64 位的 /lib64 函数库等

/root

系统管理员(root)的主文件夹。之所以放在这里,是因为如果进入单人维护模式而仅挂载根目录时, 该目录就能够拥有root的主文件夹,所以我们会希望root的主文件夹与根目录放置在同一个分区中。

/lost+found

这个目录是使用标准的ext2/ext3/ext4文件系统格式才会产生的一个目录,目的在于当文件系统发生错误时, 将一些遗失的片段放置到这个目录下。不过如果使用的是 xfs 文件系统的话,就不会存在这个目录了!

/proc

这个目录本身是一个“虚拟文件系统(virtual filesystem)”喔!他放置的数据都是在内存当中, 例如系统核心、行程信息(process)、周边设备的状态及网络状态等等。因为这个目录下的数据都是在内存当中, 所以本身不占任何硬盘空间啊!比较重要的文件例如:/proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net/* 等等。

/sys

这个目录其实跟/proc非常类似,也是一个虚拟的文件系统,主要也是记录核心与系统硬件信息较相关的信息。 包括目前已载入的核心模块与核心侦测到的硬件设备信息等等。这个目录同样不占硬盘容量喔!

/usr/bin/

所有一般用户能够使用的指令都放在这里!目前新的 CentOS 7 已经将全部的使用者指令放置于此,而使用链接文件的方式将 /bin 链接至此! 也就是说, /usr/bin 与 /bin 是一模一样了!另外,FHS 要求在此目录下不应该有子目录!

/usr/lib/

基本上,与 /lib 功能相同,所以 /lib 就是链接到此目录中的!

/usr/local/

系统管理员在本机自行安装自己下载的软件(非distribution默认提供者),建议安装到此目录, 这样会比较便于管理。举例来说,你的distribution提供的软件较旧,你想安装较新的软件但又不想移除旧版, 此时你可以将新版软件安装于/usr/local/目录下,可与原先的旧版软件有分别啦! 你可以自行到/usr/local去看看,该目录下也是具有bin, etc, include, lib…的次目录喔!

/usr/sbin/

非系统正常运行所需要的系统指令。最常见的就是某些网络服务器软件的服务指令(daemon)啰!不过基本功能与 /sbin 也差不多, 因此目前 /sbin 就是链接到此目录中的。

/usr/share/

主要放置只读架构的数据文件,当然也包括共享文件。在这个目录下放置的数据几乎是不分硬件架构均可读取的数据, 因为几乎都是文字文件嘛!在此目录下常见的还有这些次目录:/usr/share/man:线上说明文档 /usr/share/doc:软件杂项的文件说明 /usr/share/zoneinfo:与时区有关的时区文件

/usr/games/

与游戏比较相关的数据放置处

/usr/include/

c/c++等程序语言的文件开始(header)与包含档(include)放置处,当我们以tarball方式 (*.tar.gz 的方式安装软件)安装某些数据时,会使用到里头的许多包含档喔!

/usr/libexec/

某些不被一般使用者惯用的可执行文件或脚本(script)等等,都会放置在此目录中。例如大部分的 X 窗口下面的操作指令, 很多都是放在此目录下的。

/usr/src/

一般源代码建议放置到这里,src有source的意思。至于核心源代码则建议放置到/usr/src/linux/目录下。

/var/cache/

应用程序本身运行过程中会产生的一些暂存盘;

/var/lib/

程序本身执行的过程中,需要使用到的数据文件放置的目录。在此目录下各自的软件应该要有各自的目录。 举例来说,MySQL的数据库放置到/var/lib/mysql/而rpm的数据库则放到/var/lib/rpm去!

/var/lock/

某些设备或者是文件资源一次只能被一个应用程序所使用,如果同时有两个程序使用该设备时, 就可能产生一些错误的状况,因此就得要将该设备上锁(lock),以确保该设备只会给单一软件所使用。 举例来说,烧录机正在烧录一块光盘,你想一下,会不会有两个人同时在使用一个烧录机烧片? 如果两个人同时烧录,那片子写入的是谁的数据?所以当第一个人在烧录时该烧录机就会被上锁, 第二个人就得要该设备被解除锁定(就是前一个人用完了)才能够继续使用啰。目前此目录也已经挪到 /run/lock 中!

/var/log/

这是登录文件放置的目录!里面比较重要的文件如/var/log/messages, /var/log/wtmp(记录登陆者的信息)等。

/var/mail/

放置个人电子邮件信箱的目录,不过这个目录也被放置到/var/spool/mail/目录中! 通常这两个目录是互为链接文件啦!

/var/run/

某些程序或者是服务启动后,会将他们的PID放置在这个目录下喔!至于PID的意义我们会在后续章节提到的。 与 /run 相同,这个目录链接到 /run 去了!

/var/spool/

这个目录通常放置一些伫列数据,所谓的“伫列”就是排队等待其他程序使用的数据啦! 这些数据被使用后通常都会被删除。举例来说,系统收到新信会放置到/var/spool/mail/中, 但使用者收下该信件后该封信原则上就会被删除。信件如果暂时寄不出去会被放到/var/spool/mqueue/中, 等到被送出后就被删除。如果是工作调度数据(crontab),就会被放置到/var/spool/cron/目录中!

cd:变换目录


xz@xiaqiu:~/study/niao-linux/test$ cd ..
xz@xiaqiu:~/study/niao-linux$ cd test/
xz@xiaqiu:~/study/niao-linux/test$ 

pwd:显示目前的目录


xz@xiaqiu:~/study/niao-linux$ pwd
/home/xz/study/niao-linux
xz@xiaqiu:~/study/niao-linux$ 

mkdir:创建一个新的目录


xz@xiaqiu:~/study/niao-linux$ ls
readme.md  test
xz@xiaqiu:~/study/niao-linux$ mkdir dir
xz@xiaqiu:~/study/niao-linux$ ls
dir  readme.md  test
xz@xiaqiu:~/study/niao-linux$ 

rmdir:删除一个空的目录


xz@xiaqiu:~/study/niao-linux$ ls
dir  readme.md  test
xz@xiaqiu:~/study/niao-linux$ rmdir dir
xz@xiaqiu:~/study/niao-linux$ ls
readme.md  test
xz@xiaqiu:~/study/niao-linux$ 

$PATH: 环境变量


xz@xiaqiu:~/study/niao-linux$ echo $PATH
/home/xz/Android/jdk1.8.0_201/bin:/opt/vulkansdk/1.2.154.0/x86_64/bin:/opt/android-studio/bin:/opt/clion-2021.2/bin:/opt/Qt/Qt6/6.2.0/gcc_64/bin:/opt/Qt/Qt6/Tools/QtCreator/bin:/opt/Qt/qtdesignstudio-2.1.0-community/bin:/opt/Qt/Qt5.14.2/5.14.2/gcc_64/bin:/opt/Qt/Qt5.14.2/Tools/QtCreator/bin:/home/xz/.local/bin:/opt/Qt/Qt5.14.2/5.14.2/gcc_64/bin:/opt/Qt/Qt5.14.2/Tools/QtCreator/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
xz@xiaqiu:~/study/niao-linux$ 

PATH="${PATH} : ./"


xz@xiaqiu:~/study/niao-linux$ echo $PATH
/home/xz/Android/jdk1.8.0_201/bin:/opt/vulkansdk/1.2.154.0/x86_64/bin:/opt/android-studio/bin:/opt/clion-2021.2/bin:/opt/Qt/Qt6/6.2.0/gcc_64/bin:/opt/Qt/Qt6/Tools/QtCreator/bin:/opt/Qt/qtdesignstudio-2.1.0-community/bin:/opt/Qt/Qt5.14.2/5.14.2/gcc_64/bin:/opt/Qt/Qt5.14.2/Tools/QtCreator/bin:/home/xz/.local/bin:/opt/Qt/Qt5.14.2/5.14.2/gcc_64/bin:/opt/Qt/Qt5.14.2/Tools/QtCreator/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
xz@xiaqiu:~/study/niao-linux$ PATH="${PATH}:./"
xz@xiaqiu:~/study/niao-linux$ echo $PATH
/home/xz/Android/jdk1.8.0_201/bin:/opt/vulkansdk/1.2.154.0/x86_64/bin:/opt/android-studio/bin:/opt/clion-2021.2/bin:/opt/Qt/Qt6/6.2.0/gcc_64/bin:/opt/Qt/Qt6/Tools/QtCreator/bin:/opt/Qt/qtdesignstudio-2.1.0-community/bin:/opt/Qt/Qt5.14.2/5.14.2/gcc_64/bin:/opt/Qt/Qt5.14.2/Tools/QtCreator/bin:/home/xz/.local/bin:/opt/Qt/Qt5.14.2/5.14.2/gcc_64/bin:/opt/Qt/Qt5.14.2/Tools/QtCreator/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:./
xz@xiaqiu:~/study/niao-linux$ 

exit 登出


xz@xiaqiu:~/study/niao-linux$ sudo su
[sudo] xz 的密码: 
root@xiaqiu:/home/xz/study/niao-linux# exit
exit
xz@xiaqiu:~/study/niao-linux$ 

mv 移动


xz@xiaqiu:~/study/niao-linux$ ls
readme.md  test
xz@xiaqiu:~/study/niao-linux$ mv readme.md  test/
xz@xiaqiu:~/study/niao-linux$ ls
test
xz@xiaqiu:~/study/niao-linux$ mv test/readme.md  .
xz@xiaqiu:~/study/niao-linux$ ls
readme.md  test
xz@xiaqiu:~/study/niao-linux$ 

ls -al 将主文件夹下的所有文件列出来(含属性与隐藏文件)


xz@xiaqiu:~/study/niao-linux$ ls -al 
总用量 20
drwxrwxr-x  3 xz xz 4096 17 23:22 .
drwxrwxr-x 52 xz xz 4096 17 22:13 ..
-rw-rw-r--  1 xz xz 6314 17 22:52 readme.md
-rw-rw-r--  1 xz xz    0 17 23:22 .test
drwxrwxr-x  2 xz xz 4096 17 23:17 test
xz@xiaqiu:~/study/niao-linux$ 

ls -alF --color=never 不显示颜色,但在文件名末显示出该文件名代表的类型(type)


xz@xiaqiu:~/study/niao-linux$ ls -alF --color=never
总用量 20
drwxrwxr-x  3 xz xz 4096 17 23:22 ./
drwxrwxr-x 52 xz xz 4096 17 22:13 ../
-rw-rw-r--  1 xz xz 6314 17 22:52 readme.md
-rw-rw-r--  1 xz xz    0 17 23:22 .test
drwxrwxr-x  2 xz xz 4096 17 23:17 test/
xz@xiaqiu:~/study/niao-linux$ 

ls -al --full-time 完整的呈现文件的修改时间


xz@xiaqiu:~/study/niao-linux$ ls -al --full-time
总用量 20
drwxrwxr-x  3 xz xz 4096 2022-01-07 23:22:53.043705400 +0800 .
drwxrwxr-x 52 xz xz 4096 2022-01-07 22:13:08.144225918 +0800 ..
-rw-rw-r--  1 xz xz 6314 2022-01-07 22:52:11.307060308 +0800 readme.md
-rw-rw-r--  1 xz xz    0 2022-01-07 23:22:53.043705400 +0800 .test
drwxrwxr-x  2 xz xz 4096 2022-01-07 23:17:44.207729754 +0800 test
xz@xiaqiu:~/study/niao-linux$ 

cp 复制


xz@xiaqiu:~/study/niao-linux$ ls test/
xz@xiaqiu:~/study/niao-linux$ 
xz@xiaqiu:~/study/niao-linux$ cp readme.md  test/
xz@xiaqiu:~/study/niao-linux$ ls test/
readme.md
xz@xiaqiu:~/study/niao-linux$ 

cp -i


xz@xiaqiu:~/study/niao-linux$ ls readme.md test/readme.md  -l
-rw-rw-r-- 1 xz xz 22502 17 23:31 readme.md
-rw-rw-r-- 1 xz xz 21655 17 23:29 test/readme.md
xz@xiaqiu:~/study/niao-linux$ cp -i readme.md test/
cp:是否覆盖'test/readme.md'? n
xz@xiaqiu:~/study/niao-linux$ ls readme.md test/readme.md  -l
-rw-rw-r-- 1 xz xz 22502 17 23:31 readme.md
-rw-rw-r-- 1 xz xz 21655 17 23:29 test/readme.md
xz@xiaqiu:~/study/niao-linux$ cp -i readme.md test/
cp:是否覆盖'test/readme.md'? y
xz@xiaqiu:~/study/niao-linux$ ls readme.md test/readme.md  -l
-rw-rw-r-- 1 xz xz 22502 17 23:31 readme.md
-rw-rw-r-- 1 xz xz 22502 17 23:32 test/readme.md
xz@xiaqiu:~/study/niao-linux$ 

cp -a


xz@xiaqiu:~/study/niao-linux$ ls readme.md test/readme.md  -l
-rw-rw-r-- 1 xz xz 22502 17 23:31 readme.md
-rw-rw-r-- 1 xz xz 22502 17 23:32 test/readme.md
xz@xiaqiu:~/study/niao-linux$ cp -a readme.md test/
xz@xiaqiu:~/study/niao-linux$ ls readme.md test/readme.md  -l
-rw-rw-r-- 1 xz xz 22502 17 23:31 readme.md
-rw-rw-r-- 1 xz xz 22502 17 23:31 test/readme.md
xz@xiaqiu:~/study/niao-linux$ 

cp -r


xz@xiaqiu:~/study/niao-linux$ ls
readme.md  test  test1
xz@xiaqiu:~/study/niao-linux$ 
xz@xiaqiu:~/study/niao-linux$ ls test1
test
xz@xiaqiu:~/study/niao-linux$ cp test1 test/
cp: 未指定 -r;略过目录'test1'
xz@xiaqiu:~/study/niao-linux$ cp test1 test/ -r
xz@xiaqiu:~/study/niao-linux$ ls test
readme.md  test1
xz@xiaqiu:~/study/niao-linux$ 

cp -s 链接文件


xz@xiaqiu:~/study/niao-linux$ ls -l
总用量 32
-rw-rw-r-- 1 xz xz 23060 17 23:33 readme.md
drwxrwxr-x 3 xz xz  4096 17 23:37 test
drwxrwxr-x 3 xz xz  4096 17 23:35 test1
xz@xiaqiu:~/study/niao-linux$ cp -s readme.md readme.md_link
xz@xiaqiu:~/study/niao-linux$ ls -l
总用量 32
-rw-rw-r-- 1 xz xz 23060 17 23:33 readme.md
lrwxrwxrwx 1 xz xz     9 17 23:38 readme.md_link -> readme.md
drwxrwxr-x 3 xz xz  4096 17 23:37 test
drwxrwxr-x 3 xz xz  4096 17 23:35 test1
xz@xiaqiu:~/study/niao-linux$ 

cp -u 在目标文件与来源文件有差异时,才会复制的

mv -f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖

mv -f :若目标文件 (destination) 已经存在时,就会询问是否覆盖!

mv -u :若目标文件已经存在,且 source 比较新,才会更新 (update)

basename 取得路径的文件名称


xz@xiaqiu:~/study/niao-linux$ basename test/test 
test
xz@xiaqiu:~/study/niao-linux$ 

dirname 取得路径的目录名称


xz@xiaqiu:~/study/niao-linux$ dirname dir/dir/test 
dir/dir
xz@xiaqiu:~/study/niao-linux$

cat 由第一行开始显示文件内容


xz@xiaqiu:~/study/niao-linux$ cat text.txt 
dirname dir/dir/test 1
dirname dir/dir/test 2
dirname dir/dir/test 3
xz@xiaqiu:~/study/niao-linux$ 

tac 从最后一行开始显示,可以看出 tac 是 cat 的倒着写!


xz@xiaqiu:~/study/niao-linux$ tac text.txt 
dirname dir/dir/test 3
dirname dir/dir/test 2
dirname dir/dir/test 1
xz@xiaqiu:~/study/niao-linux$ 

nl 显示的时候,顺道输出行号!


xz@xiaqiu:~/study/niao-linux$ nl text.txt 
     1	dirname dir/dir/test 1
     2	dirname dir/dir/test 2
     3	dirname dir/dir/test 3
xz@xiaqiu:~/study/niao-linux$ 

more 一页一页的显示文件内容

less 与 more 类似,但是比 more 更好的是,他可以往前翻页!


xz@xiaqiu:~/study/niao-linux$ more readme.md
2.1.3 各硬件设备在Linux中的文件名
设备                         设备在Linux内的文件名
SCSI/SATA/USB硬盘机----------->/dev/sd[a-p]
USB闪存盘	------------>/dev/sd[a-p] (与SATA相同)
VirtI/O界面--------->/dev/vd[a-p] (用于虚拟机内)
软盘机--------->/dev/fd[0-7]
打印机--------->/dev/lp[0-2]25针打印机) /dev/usb/lp[0-15] (USB 接口)
鼠标-------->/dev/input/mouse[0-15] (通用) /dev/psaux (PS/2界面) /dev/mouse (当前鼠标
)
CDROM/DVDROM---------->/dev/scd[0-1] (通用) /dev/sr[0-1] (通用,CentOS 较常见) /dev/cdr
om (当前 CDROM)
磁带机----------->/dev/ht0 (IDE 界面) /dev/st0 (SATA/SCSI界面) /dev/tape (当前磁带)
IDE硬盘机	------------>/dev/hd[a-d] (旧式系统才有)

例题:假设你的主机为虚拟机,里面仅有一颗VirtIO接口的磁盘,请问他在Linux操作系统里面的设备文
件名为何?
答:参考 2.1.3 小节的介绍,虚拟机使用 VirtIO 界面时,磁盘文件名应该是 /dev/vda 才对!

例题:如果你的PC上面有两个SATA磁盘以及一个USB磁盘,而主板上面有六个SATA的插槽。这两个SATA磁
盘分别安插在主板上的SATA1, SATA5插槽上, 请问这三个磁盘在Linux中的设备文件名为何?
答:由于是使用侦测到的顺序来决定设备文件名,并非与实际插槽代号有关,因此设备的文件名如下:
1.SATA1插槽上的文件名:/dev/sda
2.SATA5插槽上的文件名:/dev/sdb
--更多--(6%)

head 只看头几行


xz@xiaqiu:~/study/niao-linux$ head readme.md
2.1.3 各硬件设备在Linux中的文件名
设备                         设备在Linux内的文件名
SCSI/SATA/USB硬盘机----------->/dev/sd[a-p]
USB闪存盘	------------>/dev/sd[a-p] (与SATA相同)
VirtI/O界面--------->/dev/vd[a-p] (用于虚拟机内)
软盘机--------->/dev/fd[0-7]
打印机--------->/dev/lp[0-2]25针打印机) /dev/usb/lp[0-15] (USB 接口)
鼠标-------->/dev/input/mouse[0-15] (通用) /dev/psaux (PS/2界面) /dev/mouse (当前鼠标)
CDROM/DVDROM---------->/dev/scd[0-1] (通用) /dev/sr[0-1] (通用,CentOS 较常见) /dev/cdrom (当前 CDROM)
磁带机----------->/dev/ht0 (IDE 界面) /dev/st0 (SATA/SCSI界面) /dev/tape (当前磁带)
xz@xiaqiu:~/study/niao-linux$ 

tail 只看尾巴几行


xz@xiaqiu:~/study/niao-linux$ tail readme.md

例题:如果你的PC上面有两个SATA磁盘以及一个USB磁盘,而主板上面有六个SATA的插槽。这两个SATA磁
盘分别安插在主板上的SATA1, SATA5插槽上, 请问这三个磁盘在Linux中的设备文件名为何?
答:由于是使用侦测到的顺序来决定设备文件名,并非与实际插槽代号有关,因此设备的文件名如下:
1.SATA1插槽上的文件名:/dev/sda
2.SATA5插槽上的文件名:/dev/sdb
--更多--(6%)


xz@xiaqiu:~/study/niao-linux$ 

od 以二进制的方式读取文件内容!


xz@xiaqiu:~/study/niao-linux$ od text.txt 
0000000 064544 067162 066541 020145 064544 027562 064544 027562
0000020 062564 072163 030440 062012 071151 060556 062555 062040
0000040 071151 062057 071151 072057 071545 020164 005062 064544
0000060 067162 066541 020145 064544 027562 064544 027562 062564
0000100 072163 031440 000012
0000105
xz@xiaqiu:~/study/niao-linux$ 

cat -n 可以印出行号


xz@xiaqiu:~/study/niao-linux$ cat -n text.txt 
     1   dirname dir/dir/test 1
     2   dirname dir/dir/test 2
     3   dirname dir/dir/test 3
xz@xiaqiu:~/study/niao-linux$

cat -A 包含特殊字符


xz@xiaqiu:~/study/niao-linux$ cat -A text.txt 
dirname dir/dir/test 1$
dirname dir/dir/test 2$
dirname dir/dir/test 3$
xz@xiaqiu:~/study/niao-linux$ 

head -n 2 显示前面2行


xz@xiaqiu:~/study/niao-linux$ head -n 2 text.txt 
dirname dir/dir/test 1
dirname dir/dir/test 2
xz@xiaqiu:~/study/niao-linux$ 

head -n -2 不显示后面2行


xz@xiaqiu:~/study/niao-linux$ head -n -2 text.txt 
dirname dir/dir/test 1
xz@xiaqiu:~/study/niao-linux$ 
xz@xiaqiu:~/study/niao-linux$ head -n -1 text.txt 
dirname dir/dir/test 1
dirname dir/dir/test 2
xz@xiaqiu:~/study/niao-linux$ 

tail -n 2 text.txt 显示最后2行


xz@xiaqiu:~/study/niao-linux$ tail -n 2 text.txt 
dirname dir/dir/test 2
dirname dir/dir/test 3
xz@xiaqiu:~/study/niao-linux$ 

od -t c 使用 ASCII 字符来输出


xz@xiaqiu:~/study/niao-linux$ od -t c text.txt 
0000000   d   i   r   n   a   m   e       d   i   r   /   d   i   r   /
0000020   t   e   s   t       1  \n   d   i   r   n   a   m   e       d
0000040   i   r   /   d   i   r   /   t   e   s   t       2  \n   d   i
0000060   r   n   a   m   e       d   i   r   /   d   i   r   /   t   e
0000100   s   t       3  \n
0000105
xz@xiaqiu:~/study/niao-linux$ 

od -t oCc text.txt


xz@xiaqiu:~/study/niao-linux$ od -t oCc text.txt 
0000000 144 151 162 156 141 155 145 040 144 151 162 057 144 151 162 057
          d   i   r   n   a   m   e       d   i   r   /   d   i   r   /
0000020 164 145 163 164 040 061 012 144 151 162 156 141 155 145 040 144
          t   e   s   t       1  \n   d   i   r   n   a   m   e       d
0000040 151 162 057 144 151 162 057 164 145 163 164 040 062 012 144 151
          i   r   /   d   i   r   /   t   e   s   t       2  \n   d   i
0000060 162 156 141 155 145 040 144 151 162 057 144 151 162 057 164 145
          r   n   a   m   e       d   i   r   /   d   i   r   /   t   e
0000100 163 164 040 063 012
          s   t       3  \n
0000105
xz@xiaqiu:~/study/niao-linux$ 

touch text.txt 则该文件的三个时间 (atime/ctime/mtime) 都会更新为目前的时间


xz@xiaqiu:~/study/niao-linux$ date; ls -l text.txt ; ls -l --time=atime text.txt ;  ls -l --time=ctime text.txt 
20220108日 星期六 16:04:10 CST
-rw-rw-r-- 1 xz xz 69 18 15:37 text.txt
-rw-rw-r-- 1 xz xz 69 18 15:37 text.txt
-rw-rw-r-- 1 xz xz 69 18 15:37 text.txt
xz@xiaqiu:~/study/niao-linux$ touch text.txt
xz@xiaqiu:~/study/niao-linux$ date; ls -l text.txt ; ls -l --time=atime text.txt ;  ls -l --time=ctime text.txt 
20220108日 星期六 16:04:26 CST
-rw-rw-r-- 1 xz xz 69 18 16:04 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:04 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:04 text.txt
xz@xiaqiu:~/study/niao-linux$ 

touch -d “2 days ago” 将日期调整为两天前


xz@xiaqiu:~/study/niao-linux$ date; ls -l text.txt ; ls -l --time=atime text.txt ;  ls -l --time=ctime text.txt 
20220108日 星期六 16:06:13 CST
-rw-rw-r-- 1 xz xz 69 18 16:04 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:04 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:04 text.txt
xz@xiaqiu:~/study/niao-linux$ touch -d "2 days ago" text.txt 
xz@xiaqiu:~/study/niao-linux$ date; ls -l text.txt ; ls -l --time=atime text.txt ;  ls -l --time=ctime text.txt 
20220108日 星期六 16:06:28 CST
-rw-rw-r-- 1 xz xz 69 16 16:06 text.txt
-rw-rw-r-- 1 xz xz 69 16 16:06 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:06 text.txt
xz@xiaqiu:~/study/niao-linux$ 

touch -t 202101010101 text.txt将 text.txt 日期改为 2021/01/01 1:01


xz@xiaqiu:~/study/niao-linux$ date; ls -l text.txt ; ls -l --time=atime text.txt ;  ls -l --time=ctime text.txt 
20220108日 星期六 16:08:46 CST
-rw-rw-r-- 1 xz xz 69 16 16:06 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:06 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:06 text.txt
xz@xiaqiu:~/study/niao-linux$ touch -t 202101010101 text.txt
xz@xiaqiu:~/study/niao-linux$ date; ls -l text.txt ; ls -l --time=atime text.txt ;  ls -l --time=ctime text.txt 
20220108日 星期六 16:08:52 CST
-rw-rw-r-- 1 xz xz 69 11  2021 text.txt
-rw-rw-r-- 1 xz xz 69 11  2021 text.txt
-rw-rw-r-- 1 xz xz 69 18 16:08 text.txt
xz@xiaqiu:~/study/niao-linux$ 

umask 文件默认权限


root@xiaqiu:/home/xz/study/niao-linux# umask
0022
root@xiaqiu:/home/xz/study/niao-linux# exit
exit
xz@xiaqiu:~/study/niao-linux$ umask
0002
xz@xiaqiu:~/study/niao-linux$ 

umask -S 符号类型的方式来显示出权限


xz@xiaqiu:~/study/niao-linux$ umask -S
u=rwx,g=rwx,o=rx
xz@xiaqiu:~/study/niao-linux$ 

chattr 设置文件隐藏属性

chattr +i text.txt 让一个文件“不能被删除、改名、设置链接也无法写入或新增数据!”!只有 root 能设置此属性


xz@xiaqiu:~/study/niao-linux$ touch text.txt
xz@xiaqiu:~/study/niao-linux$ chattr +i text.txt 
chattr: 不允许的操作 设置 text.txt 的标志时
xz@xiaqiu:~/study/niao-linux$ sudo chattr +i text.txt 
xz@xiaqiu:~/study/niao-linux$ sudo rm text.txt 
rm: 无法删除 'text.txt': 不允许的操作
xz@xiaqiu:~/study/niao-linux$ sudo chattr -i text.txt 
xz@xiaqiu:~/study/niao-linux$ rm text.txt 
xz@xiaqiu:~/study/niao-linux$ ls
dir  readme.md
xz@xiaqiu:~/study/niao-linux$ 

lsattr 显示文件隐藏属性


xz@xiaqiu:~/study/niao-linux$ lsattr
--------------e----- ./dir
--------------e----- ./readme.md
--------------e----- ./text.txt
xz@xiaqiu:~/study/niao-linux$ chattr +aiS text.txt 
chattr: 不允许的操作 设置 text.txt 的标志时
xz@xiaqiu:~/study/niao-linux$ sudo chattr +aiS text.txt 
xz@xiaqiu:~/study/niao-linux$ lsattr
--------------e----- ./dir
--------------e----- ./readme.md
--S-ia--------e----- ./text.txt
xz@xiaqiu:~/study/niao-linux$ 

文件特殊权限: SUID, SGID, SBIT

file 观察文件类型


xz@xiaqiu:~/study/niao-linux$ file text.txt 
text.txt: ASCII text
xz@xiaqiu:~/study/niao-linux$ 
xz@xiaqiu:~/study/niao-linux$ file /usr/bin/passwd
/usr/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=fa23c6b4e145d9bb5487c6cb7adb9338c5ef4fb9, for GNU/Linux 3.2.0, stripped
xz@xiaqiu:~/study/niao-linux$ 

which 寻找“可执行文件”


xz@xiaqiu:~/study/niao-linux$ which ls
/usr/bin/ls
xz@xiaqiu:~/study/niao-linux$ which cd
xz@xiaqiu:~/study/niao-linux$ which file
/usr/bin/file
xz@xiaqiu:~/study/niao-linux$ which cmake
/usr/bin/cmake
xz@xiaqiu:~/study/niao-linux$ 

whereis 特定的目录中寻找文件文件名


xz@xiaqiu:~/study/niao-linux$ whereis ifconfig
ifconfig: /usr/sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
xz@xiaqiu:~/study/niao-linux$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
xz@xiaqiu:~/study/niao-linux$ 

find . -mtime 0 将 24 小时内有更动过内容 (mtime) 的文件列出


xz@xiaqiu:~/study/niao-linux$ find . -mtime 0
.
./.test
./dir
./dir/dir
./dir/dir/test
./readme.md
./readme.md.save
./text.txt
xz@xiaqiu:~/study/niao-linux$ 

find . -user xz 搜寻 . 下面属于 xz 的文件


xz@xiaqiu:~/study/niao-linux$ sudo touch root.txt
xz@xiaqiu:~/study/niao-linux$ ls -l
总用量 68
drwxrwxr-x 3 xz   xz    4096 18 15:34 dir
-rw-rw-r-- 1 xz   xz   35203 18 16:30 readme.md
-rw-rw-r-- 1 xz   xz   24408 18 16:40 readme.md.save
-rw-r--r-- 1 root root     0 18 16:47 root.txt
-rw-rw-r-- 1 xz   xz       5 18 16:30 text.txt
xz@xiaqiu:~/study/niao-linux$ find . -user xz
.
./.test
./dir
./dir/dir
./dir/dir/test
./readme.md
./readme.md.save
./text.txt
xz@xiaqiu:~/study/niao-linux$ find . -user root
./root.txt
xz@xiaqiu:~/study/niao-linux$ 

find . -name text.txt 找出文件名为 text.txt 这个文件


xz@xiaqiu:~/study/niao-linux$ find . -name text.txt
./text.txt
xz@xiaqiu:~/study/niao-linux$ 

find . -name “text” 找出文件名包含了 text 这个关键字的文件


xz@xiaqiu:~/study/niao-linux$ find . -name "*text*"
./text.txt
xz@xiaqiu:~/study/niao-linux$ cat text.txt 
test
text
xz@xiaqiu:~/study/niao-linux$ 

find /run -type s 找出 /run 目录下,文件类型为 Socket 的文件名有哪些?


xz@xiaqiu:~/study/niao-linux$ sudo find /run -type s
/run/wpa_supplicant/p2p-dev-wlp4s0
/run/wpa_supplicant/wlp4s0
/run/docker.sock
/run/snap.docker/libnetwork/c646655678bd.sock
/run/snap.docker/metrics.sock
/run/snap.docker/containerd/containerd.sock
/run/snap.docker/containerd/containerd.sock.ttrpc
/run/snap.docker/containerd/containerd-debug.sock
/run/mysqld/mysqld.sock
/run/irqbalance/irqbalance798.sock
/run/uuidd/request
/run/snapd-snap.socket
/run/snapd.socket
/run/dbus/system_bus_socket
/run/cups/cups.sock
/run/avahi-daemon/socket
/run/acpid.socket
find:/run/user/1000/doc’: 权限不够
/run/user/1000/keyring/ssh
/run/user/1000/keyring/pkcs11
/run/user/1000/keyring/control
find:/run/user/1000/gvfs’: 权限不够
/run/user/1000/snapd-session-agent.socket
/run/user/1000/pulse/native
/run/user/1000/pk-debconf-socket
/run/user/1000/gnupg/S.gpg-agent
/run/user/1000/gnupg/S.gpg-agent.ssh
/run/user/1000/gnupg/S.gpg-agent.extra
/run/user/1000/gnupg/S.gpg-agent.browser
/run/user/1000/gnupg/S.dirmngr
/run/user/1000/bus
/run/user/1000/systemd/private
/run/user/1000/systemd/notify
/run/user/1000/inaccessible/sock
/run/systemd/fsck.progress
/run/systemd/journal/io.systemd.journal
/run/systemd/journal/socket
/run/systemd/journal/stdout
/run/systemd/journal/dev-log
/run/systemd/journal/syslog
/run/systemd/userdb/io.systemd.DynamicUser
/run/systemd/private
/run/systemd/notify
/run/systemd/inaccessible/sock
/run/lvm/lvmpolld.socket
/run/udev/control
xz@xiaqiu:~/study/niao-linux$ 

blkid 目前系统有被格式化的设备


xz@xiaqiu:~/study/niao-linux$ blkid
/dev/mapper/vgubuntu-swap_1: UUID="21509530-1d44-48ad-ac10-baf3f4046c82" TYPE="swap"
/dev/mapper/vgubuntu-root: UUID="a364734f-64ad-4663-b32e-a94c88e66549" TYPE="ext4"
xz@xiaqiu:~/study/niao-linux$ 

dumpe2fs 查询 Ext 家族 superblock 信息的指令


xz@xiaqiu:~/study/niao-linux$ sudo dumpe2fs /dev/mapper/vgubuntu-root 
Filesystem volume name:   <none>
Last mounted on:          /
Filesystem UUID:          a364734f-64ad-4663-b32e-a94c88e66549
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              30433280
Block count:              121713664
Reserved block count:     6085683
Free blocks:              49700133
Free inodes:              27912381
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Fri Jul  9 16:35:59 2021
Last mount time:          Fri Jan  7 19:16:10 2022
Last write time:          Fri Jan  7 19:15:29 2022
Mount count:              378
Maximum mount count:      -1
Last checked:             Fri Jul  9 16:35:59 2021
Check interval:           0 (<none>)
Lifetime writes:          381 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
First orphan inode:       10092559
Default directory hash:   half_md4
Directory Hash Seed:      b97f2536-4582-475b-a06e-bb616edc3c7a
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x667ba522
Journal features:         journal_incompat_revoke journal_64bit journal_checksum_v3
Journal size:             1024M
Journal length:           262144
Journal sequence:         0x0027b20c
Journal start:            1
Journal checksum type:    crc32c
Journal checksum:         0x7b4567900(0-32767) 校验值 0x7566 [ITABLE_ZEROED]
  主 超级块位于 0,组描述符位于 1-59
  保留的GDT块位于 60-1083
  块位图位于 1084 (+1084),校验值 0xb2e3cb72
  Inode 位图位于 1100 (+1100),校验值 0x7814ec52
  Inode表位于 1116-1627 (+1116)
  11356 个可用 块,0 个可用inode,646 个目录 
  可用块数: 11776-15615, 15715-15743, 20480-24575, 26624-28667, 28672-29695, 32445-32767
  可用inode数: 
组 1(32768-65535) 校验值 0x7dd0 [ITABLE_ZEROED]
  备份 超级块位于 32768,组描述符位于 32769-32827
  保留的GDT块位于 32828-33851
  块位图位于 1085 (bg #0 + 1085),校验值 0xf47318da
  Inode 位图位于 1101 (bg #0 + 1101),校验值 0x7814ec52
  Inode表位于 1628-2139 (bg #0 + 1628)
  18737 个可用 块,0 个可用inode,680 个目录 
  可用块数: 36864-39935, 41163, 41168-41471, 41984-43007, 51200-65535
  可用inode数: 
...

ls -li 查看 inode 号码


xz@xiaqiu:~/study/niao-linux$ ls -li
总用量 2640
15861363 drwxrwxr-x 3 xz   xz      4096 18 15:34 dir
15865767 -rw-rw-r-- 1 xz   xz   2632086 18 16:58 dsk.txt
15861477 -rw-rw-r-- 1 xz   xz     35203 18 16:30 readme.md
15861582 -rw-rw-r-- 1 xz   xz     24408 18 16:40 readme.md.save
15861597 -rw-r--r-- 1 root root       0 18 16:47 root.txt
15861479 -rw-rw-r-- 1 xz   xz        10 18 16:50 text.txt
xz@xiaqiu:~/study/niao-linux$ 

df:列出文件系统的整体磁盘使用量;


xz@xiaqiu:~/study/niao-linux$ df
文件系统                      1K-块      已用      可用 已用% 挂载点
udev                        1933888         0   1933888    0% /dev
tmpfs                        393740      2232    391508    1% /run
/dev/mapper/vgubuntu-root 478163720 279492528 174312076   62% /
tmpfs                       1968696       432   1968264    1% /dev/shm
tmpfs                          5120         4      5116    1% /run/lock
tmpfs                       1968696         0   1968696    0% /sys/fs/cgroup
/dev/loop0                      128       128         0  100% /snap/bare/5
/dev/loop3                    56832     56832         0  100% /snap/core18/2246
/dev/loop2                   101888    101888         0  100% /snap/core/11993
/dev/loop5                    56832     56832         0  100% /snap/core18/2253
/dev/loop6                    63488     63488         0  100% /snap/core20/1270
/dev/loop1                   101888    101888         0  100% /snap/core/11798
/dev/loop4                    63360     63360         0  100% /snap/core20/1242
/dev/loop7                   119424    119424         0  100% /snap/docker/1125
/dev/loop8                   134784    134784         0  100% /snap/docker/796
/dev/loop9                   119808    119808         0  100% /snap/drawio/137
/dev/loop11                  168832    168832         0  100% /snap/gnome-3-28-1804/161
/dev/loop12                  224256    224256         0  100% /snap/gnome-3-34-1804/77
/dev/loop10                  119808    119808         0  100% /snap/drawio/138
/dev/loop14                     256       256         0  100% /snap/gtk2-common-themes/13
/dev/loop13                  224256    224256         0  100% /snap/gnome-3-34-1804/72
/dev/loop15                   66688     66688         0  100% /snap/gtk-common-themes/1515
/dev/loop16                  253952    253952         0  100% /snap/gnome-3-38-2004/87
/dev/loop17                   52224     52224         0  100% /snap/snap-store/547
/dev/loop18                  114048    114048         0  100% /snap/shutter/27
/dev/loop19                   43264     43264         0  100% /snap/snapd/14066
/dev/loop21                   44416     44416         0  100% /snap/snapd/14295
/dev/loop23                   55552     55552         0  100% /snap/snap-store/558
/dev/loop20                   66816     66816         0  100% /snap/gtk-common-themes/1519
/dev/loop24                    4352      4352         0  100% /snap/tree/18
/dev/loop25                   91008     91008         0  100% /snap/typora/46
/dev/loop22                   90880     90880         0  100% /snap/typora/42
/dev/sda1                    523248      8036    515212    2% /boot/efi
tmpfs                        393736       588    393148    1% /run/user/1000
xz@xiaqiu:~/study/niao-linux$ 


df -h 以 G/M 等容量格式显示出来


xz@xiaqiu:~/study/niao-linux$ df -h
]文件系统                   容量  已用  可用 已用% 挂载点
udev                       1.9G     0  1.9G    0% /dev
tmpfs                      385M  2.2M  383M    1% /run
/dev/mapper/vgubuntu-root  457G  267G  167G   62% /
tmpfs                      1.9G  432K  1.9G    1% /dev/shm
tmpfs                      5.0M  4.0K  5.0M    1% /run/lock
tmpfs                      1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/loop0                 128K  128K     0  100% /snap/bare/5
/dev/loop3                  56M   56M     0  100% /snap/core18/2246
/dev/loop2                 100M  100M     0  100% /snap/core/11993
/dev/loop5                  56M   56M     0  100% /snap/core18/2253
/dev/loop6                  62M   62M     0  100% /snap/core20/1270
/dev/loop1                 100M  100M     0  100% /snap/core/11798
/dev/loop4                  62M   62M     0  100% /snap/core20/1242
/dev/loop7                 117M  117M     0  100% /snap/docker/1125
/dev/loop8                 132M  132M     0  100% /snap/docker/796
/dev/loop9                 117M  117M     0  100% /snap/drawio/137
/dev/loop11                165M  165M     0  100% /snap/gnome-3-28-1804/161
/dev/loop12                219M  219M     0  100% /snap/gnome-3-34-1804/77
/dev/loop10                117M  117M     0  100% /snap/drawio/138
/dev/loop14                256K  256K     0  100% /snap/gtk2-common-themes/13
/dev/loop13                219M  219M     0  100% /snap/gnome-3-34-1804/72
/dev/loop15                 66M   66M     0  100% /snap/gtk-common-themes/1515
/dev/loop16                248M  248M     0  100% /snap/gnome-3-38-2004/87
/dev/loop17                 51M   51M     0  100% /snap/snap-store/547
/dev/loop18                112M  112M     0  100% /snap/shutter/27
/dev/loop19                 43M   43M     0  100% /snap/snapd/14066
/dev/loop21                 44M   44M     0  100% /snap/snapd/14295
/dev/loop23                 55M   55M     0  100% /snap/snap-store/558
/dev/loop20                 66M   66M     0  100% /snap/gtk-common-themes/1519
/dev/loop24                4.3M  4.3M     0  100% /snap/tree/18
/dev/loop25                 89M   89M     0  100% /snap/typora/46
/dev/loop22                 89M   89M     0  100% /snap/typora/42
/dev/sda1                  511M  7.9M  504M    2% /boot/efi
tmpfs                      385M  588K  384M    1% /run/user/1000
xz@xiaqiu:~/study/niao-linux$ 



df -aT 将系统内的所有特殊文件格式及名称都列出来


xz@xiaqiu:~/study/niao-linux$ df -aT 
文件系统                  类型                1K-块      已用      可用 已用% 挂载点
sysfs                     sysfs                   0         0         0     - /sys
proc                      proc                    0         0         0     - /proc
udev                      devtmpfs          1933888         0   1933888    0% /dev
devpts                    devpts                  0         0         0     - /dev/pts
tmpfs                     tmpfs              393740      2232    391508    1% /run
/dev/mapper/vgubuntu-root ext4            478163720 279491892 174312712   62% /
securityfs                securityfs              0         0         0     - /sys/kernel/security
tmpfs                     tmpfs             1968696       432   1968264    1% /dev/shm
tmpfs                     tmpfs                5120         4      5116    1% /run/lock
tmpfs                     tmpfs             1968696         0   1968696    0% /sys/fs/cgroup
cgroup2                   cgroup2                 0         0         0     - /sys/fs/cgroup/unified
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/systemd
pstore                    pstore                  0         0         0     - /sys/fs/pstore
efivarfs                  efivarfs                0         0         0     - /sys/firmware/efi/efivars
none                      bpf                     0         0         0     - /sys/fs/bpf
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/rdma
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/pids
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/hugetlb
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/blkio
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/cpu,cpuacct
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/cpuset
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/perf_event
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/net_cls,net_prio
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/memory
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/freezer
cgroup                    cgroup                  0         0         0     - /sys/fs/cgroup/devices
systemd-1                 -                       -         -         -     - /proc/sys/fs/binfmt_misc
tracefs                   tracefs                 0         0         0     - /sys/kernel/tracing
hugetlbfs                 hugetlbfs               0         0         0     - /dev/hugepages
mqueue                    mqueue                  0         0         0     - /dev/mqueue
debugfs                   debugfs                 0         0         0     - /sys/kernel/debug
/dev/loop0                squashfs              128       128         0  100% /snap/bare/5
/dev/loop3                squashfs            56832     56832         0  100% /snap/core18/2246
/dev/loop2                squashfs           101888    101888         0  100% /snap/core/11993
/dev/loop5                squashfs            56832     56832         0  100% /snap/core18/2253
/dev/loop6                squashfs            63488     63488         0  100% /snap/core20/1270
/dev/loop1                squashfs           101888    101888         0  100% /snap/core/11798
/dev/loop4                squashfs            63360     63360         0  100% /snap/core20/1242
/dev/loop7                squashfs           119424    119424         0  100% /snap/docker/1125
/dev/loop8                squashfs           134784    134784         0  100% /snap/docker/796
/dev/loop9                squashfs           119808    119808         0  100% /snap/drawio/137
/dev/loop11               squashfs           168832    168832         0  100% /snap/gnome-3-28-1804/161
/dev/loop12               squashfs           224256    224256         0  100% /snap/gnome-3-34-1804/77
fusectl                   fusectl                 0         0         0     - /sys/fs/fuse/connections
configfs                  configfs                0         0         0     - /sys/kernel/config
/dev/loop10               squashfs           119808    119808         0  100% /snap/drawio/138
/dev/loop14               squashfs              256       256         0  100% /snap/gtk2-common-themes/13
/dev/loop13               squashfs           224256    224256         0  100% /snap/gnome-3-34-1804/72
/dev/loop15               squashfs            66688     66688         0  100% /snap/gtk-common-themes/1515
/dev/loop16               squashfs           253952    253952         0  100% /snap/gnome-3-38-2004/87
/dev/loop17               squashfs            52224     52224         0  100% /snap/snap-store/547
/dev/loop18               squashfs           114048    114048         0  100% /snap/shutter/27
/dev/loop19               squashfs            43264     43264         0  100% /snap/snapd/14066
/dev/loop21               squashfs            44416     44416         0  100% /snap/snapd/14295
/dev/loop23               squashfs            55552     55552         0  100% /snap/snap-store/558
/dev/loop20               squashfs            66816     66816         0  100% /snap/gtk-common-themes/1519
/dev/loop24               squashfs             4352      4352         0  100% /snap/tree/18
/dev/loop25               squashfs            91008     91008         0  100% /snap/typora/46
/dev/loop22               squashfs            90880     90880         0  100% /snap/typora/42
/dev/sda1                 vfat               523248      8036    515212    2% /boot/efi
binfmt_misc               binfmt_misc             0         0         0     - /proc/sys/fs/binfmt_misc
tmpfs                     tmpfs              393740      2232    391508    1% /run/snapd/ns
nsfs                      nsfs                    0         0         0     - /run/snapd/ns/docker.mnt
tmpfs                     tmpfs              393736       588    393148    1% /run/user/1000
gvfsd-fuse                fuse.gvfsd-fuse         0         0         0     - /run/user/1000/gvfs
/dev/fuse                 fuse                    0         0         0     - /run/user/1000/doc
nsfs                      nsfs                    0         0         0     - /run/snapd/ns/snap-store.mnt
nsfs                      nsfs                    0         0         0     - /run/snapd/ns/shutter.mnt
nsfs                      nsfs                    0         0         0     - /run/snapd/ns/typora.mnt
nsfs                      nsfs                    0         0         0     - /run/snapd/ns/tree.mnt
xz@xiaqiu:~/study/niao-linux$ 

df -h /etc 将 /etc 下面的可用的磁盘容量以易读的容量格式显示


xz@xiaqiu:~/study/niao-linux$ df -h /etc
文件系统                   容量  已用  可用 已用% 挂载点
/dev/mapper/vgubuntu-root  457G  267G  167G   62% /
xz@xiaqiu:~/study/niao-linux$ 

df -iH 将目前各个 partition 当中可用的 inode 数量列出


xz@xiaqiu:~/study/niao-linux$ sudo df -iH /etc
文件系统                  Inodes 已用(I) 可用(I) 已用(I)% 挂载点
/dev/mapper/vgubuntu-root    31M    2.6M     28M       9% /
xz@xiaqiu:~/study/niao-linux$ 

du 列出目前目录下的所有文件大小


xz@xiaqiu:~/study/niao-linux$ du
4  ./dir/dir
8  ./dir
2656  .
xz@xiaqiu:~/study/niao-linux$ 

du -a


xz@xiaqiu:~/study/niao-linux$ du -a
0  ./.test
0  ./dir/dir/test
4  ./dir/dir
8  ./dir
44 ./readme.md
24 ./readme.md.save
4  ./text.txt
2572  ./dsk.txt
0  ./root.txt
2656  .
xz@xiaqiu:~/study/niao-linux$ 

du -sm ./* 检查./目录下面每个目录所占用的容量


xz@xiaqiu:~/study/niao-linux$ du -sm ./*
1  ./dir
3  ./dsk.txt
1  ./readme.md
1  ./readme.md.save
0  ./root.txt
1  ./text.txt
xz@xiaqiu:~/study/niao-linux$ 

df 不一样的是,du 这个指令其实会直接到文件系统内去搜寻所有的文件数据, 所以上述第三个范例指令的运行会执行一小段时间

lsblk 观察磁盘分区状态


xz@xiaqiu:~/study/niao-linux$ lsblk
NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0                 7:0    0     4K  1 loop /snap/bare/5
loop1                 7:1    0  99.5M  1 loop /snap/core/11798
loop2                 7:2    0  99.4M  1 loop /snap/core/11993
loop3                 7:3    0  55.5M  1 loop /snap/core18/2246
loop4                 7:4    0  61.9M  1 loop /snap/core20/1242
loop5                 7:5    0  55.5M  1 loop /snap/core18/2253
loop6                 7:6    0  61.9M  1 loop /snap/core20/1270
loop7                 7:7    0 116.6M  1 loop /snap/docker/1125
loop8                 7:8    0 131.6M  1 loop /snap/docker/796
loop9                 7:9    0 116.9M  1 loop /snap/drawio/137
loop10                7:10   0 116.9M  1 loop /snap/drawio/138
loop11                7:11   0 164.8M  1 loop /snap/gnome-3-28-1804/161
loop12                7:12   0   219M  1 loop /snap/gnome-3-34-1804/77
loop13                7:13   0   219M  1 loop /snap/gnome-3-34-1804/72
loop14                7:14   0   140K  1 loop /snap/gtk2-common-themes/13
loop15                7:15   0  65.1M  1 loop /snap/gtk-common-themes/1515
loop16                7:16   0 247.9M  1 loop /snap/gnome-3-38-2004/87
loop17                7:17   0    51M  1 loop /snap/snap-store/547
loop18                7:18   0 111.3M  1 loop /snap/shutter/27
loop19                7:19   0  42.2M  1 loop /snap/snapd/14066
loop20                7:20   0  65.2M  1 loop /snap/gtk-common-themes/1519
loop21                7:21   0  43.3M  1 loop /snap/snapd/14295
loop22                7:22   0  88.8M  1 loop /snap/typora/42
loop23                7:23   0  54.2M  1 loop /snap/snap-store/558
loop24                7:24   0   4.2M  1 loop /snap/tree/18
loop25                7:25   0  88.9M  1 loop /snap/typora/46
sda                   8:0    0 465.8G  0 disk 
├─sda1                8:1    0   512M  0 part /boot/efi
└─sda2                8:2    0 465.3G  0 part 
  ├─vgubuntu-root   253:0    0 464.3G  0 lvm  /
  └─vgubuntu-swap_1 253:1    0   980M  0 lvm  [SWAP]
xz@xiaqiu:~/study/niao-linux$ 

lsblk -ip /dev/sda1 仅列出 /dev/sda1 设备内的所有数据的完整文件名


xz@xiaqiu:~/study/niao-linux$ lsblk -ip /dev/sda1
NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
/dev/sda1   8:1    0  512M  0 part /boot/efi
xz@xiaqiu:~/study/niao-linux$ 
xz@xiaqiu:~/study/niao-linux$ lsblk -ip /dev/sda2
NAME                          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
/dev/sda2                       8:2    0 465.3G  0 part 
|-/dev/mapper/vgubuntu-root   253:0    0 464.3G  0 lvm  /
`-/dev/mapper/vgubuntu-swap_1 253:1    0   980M  0 lvm  [SWAP]
xz@xiaqiu:~/study/niao-linux$ 

blkid 列出设备的 UUID 等参数


xz@xiaqiu:~/study/niao-linux$ blkid
/dev/mapper/vgubuntu-swap_1: UUID="21509530-1d44-48ad-ac10-baf3f4046c82" TYPE="swap"
/dev/mapper/vgubuntu-root: UUID="a364734f-64ad-4663-b32e-a94c88e66549" TYPE="ext4"
xz@xiaqiu:~/study/niao-linux$ 

sudo parted /dev/sda1 print 列出 /dev/sda1 磁盘的相关数据


xz@xiaqiu:~/study/niao-linux$ sudo parted /dev/sda1 print
型号:未知 (unknown)
磁盘 /dev/sda1: 537MB
扇区大小 (逻辑/物理)512B/4096B
分区表:loop
磁盘标志:

编号  起始点  结束点  大小   文件系统  标志
 1    0.00B   537MB   537MB  fat32

xz@xiaqiu:~/study/niao-linux$ 

time tar -zpcv -f dir.tar.gz dir 备份dir

由于加上 -v 这个选项,因此正在作用中的文件名就会显示在屏幕上

如果你可以翻到第一页,会发现出现上面的错误讯息!下面会讲解。

至于 -p 的选项,重点在于“保留原本文件的权限与属性”之意。


xz@xiaqiu:~/study/niao-linux$ time tar -zpcv -f dir.tar.gz dir
dir/
dir/dir/
dir/dir/test

real  0m0.071s
user  0m0.007s
sys   0m0.003s
xz@xiaqiu:~/study/niao-linux$ ls
dir  dir.tar.gz  dsk.txt  readme.md  readme.md.save  root.txt  text.txt
xz@xiaqiu:~/study/niao-linux$ ls -l dir.tar.gz 
-rw-rw-r-- 1 xz xz 156 18 17:24 dir.tar.gz
xz@xiaqiu:~/study/niao-linux$ 

source :读入环境配置文件的指令


xz@xiaqiu:~/study/niao-linux$ source ~/.bashrc 
xz@xiaqiu:~/study/niao-linux$ 

stty -a 将目前所有的 stty 参数列出来


xz@xiaqiu:~/study/niao-linux$ stty -a
speed 38400 baud; rows 24; columns 91; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany
-imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
-flusho -extproc
xz@xiaqiu:~/study/niao-linux$ 

echo $- 显示目前所有的 set 设置值


xz@xiaqiu:~/study/niao-linux$ echo $-
himBHs
xz@xiaqiu:~/study/niao-linux$ 

set -x 执行前,显示该指令内容


xz@xiaqiu:~/study/niao-linux$ set -x
xz@xiaqiu:~/study/niao-linux$ echo ${HOME}
+ echo /home/xz
/home/xz
xz@xiaqiu:~/study/niao-linux$ 

last 显示的登陆者的信息


xz       :0           :0               Fri Jan  7 20:44   still logged in
reboot   system boot  5.11.0-44-generi Fri Jan  7 19:16   still running
xz       :0           :0               Thu Jan  6 19:05 - crash (1+00:11)
reboot   system boot  5.11.0-44-generi Thu Jan  6 19:03   still running
xz       :0           :0               Wed Jan  5 18:34 - crash (1+00:28)
reboot   system boot  5.11.0-43-generi Wed Jan  5 18:27   still running
xz       :0           :0               Wed Jan  5 12:54 - down   (05:32)
reboot   system boot  5.11.0-43-generi Wed Jan  5 12:52 - 18:26  (05:34)
xz       :0           :0               Mon Jan  3 16:36 - crash (1+20:16)
reboot   system boot  5.11.0-43-generi Mon Jan  3 16:34 - 18:26 (2+01:52)
xz       :0           :0               Sun Jan  2 22:43 - down   (00:58)
reboot   system boot  5.11.0-43-generi Sun Jan  2 22:41 - 23:42  (01:00)
xz       :0           :0               Sun Jan  2 18:38 - crash  (04:02)
reboot   system boot  5.11.0-43-generi Sun Jan  2 18:36 - 23:42  (05:05)
reboot   system boot  5.11.0-43-generi Sun Jan  2 18:35 - 23:42  (05:07)
xz       :0           :0               Sun Jan  2 12:49 - crash  (05:45)
reboot   system boot  5.11.0-43-generi Sun Jan  2 12:46 - 23:42  (10:55)
xz       :0           :0               Sat Jan  1 18:22 - crash  (18:24)
reboot   system boot  5.11.0-43-generi Sat Jan  1 18:20 - 23:42 (1+05:21)
xz       :0           :0               Sat Jan  1 12:11 - crash  (06:08)
reboot   system boot  5.11.0-43-generi Sat Jan  1 12:10 - 23:42 (1+11:32)

grep


xz@xiaqiu:~/study/niao-linux$ last | grep "xz"
xz@xiaqiu:~/study/niao-linux$ last | grep "xz"
+ last
+ grep --color=auto xz
xz       :0           :0               Fri Jan  7 20:44   still logged in
xz       :0           :0               Thu Jan  6 19:05 - crash (1+00:11)
xz       :0           :0               Wed Jan  5 18:34 - crash (1+00:28)
xz       :0           :0               Wed Jan  5 12:54 - down   (05:32)
xz       :0           :0               Mon Jan  3 16:36 - crash (1+20:16)
xz       :0           :0               Sun Jan  2 22:43 - down   (00:58)
xz       :0           :0               Sun Jan  2 18:38 - crash  (04:02)
xz       :0           :0               Sun Jan  2 12:49 - crash  (05:45)
xz       :0           :0               Sat Jan  1 18:22 - crash  (18:24)
xz       :0           :0               Sat Jan  1 12:11 - crash  (06:08)
xz       :0           :0               Sat Jan  1 11:54 - crash  (00:15)
xz       :0           :0               Fri Dec 31 23:06 - crash  (12:45)
xz       :0           :0               Wed Dec 29 19:51 - crash (2+03:13)
xz       :0           :0               Wed Dec 29 15:36 - crash  (04:10)
xz       :0           :0               Tue Dec 28 15:09 - crash (1+00:25)
xz       :0           :0               Sat Dec 25 12:44 - down  (2+21:01)
xz       :0           :0               Thu Dec 23 08:43 - down  (1+14:04)
xz       :0           :0               Tue Dec 21 14:49 - down  (1+09:34)
xz       :0           :0               Mon Dec 20 17:00 - crash  (21:47)
xz       :0           :0               Sun Dec 19 10:03 - crash (1+06:55)
xz       :0           :0               Sat Dec 18 11:35 - crash  (22:26)
xz       :0           :0               Fri Dec 17 13:50 - down   (10:21)
xz       :0           :0               Thu Dec 16 18:37 - down   (05:21)
xz       :0           :0               Wed Dec 15 16:28 - crash (1+02:02)
xz       :0           :0               Tue Dec 14 22:40 - down   (01:30)
xz       :0           :0               Tue Dec 14 18:20 - crash  (04:18)
xz       :0           :0               Tue Dec 14 12:54 - crash  (05:24)
xz       :0           :0               Mon Dec 13 12:18 - crash (1+00:34)
xz       :0           :0               Sun Dec 12 10:51 - crash (1+01:03)
xz       :0           :0               Sat Dec 11 23:39 - down   (00:22)
xz       :0           :0               Fri Dec 10 14:50 - down  (1+08:44)
xz       :0           :0               Fri Dec 10 14:05 - crash  (00:43)
xz       :0           :0               Thu Dec  9 14:25 - crash  (23:37)
xz       :0           :0               Tue Dec  7 11:04 - down  (2+03:18)
xz       :0           :0               Mon Dec  6 10:43 - crash (1+00:18)
xz       :0           :0               Sun Dec  5 22:30 - down   (01:34)
xz       :0           :0               Sat Dec  4 13:59 - crash (1+08:29)

cat /etc/passwd | sort 个人帐号都记录在 /etc/passwd 下,请将帐号进行排序


xz@xiaqiu:~/study/niao-linux$ cat /etc/passwd | sort
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
avahi-autoipd:x:109:116:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/usr/sbin/nologin
avahi:x:115:121:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
colord:x:121:126:colord colour management daemon,,,:/var/lib/colord:/usr/sbin/nologin
cups-pk-helper:x:113:120:user for cups-pk-helper service,,,:/home/cups-pk-helper:/usr/sbin/nologin
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin
games:x:5:60:games:/usr/games:/usr/sbin/nologin
gdm:x:125:130:Gnome Display Manager:/var/lib/gdm3:/bin/false
geoclue:x:122:127::/var/lib/geoclue:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
gnome-initial-setup:x:124:65534::/run/gnome-initial-setup/:/bin/false
hplip:x:119:7:HPLIP system user,,,:/run/hplip:/bin/false
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin

cat /etc/passwd || sort -t ‘:’ -k 3 /etc/passwd 内容是以 : 来分隔的,我想以第三栏来排序


xz@xiaqiu:~/study/niao-linux$ cat /etc/passwd || sort -t ':' -k 3
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin


uniq 将重复的数据仅列出一个显示

cat text.txt | wc 统计里面到底有多少相关字、行、字符数


xz@xiaqiu:~/study/niao-linux$ cat text.txt | wc
      2       2      10
xz@xiaqiu:~/study/niao-linux$ 

tee 双向重导向

last | tee last.list | cut -d " " -f1 让 last 的输出存一份到 last.list 文件中


xz@xiaqiu:~/study/niao-linux$ last | tee last.list | cut -d " " -f1
xz
reboot
xz
reboot
xz
reboot
xz
reboot
xz
reboot
xz
reboot
...
xz@xiaqiu:~/study/niao-linux$ ls last.list 
last.list
xz@xiaqiu:~/study/niao-linux$ cat last.list 
xz       :0           :0               Fri Jan  7 20:44   still logged in
reboot   system boot  5.11.0-44-generi Fri Jan  7 19:16   still running
xz       :0           :0               Thu Jan  6 19:05 - crash (1+00:11)
reboot   system boot  5.11.0-44-generi Thu Jan  6 19:03   still running
xz       :0           :0               Wed Jan  5 18:34 - crash (1+00:28)
reboot   system boot  5.11.0-43-generi Wed Jan  5 18:27   still running
xz       :0           :0               Wed Jan  5 12:54 - down   (05:32)
reboot   system boot  5.11.0-43-generi Wed Jan  5 12:52 - 18:26  (05:34)

ls -l | tee ./ls.list | more 将 ls 的数据存一份到 ls.list ,同时屏幕也有输出讯息


xz@xiaqiu:~/study/niao-linux$ ls -l | tee  ./ls.list | more
总用量 2736
drwxrwxr-x 3 xz   xz      4096 18 15:34 dir
-rw-rw-r-- 1 xz   xz       156 18 17:24 dir.tar.gz
-rw-rw-r-- 1 xz   xz   2632086 18 16:58 dsk.txt
-rw-rw-r-- 1 xz   xz     54731 18 17:57 last.list
-rw-rw-r-- 1 xz   xz     70561 18 17:59 readme.md
-rw-rw-r-- 1 xz   xz     24408 18 16:40 readme.md.save
-rw-r--r-- 1 root root       0 18 16:47 root.txt
-rw-rw-r-- 1 xz   xz        10 18 16:50 text.txt
xz@xiaqiu:~/study/niao-linux$ ls ls.list 
ls.list
xz@xiaqiu:~/study/niao-linux$ cat ls.list 
总用量 2736
drwxrwxr-x 3 xz   xz      4096 18 15:34 dir
-rw-rw-r-- 1 xz   xz       156 18 17:24 dir.tar.gz
-rw-rw-r-- 1 xz   xz   2632086 18 16:58 dsk.txt
-rw-rw-r-- 1 xz   xz     54731 18 17:57 last.list
-rw-rw-r-- 1 xz   xz     70561 18 17:59 readme.md
-rw-rw-r-- 1 xz   xz     24408 18 16:40 readme.md.save
-rw-r--r-- 1 root root       0 18 16:47 root.txt
-rw-rw-r-- 1 xz   xz        10 18 16:50 text.txt
xz@xiaqiu:~/study/niao-linux$ 


tr 删除 替换

last | tr ‘[a-z]’ ‘[A-Z]’ 将 last输出小写替换大写


xz@xiaqiu:~/study/niao-linux$ last | tr '[a-z]' '[A-Z]'
XZ       :0           :0               FRI JAN  7 20:44   STILL LOGGED IN
REBOOT   SYSTEM BOOT  5.11.0-44-GENERI FRI JAN  7 19:16   STILL RUNNING
XZ       :0           :0               THU JAN  6 19:05 - CRASH (1+00:11)
REBOOT   SYSTEM BOOT  5.11.0-44-GENERI THU JAN  6 19:03   STILL RUNNING
XZ       :0           :0               WED JAN  5 18:34 - CRASH (1+00:28)
REBOOT   SYSTEM BOOT  5.11.0-43-GENERI WED JAN  5 18:27   STILL RUNNING
XZ       :0           :0               WED JAN  5 12:54 - DOWN   (05:32)
REBOOT   SYSTEM BOOT  5.11.0-43-GENERI WED JAN  5 12:52 - 18:26  (05:34)
XZ       :0           :0               MON JAN  3 16:36 - CRASH (1+20:16)
REBOOT   SYSTEM BOOT  5.11.0-43-GENERI MON JAN  3 16:34 - 18:26 (2+01:52)
XZ       :0           :0               SUN JAN  2 22:43 - DOWN   (00:58)
REBOOT   SYSTEM BOOT  5.11.0-43-GENERI SUN JAN  2 22:41 - 23:42  (01:00)
XZ       :0           :0               SUN JAN  2 18:38 - CRASH  (04:02)
REBOOT   SYSTEM BOOT  5.11.0-43-GENERI SUN JAN  2 18:36 - 23:42  (05:05)
REBOOT   SYSTEM BOOT  5.11.0-43-GENERI SUN JAN  2 18:35 - 23:42  (05:07)
XZ       :0           :0               SUN JAN  2 12:49 - CRASH  (05:45)
REBOOT   SYSTEM BOOT  5.11.0-43-GENERI SUN JAN  2 12:46 - 23:42  (10:55)
XZ       :0           :0               SAT JAN  1 18:22 - CRASH  (18:24)

...

cat /etc/passwd | tr -d ‘:’ 将 /etc/passwd 输出中将冒号 (:) 删除


xz@xiaqiu:~/study/niao-linux$ cat /etc/passwd | tr -d ':'
rootx00root/root/bin/bash
daemonx11daemon/usr/sbin/usr/sbin/nologin
binx22bin/bin/usr/sbin/nologin
sysx33sys/dev/usr/sbin/nologin
syncx465534sync/bin/bin/sync
gamesx560games/usr/games/usr/sbin/nologin
manx612man/var/cache/man/usr/sbin/nologin
lpx77lp/var/spool/lpd/usr/sbin/nologin
mailx88mail/var/mail/usr/sbin/nologin
newsx99news/var/spool/news/usr/sbin/nologin
uucpx1010uucp/var/spool/uucp/usr/sbin/nologin
proxyx1313proxy/bin/usr/sbin/nologin
www-datax3333www-data/var/www/usr/sbin/nologin
backupx3434backup/var/backups/usr/sbin/nologin
listx3838Mailing List Manager/var/list/usr/sbin/nologin
ircx3939ircd/var/run/ircd/usr/sbin/nologin
gnatsx4141Gnats Bug-Reporting System (admin)/var/lib/gnats/usr/sbin/nologin
...

join 有 “相同数据” 的那一行,才将他加在一起


xz@xiaqiu:~/study/niao-linux$ head -n 3 text.txt text1.txt 
==> text.txt <==
test:100
text1:300

==> text1.txt <==
test:200
text3:100
xz@xiaqiu:~/study/niao-linux$ join -t ':' text.txt text1.txt | head -n 3
test:100:200
xz@xiaqiu:~/study/niao-linux$ 

paste text.txt text1.txt 将两行贴在一起,且中间以 [tab] 键隔开


xz@xiaqiu:~/study/niao-linux$ head -n 3 text.txt text1.txt 
==> text.txt <==
test:100
text1:300

==> text1.txt <==
test:200
text3:100
xz@xiaqiu:~/study/niao-linux$ paste text.txt text1.txt 
test:100    test:200
text1:300   text3:100
xz@xiaqiu:~/study/niao-linux$ 

split 文件split


xz@xiaqiu:~/study/niao-linux$ split -b 50 dir.tar.gz dir.tar.gz 
xz@xiaqiu:~/study/niao-linux$ ls -l dir.tar.gz*
-rw-rw-r-- 1 xz xz 156 18 17:24 dir.tar.gz
-rw-rw-r-- 1 xz xz  50 18 18:29 dir.tar.gzaa
-rw-rw-r-- 1 xz xz  50 18 18:29 dir.tar.gzab
-rw-rw-r-- 1 xz xz  50 18 18:29 dir.tar.gzac
-rw-rw-r-- 1 xz xz   6 18 18:29 dir.tar.gzad
xz@xiaqiu:~/study/niao-linux$ 


cat dir.tar.gza* >> dir.tar.gz.bak 将上面的三个小文件合成一个文件


xz@xiaqiu:~/study/niao-linux$ cat dir.tar.gza* >> dir.tar.gz.bak
xz@xiaqiu:~/study/niao-linux$ ls dir.tar.gz.bak -l
-rw-rw-r-- 1 xz xz 156 18 18:33 dir.tar.gz.bak
xz@xiaqiu:~/study/niao-linux$ 

grep -n “test” text.txt 搜寻特定字串


xz@xiaqiu:~/study/niao-linux$ cat text.txt 
test:100 
text1:300
test:300
test:400
test:700
test:600
test:500
xz@xiaqiu:~/study/niao-linux$ grep -n "test" text.txt 
1:test:100 
3:test:300
4:test:400
5:test:700
6:test:600
7:test:500
xz@xiaqiu:~/study/niao-linux$ 

grep -vn “test” text.txt 当该行没有 ‘test’ 这个字串时才显示在屏幕上


xz@xiaqiu:~/study/niao-linux$ cat text.txt 
test:100 
text1:300
test:300
test:400
test:700
test:600
test:500
xz@xiaqiu:~/study/niao-linux$ grep -vn "test" text.txt 
2:text1:300
xz@xiaqiu:~/study/niao-linux$ 

grep -n “te[sx]t” text.txt 利用中括号 [] 来搜寻集合字符


xz@xiaqiu:~/study/niao-linux$ grep -n "te[sx]t" text.txt 
1:test:100 
2:text1:300
3:test:300
4:test:400
5:test:700
6:test:600
7:test:500
xz@xiaqiu:~/study/niao-linux$ 

grep -n “[^a]test” text.txt


xz@xiaqiu:~/study/niao-linux$ grep -n "test" text.txt 
1:atest:100 
3:atest:300
4:btest:400
5:btest:700
6:btest:600
7:btest:500
xz@xiaqiu:~/study/niao-linux$ grep -n "[^a]test" text.txt 
4:btest:400
5:btest:700
6:btest:600
7:btest:500
xz@xiaqiu:~/study/niao-linux$ grep -n "[^b]test" text.txt 
1:atest:100 
3:atest:300
xz@xiaqiu:~/study/niao-linux$ 

grep -n “[^a-z]test” text.txt


xz@xiaqiu:~/study/niao-linux$ cat text.txt 
atest:100 
atext1:300
atest:300
btest:400
btest:700
btest:600
btest:500
Atest:100 
Atext1:300
Btest:300
Btest:400
1test:700
2test:600
~test:500
xz@xiaqiu:~/study/niao-linux$ grep -n "[^a-z]test" text.txt 
8:Atest:100 
10:Btest:300
11:Btest:400
12:1test:700
13:2test:600
14:~test:500
xz@xiaqiu:~/study/niao-linux$ grep -n "[^A-Z]test" text.txt 
1:atest:100 
3:atest:300
4:btest:400
5:btest:700
6:btest:600
7:btest:500
12:1test:700
13:2test:600
14:~test:500
xz@xiaqiu:~/study/niao-linux$ grep -n "[^0-9]test" text.txt 
1:atest:100 
3:atest:300
4:btest:400
5:btest:700
6:btest:600
7:btest:500
8:Atest:100 
10:Btest:300
11:Btest:400
14:~test:500
xz@xiaqiu:~/study/niao-linux$ 

grep -n “[1]test” text.txt

grep -n “[2]test” text.txt


xz@xiaqiu:~/study/niao-linux$ grep -n "[^[:lower:]]test" text.txt 
8:Atest:100 
10:Btest:300
11:Btest:400
12:1test:700
13:2test:600
14:~test:500
xz@xiaqiu:~/study/niao-linux$ grep -n "[^[:digit:]]test" text.txt 
1:atest:100 
3:atest:300
4:btest:400
5:btest:700
6:btest:600
7:btest:500
8:Atest:100 
10:Btest:300
11:Btest:400
14:~test:500
xz@xiaqiu:~/study/niao-linux$ 

grep -n “t…t” text.txt


xz@xiaqiu:~/study/niao-linux$ grep -n "t..t" text.txt 
1:atest:100 
2:atext1:300
3:atest:300
4:btest:400
5:btest:700
6:btest:600
7:btest:500
8:Atest:100 
9:Atext1:300
10:Btest:300
11:Btest:400
12:1test:700
13:2test:600
14:~test:500
xz@xiaqiu:~/study/niao-linux$ 


正则表达式

^word
意义:待搜寻的字串(word)在行首!范例:搜寻行首为 # 开始的那一行,并列出行号 > grep -n ‘^#’ text.txt

word$
意义:待搜寻的字串(word)在行尾!范例:将行尾为 ! 的那一行打印出来,并列出行号 > grep -n ‘!$’ text.txt

.
意义:代表“一定有一个任意字符”的字符!范例:搜寻的字串可以是 (eve) (eae) (eee) (e e), 但不能仅有 (ee) !亦即 e 与 e 中间“一定”仅有一个字符,而空白字符也是字符! > grep -n ‘e.e’ text.txt

\
意义:跳脱字符,将特殊符号的特殊意义去除!范例:搜寻含有单引号 ’ 的那一行! > grep -n ’ text.txt

意义:重复零个到无穷多个的前一个 RE 字符 范例:找出含有 (es) (ess) (esss) 等等的字串,注意,因为 可以是 0 个,所以 es 也是符合带搜寻字串。另外,因为 为重复“前一个 RE 字符”的符号, 因此,在 之前必须要紧接着一个 RE 字符喔!例如任意字符则为 “.” ! > grep -n ‘ess*’ text.txt

[list]
意义:字符集合的 RE 字符,里面列出想要撷取的字符!范例:搜寻含有 (gl) 或 (gd) 的那一行,需要特别留意的是,在 [] 当中“谨代表一个待搜寻的字符”, 例如“ a[afl]y ”代表搜寻的字串可以是 aay, afy, aly 即 [afl] 代表 a 或 f 或 l 的意思! > grep -n ‘g[ld]’ text.txt

[n1-n2]
意义:字符集合的 RE 字符,里面列出想要撷取的字符范围!范例:搜寻含有任意数字的那一行!需特别留意,在字符集合 [] 中的减号 - 是有特殊意义的,他代表两个字符之间的所有连续字符!但这个连续与否与 ASCII 编码有关,因此,你的编码需要设置正确(在 bash 当中,需要确定 LANG 与 LANGUAGE 的变量是否正确!) 例如所有大写字符则为 [A-Z] > grep -n ‘[A-Z]’ text.txt

[^list]
意义:字符集合的 RE 字符,里面列出不要的字串或范围!范例:搜寻的字串可以是 (oog) (ood) 但不能是 (oot) ,那个 ^ 在 [] 内时,代表的意义是“反向选择”的意思。 例如,我不要大写字符,则为 [^A-Z]。但是,需要特别注意的是,如果以 grep -n [^A-Z] regular_express.txt 来搜寻,却发现该文件内的所有行都被列出,为什么?因为这个 [^A-Z] 是“非大写字符”的意思, 因为每一行均有非大写字符,例如第一行的 “Open Source” 就有 p,e,n,o… 等等的小写字 > grep -n ‘oo[^t]’ text.txt

{n,m}
意义:连续 n 到 m 个的“前一个 RE 字符” 意义:若为 {n} 则是连续 n 个的前一个 RE 字符, 意义:若是 {n,} 则是连续 n 个以上的前一个 RE 字符! 范例:在 g 与 g 之间有 2 个到 3 个的 o 存在的字串,亦即 (goog)(gooog) > grep -n ‘go{2,3}g’ text.txt

nl text.txt | sed ‘2,5d’ 将 text.txt 的内容列出并且打印行号,同时,请将第 2~5 行删除!


xz@xiaqiu:~/study/niao-linux$ nl text.txt | sed '2,5d'
     1   atest:100 
     6   btest:600
     7   btest:500
     8   Atest:100 
     9   Atext1:300
    10   Btest:300
    11   Btest:400
    12   1test:700
    13   2test:600
    14   ~test:500
xz@xiaqiu:~/study/niao-linux$ 

nl text.txt | sed ‘2a drink tea’ 在第二行后(亦即是加在第三行)加上“drink tea?”字样


xz@xiaqiu:~/study/niao-linux$ nl text.txt | sed '2a drink tea'
     1   atest:100 
     2   atext1:300
drink tea
     3   atest:300
     4   btest:400
     5   btest:700
     6   btest:600
     7   btest:500
     8   Atest:100 
     9   Atext1:300
    10   Btest:300
    11   Btest:400
    12   1test:700
    13   2test:600
    14   ~test:500
xz@xiaqiu:~/study/niao-linux$ 

nl text.txt | sed ‘2a drink tea ;\ndrink beer’ 在第二行后面加入两行字,例如“Drink tea or …”与“drink beer?”


xz@xiaqiu:~/study/niao-linux$ nl text.txt | sed '2a drink tea ;\ndrink beer' 
     1   atest:100 
     2   atext1:300
drink tea ;
drink beer
     3   atest:300
     4   btest:400
     5   btest:700
     6   btest:600
     7   btest:500
     8   Atest:100 
     9   Atext1:300
    10   Btest:300
    11   Btest:400
    12   1test:700
    13   2test:600
    14   ~test:500
xz@xiaqiu:~/study/niao-linux$ 

nl text.txt | sed ‘2,5c No 2-5 number’ 将第2-5行的内容取代成为“No 2-5 number”


xz@xiaqiu:~/study/niao-linux$ nl text.txt | sed '2,5c No 2-5 number' 
     1   atest:100 
No 2-5 number
     6   btest:600
     7   btest:500
     8   Atest:100 
     9   Atext1:300
    10   Btest:300
    11   Btest:400
    12   1test:700
    13   2test:600
    14   ~test:500
xz@xiaqiu:~/study/niao-linux$ 

nl text.txt | sed -n ‘5,7p’ 仅列出 text.txt 文件内的第 5-7 行


xz@xiaqiu:~/study/niao-linux$ nl text.txt | sed -n '5,7p' 
     5   btest:700
     6   btest:600
     7   btest:500
xz@xiaqiu:~/study/niao-linux$ 

sed ‘s/^.*inet //g’

sed ‘s/ *netmask.*$//g’


1.查询wlp4s0 IP
xz@xiaqiu:~/study/niao-linux$ ifconfig wlp4s0
wlp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.7  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2409:8a62:33a:fd40:ebb7:4d7a:1b3c:ebdd  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::ab47:8069:544a:3553  prefixlen 64  scopeid 0x20<link>
        inet6 2409:8a62:33a:fd40:10e2:ede3:c67:7749  prefixlen 64  scopeid 0x0<global>
        ether a0:d3:7a:16:04:86  txqueuelen 1000  (以太网)
        RX packets 43676  bytes 42938780 (42.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38453  bytes 8185214 (8.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
xz@xiaqiu:~/study/niao-linux$ 
2.grep 撷取出关键的一行数据
xz@xiaqiu:~/study/niao-linux$ ifconfig wlp4s0 | grep 'inet '
        inet 192.168.1.7  netmask 255.255.255.0  broadcast 192.168.1.255
xz@xiaqiu:~/study/niao-linux$ 
3.将 IP 前面的部分予以删除
xz@xiaqiu:~/study/niao-linux$ ifconfig wlp4s0 | grep 'inet ' | sed 's/^.*inet //g'
192.168.1.7  netmask 255.255.255.0  broadcast 192.168.1.255
xz@xiaqiu:~/study/niao-linux$ 
4.将 IP 后面的部分予以删除
xz@xiaqiu:~/study/niao-linux$ ifconfig wlp4s0 | grep 'inet ' | sed 's/^.*inet //g' | sed 's/ *netmask.*$//g'
192.168.1.7
xz@xiaqiu:~/study/niao-linux$ 


  1. :lower: ↩︎

  2. :digit: ↩︎


http://www.niftyadmin.cn/n/1241647.html

相关文章

Day409.商品上架 -谷粒商城

一、商品上架 1、项目架构图 2、product-es准备 ES在内存中&#xff0c;所以在检索中优于mysql。ES也支持集群&#xff0c;数据分片存储。 需求&#xff1a; 上架的商品才可以在网站展示。上架的商品需要可以被检索。(上架的商品就加入到es去被检索)分析sku在es中如何存储 商…

C++ 移动语义学习

C03 示例&#xff08;在移动语义之前&#xff09; 假设我们有以下程序: #include <string> #include <vector>std::vector<std::string> createAndInsert() {std::vector<std::string> coll; // create vector of stringscoll.reserve(3); // reserve …

Day410411.商品系统首页 -谷粒商城

二、商城系统首页 不使用前后端分离开发了&#xff0c;管理后台用vue nginx发给网关集群&#xff0c;网关再路由到微服务 静态资源放到nginx中 依赖 导入thymeleaf依赖、热部署依赖devtools使页面实时生效 achangmall-product/pom.xml <dependency><groupId>o…

Day412.分布式锁redisson与缓存 -谷粒商城

分布式锁redisson与缓存 读模式缓存使用流程 缓存 本地缓存&#xff1a;和微服务同一个进程。缺点&#xff1a;分布式时本都缓存不能共享 分布式缓存&#xff1a;缓存中间件 一、本地缓存 category、brand、product 安装docker-redis https://blog.csdn.net/qq_43284469/ar…

vscode

vscode 基本操作 vscode git vscode cpp vscode 插件 vscode PlatformIO (物联网) vscode remote(远程开发) 正则表达式 1. 查找多个关键字(word1)|(word2) 2. 删除和替换带有指定关键字的行^.*(word1|word2).*\n 3. 正则表达式匹配日期\[[^\[]*\] VSCODE标尺设置 "edito…

Day413.SpringCache -谷粒商城

SpringCache 每次都那样写缓存太麻烦了&#xff0c;spring从3.1开始定义了Cache、CacheManager接口来统一不同的缓存技术。并支持使用JCache(JSR-107)注解简化我们的开发Cache接口的实现包括RedisCache、EhCacheCache、ConcurrentMapCache等每次调用需要缓存功能的方法时&…

阿昌教你用SpringCache+Redis缓存数据

0、前言 这几天学习谷粒商城又再次的回顾了一次SpringCache&#xff0c;之前在学习谷粒学院的时候其实已经学习了一次了&#xff01;&#xff01;&#xff01; 这里就对自己学过来的内容进行一次的总结和归纳&#xff01;&#xff01;&#xff01; 一、什么是SpringCache Sp…

Day414415416417418.检索服务 -谷粒商城

检索服务 0、准备环境 achangmall-search 引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency><groupId>org.springf…