1、描述Linux发行版的系统目录名称命名规则以及用途。
linux目录得命名规则:
1、目录名称严格区分大小写
2、目录名称得长度超过255个字符
3、目录命名时严禁使用系统含有特殊含义得字符,例如:/、$、?等
linux存在得各目录的用途:
/boot:此目录中存放系统开机时加载的引导程序文件,内核文件(vmlinuz)、引导加载器(bootloader,grub)
/dev: 此目录存放的是系统的相关硬件设备文件
/home:此目录是普通用户的家目录,存放普通用户的相关信息
/root:此目录为管理员的家目录
/bin: 存放所有用户使用的基本命令,现已为/usr/bin的软连接文件
/sbin:存放管理员用户使用的命令,现已位/usr/sbin的软连接文件
/lib:启动时程序依赖的基本共享库文件以及内核模块文件
/lib64:专用于64位系统的辅助共享库文件存放位置
/media:移动设备的挂载点
/mnt:临时文件系统的挂载点
/tmp:存放临时文件的目录
/opt:第三方应用程序的安装目录
/sys:存放当前系统硬件设备相关信息的虚拟文件系统
/proc:存放内核于进程相关的虚拟文件系统
/etc:存放配置文件目录
/srv:此目录存放一些服务启动后需要提取的数据
/usr:共享资源文件目录
/var:此目录存放日志相关内容
====================================
2、描述文件的元数据信息有哪些,分别表示什么含义,如何查看?如何修改文件的时间戳信息?
查看文件的元数据:
[08:29:12 root@node ~]#ll /data/scripts/systeminfo.sh
-rwxr-xr-x 1 root root 704 Nov 12 23:27 /data/scripts/systeminfo.sh
-rwxr-xr-x:
前面的共有十位:
-:代表文件位普通文件
rwx:文件所有者所拥有的权限
r-x:文件所属组所拥有的权限
r-x:其他人所拥有的权限
1:代表的是此文件的链接文件数
root(第一个):文件的所有者
root(第二个):文件的所属组
704: 文件的大小是多少
Nov 12 23:27:此文件的生成时间
/data/scripts/systeminfo.sh:文件的名称
查看文件的时间戳:
[09:04:49 root@node scripts]#stat systeminfo.sh
File: systeminfo.sh?
Size: 704 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 33615504 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-11-23 07:34:59.342379388 -0500
Modify: 2020-11-12 23:27:22.945408338 -0500
Change: 2020-11-16 01:09:08.550564269 -0500
Birth: -
更改文件的时间戳信息
[09:04:58 root@node scripts]#touch systeminfo.sh
[09:05:56 root@node scripts]#stat systeminfo.sh
File: systeminfo.sh?
Size: 704 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 33615504 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-12-01 09:05:56.960942280 -0500
Modify: 2020-12-01 09:05:56.960942280 -0500
Change: 2020-12-01 09:05:56.960942280 -0500
Birth: -
====================================
3、总结软连接和硬连接区别。
创建硬链接文件:
[17:54:56 root@centos8 local]#ln a.txt /tmp/a.txt
[17:55:52 root@centos8 local]#ll -i /tmp/a.txt a.txt
1190967 -rw-r--r--. 2 root root 0 Dec 2 17:54 a.txt
1190967 -rw-r--r--. 2 root root 0 Dec 2 17:54 /tmp/a.txt
[17:56:10 root@centos8 local]#echo "hello world" > a.txt
[17:56:37 root@centos8 local]#cat a.txt
hello world
[17:56:40 root@centos8 local]#cat /tmp/a.txt
hello world
删除硬链接源文件,不影响链接文件的查看
[17:56:46 root@centos8 local]#rm a.txt
rm: remove regular file 'a.txt'? y
[17:58:49 root@centos8 local]#ls
[17:58:51 root@centos8 local]#cat /tmp/a.txt
hello world
创建软链接文件
[18:21:10 root@centos8 data]#ln -s /data/mysql/ /tmp/mysql_softlink
[18:21:42 root@centos8 data]#ll /tmp/mysql_softlink
lrwxrwxrwx. 1 root root 12 Dec 2 18:21 /tmp/mysql_softlink -> /data/mysql/
[18:21:50 root@centos8 data]#cd /data/mysql/
[18:22:35 root@centos8 mysql]#touch a.txt
[18:22:42 root@centos8 mysql]#ls
a.txt
[18:22:49 root@centos8 mysql]#cat /tmp/mysql_softlink/a.txt
[18:22:57 root@centos8 mysql]#ls /tmp/mysql_softlink/
a.txt
删除软链接文件
[18:23:05 root@centos8 mysql]#rm -rf /data/mysql/
[18:23:43 root@centos8 mysql]#ll /tmp/mysql_softlink
lrwxrwxrwx. 1 root root 12 Dec 2 18:21 /tmp/mysql_softlink -> /data/mysql/(此处为红色闪烁状态)
[18:24:24 root@centos8 tmp]#cd /tmp/mysql_softling 软链接文件无法查看
-bash: cd: /tmp/mysql_softling: No such file or directory
====================================
4、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。
*********************************************
pwd:显示当前所在的工作目录
-P:显示真实物理路径
-L:显示链接路径(默认)
例子:
[18:55:11 root@centos8 data]#pwd
/data
[18:55:12 root@centos8 data]#cd /bin/
[18:55:37 root@centos8 bin]#pwd -P
/usr/bin
[18:55:40 root@centos8 bin]#pwd -L
/bin
*********************************************
basename:基名(只取文件的名称)
dirname:目录名(只读取文件的目录名称,不要文件名)
例子:
[18:58:54 root@centos8 ~]#touch a.txt;basename /data/mysql/a.txt
a.txt
[18:59:31 root@centos8 ~]#dirname /data/mysql/a.txt
/data/mysql
*********************************************
cd:更改当前的工作目录
-P:切换至物理路劲,而非软链接目录
cd -:切换至以前工作目录
cd:切换至当前用户的主目录
cd ..:切换至当前工作目录的父目录
例子:
[18:59:53 root@centos8 ~]#cd /data/mysql/
[19:06:36 root@centos8 mysql]#cd ..
[19:06:41 root@centos8 data]#cd -
/data/mysql
[19:06:46 root@centos8 mysql]#cd
[19:06:51 root@centos8 ~]#
[19:06:51 root@centos8 ~]#cd -P /bin
[19:07:19 root@centos8 bin]#pwd
/usr/bin
*********************************************
ls:列出当前目录的内容或指定目录的内容
-a:显示包含隐藏文件的所有文件
-l:以长格式显示文件的属性
-R:递归显示
-ld:目录和符号的链接信息
-1:文件分行进行显示
-S:按从大到小排序
-t:按mtime排序
-u:配合-t使用,显示并按atime从新到旧排序
-U:按目存放顺序显示
-X: 按文件后缀排序
例子:
[19:25:32 root@centos8 data]#ls -a
. .. local mysql
[19:25:34 root@centos8 data]#ls -la
total 0
drwxr-xr-x. 4 root root 32 Dec 2 18:28 .
dr-xr-xr-x. 18 root root 236 Dec 2 17:53 ..
drwxr-xr-x. 2 root root 26 Dec 2 18:06 local
drwxr-xr-x. 2 root root 6 Dec 2 18:28 mysql
[19:25:39 root@centos8 data]#ls -lta
total 0
drwxr-xr-x. 4 root root 32 Dec 2 18:28 .
drwxr-xr-x. 2 root root 6 Dec 2 18:28 mysql
drwxr-xr-x. 2 root root 26 Dec 2 18:06 local
dr-xr-xr-x. 18 root root 236 Dec 2 17:53 ..
[19:27:31 root@centos8 ~]#ll -R /data/
/data/:
total 0
drwxr-xr-x. 2 root root 26 Dec 2 18:06 local
drwxr-xr-x. 2 root root 6 Dec 2 18:28 mysql
/data/local:
total 4
-rw-r--r--. 1 root root 6 Dec 2 18:14 softlink.txt
/data/mysql:
total 0
*********************************************
stat:查看文件状态
文件的相关信息:metadata,data
例子:
[09:05:56 root@node scripts]#stat systeminfo.sh
File: systeminfo.sh?
Size: 704 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 33615504 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-12-01 09:05:56.960942280 -0500 //读取文件内容,此时间修改
Modify: 2020-12-01 09:05:56.960942280 -0500 //改变文件的内容,时间发生改变
Change: 2020-12-01 09:05:56.960942280 -0500 //改变文件的metadata,时间发生改变
Birth: -
*********************************************
file:查看文件的类型
-b:列出文件辨识结果时,不显示文件的名称
-f:filelist列出文件filelist中文件名的文件类型
-L:查看对应软连接对应文件的文件类型
例子:
[19:27:38 root@centos8 ~]#file /etc/
/etc/: directory
[19:42:35 root@centos8 ~]#file -b /etc/
directory
[19:42:41 root@centos8 ~]#file -L /etc/
/etc/: directory
[19:42:53 root@centos8 ~]#file -L /bin/
/bin/: directory
[20:02:49 root@centos8 ~]#echo "/etc" > /data/local/file.list
[20:03:04 root@centos8 ~]#file -f /data/local/file.list
/etc: directory
*********************************************
touch:可以创建空文件和刷新文件的三个时间戳
-a:仅改变atime和ctime
-m:仅改变mtime和ctime
-t:指定atime和mtime的时间戳格式
-c:文件如果不存在,则不予创建
例子:
[21:08:34 root@centos8 local]#stat file.list
File: file.list
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 1190968 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:default_t:s0
Access: 2020-12-02 20:03:07.289592962 +0800
Modify: 2020-12-02 20:03:04.672592763 +0800
Change: 2020-12-02 20:03:04.672592763 +0800
Birth: -
[21:08:51 root@centos8 local]#touch -a file.list
[21:08:59 root@centos8 local]#stat file.list
File: file.list
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 1190968 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:default_t:s0
Access: 2020-12-02 21:08:59.151894356 +0800
Modify: 2020-12-02 20:03:04.672592763 +0800
Change: 2020-12-02 21:08:59.151894356 +0800
Birth: -
[21:09:00 root@centos8 local]#touch -c file.list
[21:10:14 root@centos8 local]#ls
file.list softlink.txt
*********************************************
cp复制文件和目录
-i:目标文件存在,提示是否覆盖
-r|R:递归复制目录中的文件
-a:归档,常用于备份功能
-d:不复制源文件,只复制链接名
-v:显示复制过程的详细信息
-f:强制复制
-p:复制文件的所有者、所属组、权限、和时间戳
-b:目标存在,覆盖前先备份,默认的形式为filename~
例子:
[21:32:27 root@centos8 ~]#cp /etc/profile /tmp/
cp: overwrite '/tmp/profile'? y
[21:48:45 root@centos8 ~]#alias cp
alias cp='cp -i'
[21:48:49 root@centos8 ~]#cp -r /etc /tmp/etc
[21:49:30 root@centos8 ~]#ls /tmp/etc/
====================================
5、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字符
[21:23:38 root@centos8 ~]#cp /etc/profile /tmp
[21:23:38 root@centos8 ~]#cat /tmp/profile | tr -d ' '
====================================
6、在vim中设置tab缩进为4个字符
[21:32:03 root@centos8 ~]#vim .vimrc
set ts=4
set autoindent