中山古镇做网站,网络运营推广怎么做,腾讯官方网站做书签,网络服务提供者利用网络侵害他人✅作者简介#xff1a;大家好#xff0c;我是Leo#xff0c;热爱Java后端开发者#xff0c;一个想要与大家共同进步的男人#x1f609;#x1f609; #x1f34e;个人主页#xff1a;Leo的博客 #x1f49e;当前专栏#xff1a; Linux相关 ✨特色专栏#xff1a; My…
✅作者简介大家好我是Leo热爱Java后端开发者一个想要与大家共同进步的男人 个人主页Leo的博客 当前专栏 Linux相关 ✨特色专栏 MySQL学习 本文内容Linux自用笔记 ️个人小站 个人博客欢迎大家访问 个人知识库 Leo知识库欢迎大家访问
1.命令终端字段含义介绍 [rootlocalhost ~]# 解释 root当前登录系统用户名(root超级管理员)localhost 当前主机名当前用户所在目录 为家目录 root超级管理员家目录/root# 当前用户身份是超级管理员 [studentlocalhost ~]$ $当前用户身份为普通用户普通用户的家目录/home/用户名同名
3.Linux系统基本概念
多用户的系统允许同时有很多个用户登录系统使用系统里的资源多任务的系统允许同时执行多个任务严格区分大小写命令选项参数文件名目录名都严格区分大小写一切皆文件硬件设备内存、CPU、网卡、显示器、硬盘等等都是以文件的形式存在的不管是文件还是目录都是以倒挂的树形结构存在于系统的“/”根目录下根目录是Linux系统的起点对于Linux系统而言目录/文件没有扩展名一说扩展名如.sh脚本文件) .conf配置文件 .log日志文件 .rpm软件包.tar压缩包是易于用户方便识别没有提示就是最好的提示成功了Linux系统没有回收站
4.显示行号
第一步打开vim
vim ~/.vimrc第二步在该文件中加入一行命令如下
set nu # 显示行号
set nonu # 不显示行号 5.命令行编辑技巧
键盘上下键调出历史命令 Ctrl c废弃当前命令行中的命令取消当前执行的命令例如ping Ctrl l,clear清屏 tab建自动补齐可补齐命令、参数、文件路径、软件名 esc . 将上一条命令参数变成当前命令的执行对象 Ctrl a将当前光标移动至行首 Ctrl e将当前光标移动至行尾 Ctrl u 清空至行首 Ctrl w 删除一个单词 exitlogout退出系统 6.命令行一般命令格式
命令字 [-选项…] [参数…] 命令字命令本身功能选项调整命令功能的 短选项-l -a -d -h单个字符短选项可以合并使用-lad -lh长选项–help单词长选项通常是不能合并使用的 参数命令的执行对象文件/目录/程序等[]可选的…可以同时有多个选项或参数
7.Linux系统辨别目录与文件的方法 蓝色表示目录windows系统里的文件夹 白色表示文件 浅蓝色表示链接文件类似于windows系统的快捷方式 绿色表示可执行文件如脚本命令程序文件 红色表示压缩文件 黄色表示设备文件硬盘、键盘、鼠标、网卡、CPU硬件设备都是以文件的形式存在的 红色闪动文件——表示链接文件不可用 8.ls 查看目录/文件命令 ls命令英文全拼list用于查看目录下内容及目录和文件详细属性信息 命令格式ls [-选项…] [参数…] 常用选项 -a 显示目录下所有内容包含隐藏的内容-l 以长格式显示目录下的内容及详细属性-h 人性化显示目录下内容大小kB、MB、GB-d 仅显示目录本身而不显示目录下的内容-i 查看inode号系统任何的文件或目录都有一个唯一的编号-R递归查看目录下所有内容从头到尾 注意附加递归是指将所有的目录从头到尾全部呈现出来。
9.Linux系统文件类型 - 文件 d 目录 l 链接文件 b 跨设备文件 c 字符设备文件 p 管道设备文件 s 套接字 10.Linux系统下的归属关系 在Linux系统下文件给用户分成了三类 所有者文件或目录的拥有者拥有者的权限通常是最大的 所属组文件或目录属于哪一个组所属组的权限略微比所有者小 其他人既不是文件或目录的所有者也不属于文件或目录组内的成员其他人的权限通常最小的权限 ls命令示例
#显示当前所在目录下的所有内容
[rootlocalhost ~]# ls #查看根目录下所有内容
[rootlocalhost ~]# ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var#查看/etc目录下所有内容
[rootlocalhost ~]# ls /etc#查看/bin目录下所有内容
[rootlocalhost ~]# ls /bin#查看/dev目录下所有内容
[rootlocalhost ~]# ls /dev#查看目录下所有目录和文件包括隐藏的内容
[rootlocalhost ~]# ls -a#以长格式显示目录下所有内容包括详细的属性信息
[rootlocalhost ~]# ls -l
-rw-r--r--. 1 root root 0 10月 24 15:16 hello#解释
-文件类型
1代表文件的引用次数
root文件的所有者
root文件的所属组
0文件的大小默认以字节为单位显示大小
10月 24 15:16文件最近一次的修改时间
hello文件名#以长格式显示目录所有内容以人性化的方式显示详细的属性信息
[rootlocalhost ~]# ls -l -h#短选项合并使用
[rootlocalhost ~]# ls -lh#以长格式显示目录所有内容以人性化的方式显示详细的属性信息包括隐藏的内容
[rootlocalhost ~]# ls -lha#以长格式显示根目录下所有内容包括详细的属性信息
[rootlocalhost ~]# ls -l /
lrwxrwxrwx. 1 root root 7 3月 13 17:15 bin - usr/bin#创建hello.txt文件
[rootlocalhost ~]# touch hello.txt#查看文件的元数据信息
[rootlocalhost ~]# stat hello.txt文件hello.txt大小0 块0 IO 块4096 普通空文件
设备fd00h/64768d Inode33575020 硬链接1
权限(0644/-rw-r--r--) Uid( 0/ root) Gid( 0/ root)
环境unconfined_u:object_r:admin_home_t:s0
最近访问2021-03-14 16:38:14.349861770 0800
最近更改2021-03-14 16:38:14.349861770 0800
最近改动2021-03-14 16:38:14.349861770 0800
创建时间-
11.Linux基本权限的类别 r 读取 w 写入 x 执行 - 没有权限 权限顺序rwx rwx rwx
[rootlocalhost ~]# ls -l
-rw-r--r--. 1 root root 1831 3月 13 17:45 initial-setup-ks.cfg
# 解释
-文件类型
rw- r-- r--所有者u、所属组g、其他人o的权限
u g or 读取权限w写入权限x执行权限-没有任何权限1代表文件的引用次数只针对与做了硬连接的文件才有效
root文件的所有者
root文件的所属组
1831文件的大小默认以字节为单位显示大小
3月 13 17:45文件最近一次的修改时间
initial-setup-ks.cfg文件名#查看/root目录本身详细属性信息
[rootlocalhost ~]# ls -ld /root
dr-xr-x---. 14 root root 4096 3月 14 16:38 /root#查看当前目录下所有内容的inode号
[rootlocalhost ~]# ls -i
33574979 anaconda-ks.cfg 33574984 initial-setup-ks.cfg 33575035 模板 33575036 图片 17470701 下载 17470702 音乐
33575020 hello.txt 51909391 公共 51909392 视频 3204374 文档 33575017 新建文件夹.zip 3204373 桌面#查看hello.txt文件的inode号
[rootlocalhost ~]# ls -i hello.txt
33575020 hello.txt#查看/etc/目录本身的inode号
[rootlocalhost ~]# ls -id /etc
16777281 /etc12.绝对路径与相对路径 绝对路径以 /根 为起点到达你想去的目标目录称为绝对路径 相对路径以当前路径为起点到达你想去的目标目录 常用快捷操作 ~ 表示为家目录. 表示为当前目录… 表示上一级目录 -可在两路径之间来回切换
13.pwd 打印当前所在目录 pwd英文全拼print work directory打印当前所在的工作目录执行pwd命令后可显示当前所在的工作目录的绝对路径名称 命令格式pwd [-选项]
[rootlocalhost ~]# cd /opt/a/b/c/d#打印当前所在目录绝对路径
[rootlocalhost d]# pwd
/opt/a/b/c/d#切换到用户家目录
[rootlocalhost d]# cd ~
[rootlocalhost ~]# pwd
/root
[rootlocalhost ~]# cd /opt/a/b/c/d
[rootlocalhost d]# pwd
/opt/a/b/c/d
[rootlocalhost d]# cd
[rootlocalhost ~]# pwd
/root[rootlocalhost ~]# cd /bin
[rootlocalhost bin]# pwd
/bin[rootlocalhost bin]# cd /boot
[rootlocalhost boot]# pwd
/boot
[rootlocalhost boot]# ls[rootlocalhost boot]# cd /dev
[rootlocalhost dev]# pwd
/dev
[rootlocalhost dev]# ls[rootlocalhost dev]# cd /etc
[rootlocalhost etc]# pwd
/etc
[rootlocalhost etc]# ls[rootlocalhost etc]# ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var#“.”表示当前所在目录对于cd命令而言作用不大
[rootlocalhost etc]# cd .[rootlocalhost etc]# cd /opt/a/b/c/d
[rootlocalhost d]# pwd
/opt/a/b/c/d#“..”切换到当前目录的上一级目录
[rootlocalhost d]# cd ..
[rootlocalhost c]# pwd
/opt/a/b/c[rootlocalhost c]# cd ..
[rootlocalhost b]# pwd
/opt/a/b[rootlocalhost b]# cd ..
[rootlocalhost a]# cd ..
[rootlocalhost opt]# pwd
/opt[rootlocalhost opt]# cd ..
[rootlocalhost /]# cd ..
[rootlocalhost /]# cd
[rootlocalhost ~]# ls[rootlocalhost ~]# cd /opt/a/b/c/d
[rootlocalhost d]# pwd
/opt/a/b/c/d#-可在两个路径之间来回切换
[rootlocalhost d]# cd /etc/yum
[rootlocalhost yum]# cd -
/opt/a/b/c/d[rootlocalhost d]# pwd
/opt/a/b/c/d[rootlocalhost d]# cd -
/etc/ym[rootlocalhost yum]# cd -
/opt/a/b/c/d[rootlocalhost d]# cd -
/etc/yum14.rmdir 删除空目录命令 rmdir英文全拼remove directory删除空目录 命令格式rmdir [-选项] 目录名
#rmdir只能删除空目录如果目录下存在数据无法删除
[rootlocalhost ~]# rmdir /opt/a
rmdir: 删除 /opt/a 失败: 目录非空
[rootlocalhost ~]# ls -R /opt/a
/opt/a:
b/opt/a/b:
c/opt/a/b/c:
d/opt/a/b/c/d:[rootlocalhost ~]# rmdir /opt/a/b/c/d
[rootlocalhost ~]# ls -R /opt/a
/opt/a:
b/opt/a/b:
c/opt/a/b/c:[rootlocalhost ~]# rmdir /opt/a/b/c
[rootlocalhost ~]# ls -R /opt/a/b
/opt/a/b:[rootlocalhost ~]# rmdir /opt/a/b
[rootlocalhost ~]# ls -R /opt/a
/opt/a:[rootlocalhost ~]# rmdir /opt/a
[rootlocalhost ~]# ls /opt
rh student xx[rootlocalhost ~]# rmdir /opt/
rmdir: 删除 /opt/ 失败: 目录非空15.touch 创建文件命令 touch 命令用于创建新的空白文件 命令格式touch [-选项] 文件名
#在当前路径创建空文件
[rootlocalhost ~]# touch hello
[rootlocalhost ~]# ls#在当前路径同时创建多个文件
[rootlocalhost ~]# touch t1 t2 t3 t4
[rootlocalhost ~]# ls#在指定路径同时创建多个文件
[rootlocalhost ~]# touch /opt/test1 /opt/test2 /opt/test3
[rootlocalhost ~]# ls /opt
rh student test1 test2 test3 xx#如果存在同名目录时无法创建
[rootlocalhost ~]# mkdir test
mkdir: 无法创建目录test: 文件已存在#如果存在同名文件时touch命令没有提示但原有文件不会被覆盖
[rootlocalhost ~]# touch t1#对于目录而言只有单个目录的时候“/”可有可无
[rootlocalhost ~]# ls /opt/
rh student test1 test2 test3 xx
[rootlocalhost ~]# ls /opt
rh student test1 test2 test3 xx#对于目录而言查看目录下的内容时必须要有“/”
[rootlocalhost ~]# ls /opt/xx
oo#对于文件而言后边绝对不能有“/”
[rootlocalhost ~]# ls /opt/test1
/opt/test1
[rootlocalhost ~]# ls /opt/test1/
ls: 无法访问/opt/test1/: 不是目录16.cp 复制命令 cp英文全拼copy file用于复制文件或目录cp命令在复制时也可修改目录或文件名字 命令格式cp [-选项] 源文件或目录 目标目录 常用选项 -p 保留源文件属性不变如修改时间、归属关系、权限-r 复制目录包含该目录下所有的子目录和文件
#复制当前目录文件到/opt目录相对路径方式复制
[rootlocalhost ~]# cp t1 /opt/
[rootlocalhost ~]# ls /opt
rh student t1 test1 test2 test3 xx#复制文件到/opt目录绝对路径方式复制
[rootlocalhost ~]# cp /root/t2 /opt
[rootlocalhost ~]# ls /opt
rh student t1 t2 test1 test2 test3 xx#同时复制多个文件
[rootlocalhost ~]# cp t3 t4 /opt/
[rootlocalhost ~]# ls /opt#创建目录
[rootlocalhost ~]# mkdir abc#使用-r对目录执行复制
[rootlocalhost ~]# cp -r abc /opt
[rootlocalhost ~]# ls /opt#同时复制多个目录
[rootlocalhost ~]# mkdir abc1 abc2 abc3
[rootlocalhost ~]# cp -r abc1 abc2 abc3 /opt
[rootlocalhost ~]# ls /opt#复制hello文件到/opt并改名为hello.txt
[rootlocalhost ~]# cp hello /opt/hello.txt
[rootlocalhost ~]# ls /opt#复制xxxx目录到/opt并改名xxoo
[rootlocalhost ~]# mkdir xxxx
[rootlocalhost ~]# cp -r xxxx /opt/xxoo
[rootlocalhost ~]# ls /opt#使用“.”配合cp命令执行复制
[rootlocalhost ~]# cd /etc/sysconfig/network-scripts/
[rootlocalhost network-scripts]# pwd
/etc/sysconfig/network-scripts[rootlocalhost network-scripts]# cp /root/t1 .
[rootlocalhost network-scripts]# ls#操持属性不变复制文件
[rootlocalhost ~]# cp -p anaconda-ks.cfg /opt
cp是否覆盖/opt/anaconda-ks.cfg y
[rootlocalhost ~]# ls -l /opt/anaconda-ks.cfg
-rw-------. 1 root root 1800 3月 13 17:34 /opt/anaconda-ks.cfg#对比以上两个文件的详细属性信息最后一次修改时间
[rootlocalhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1800 3月 13 17:34 anaconda-ks.cfg#这两个操作代表什么意思
[rootlocalhost ~]# cp -r xxxx /mnt/oooo #拷贝并改名
[rootlocalhost ~]# cp -r xxxx /mnt/oooo #拷贝17.mv 移动命令 mv英文全拼move file用于移动文件或目录到其他位置也可用于修改目录或文件名 命令格式mv [-选项] 源文件… 目标路径
#移动当前路径hello文件到/mnt目录
[rootlocalhost ~]# mv hello /mnt
[rootlocalhost ~]# ls /mnt
hello home oooo test#同时移动多个文件
[rootlocalhost ~]# mv t1 t2 t3 t4 /mnt
[rootlocalhost ~]# ls /mnt
hello home oooo student1 t1 t2 t3 t4 test#移动/opt目录下文件到/mnt
rootlocalhost ~]# mv /opt/test1 /opt/test2 /opt/test3 /mnt/
[rootlocalhost ~]# ls /mnt
hello home oooo student1 t1 t2 t3 t4 test test1 test2 test3#移动目录
[rootlocalhost ~]# mv student1 /mnt
[rootlocalhost ~]# ls /mnt
hello home oooo student1 test#移动文件并改名
[rootlocalhost ~]# mv hello.txt /media/hello
[rootlocalhost ~]# ls /media/
hello#移动目录并改名
[rootlocalhost ~]# mv test /media/testxx
[rootlocalhost ~]# ls /media/
hello testxx18.cat 查看文件内容命令 cat 英文全拼concatenate命令用于查看文本文件内容 命令格式cat [选项] 文件名 常用选项 -n #查看文件时以行号的形式显示文件内容
#查看文件内容
[rootlocalhost ~]# cat anaconda-ks.cfg
[rootlocalhost ~]# cat initial-setup-ks.cfg
[rootlocalhost ~]# cat /etc/hosts#查看网卡文件内容网卡配置文件
[rootlocalhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
...
NAMEens32 //网卡名
UUID16085f4c-f690-4058-b29e-d55c73387026
DEVICEens32
ONBOOTyes
IPADDR192.168.0.50 //网卡IP地址
PREFIX24 //子网掩码
GATEWAY192.168.0.254 //网关
DNS1114.114.114.114 //DNS#查看当前系统用户基本信息文件内容
[rootlocalhost ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin#查看当前系统主机名配置文件内容
[rootlocalhost ~]# cat /etc/hostname
localhost.localdomain#查看当前系统版本信息文件内容
[rootlocalhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) #查看当前系统开机自动挂载配置文件内容
[rootlocalhost ~]# cat /etc/fstab#查看系统组基本信息文件内容
[rootlocalhost ~]# cat /etc/group#使用“-n”以行号形式显示文件内容
[rootlocalhost ~]# cat -n /etc/passwd
[rootlocalhost ~]# cat -n /etc/hostname
[rootlocalhost ~]# cat -n /etc/fstab
[rootlocalhost ~]# cat -n /etc/group
[rootlocalhost ~]# cat -n /etc/services
19.less命令 less工具是对文件的输出进行分页显示的工具常用于查看内容量较大的文件 命令格式less [-选项] 文件 常用选项 -N #以行号形式显示文件内容 使用技巧 键盘上下键逐行查看pgdn 向下翻一页Fn 下键pgup 向上翻一页Fn 上键 /字符串 搜索指定字符串n从上向下搜索N从下向上搜索 G直接跳转到文件最后一行gg直接跳转到文件行首1000 #精准的定位到某一行q 退出
[rootlocalhost ~]# less -N /etc/services20.head与tail命令 head命令用来显示文件开头部分内容默认显示文件开头10行内容 命令格式head [选项] 参数 常用选项 -n行数 指定显示的行数
[rootlocalhost ~]# head /etc/passwd
[rootlocalhost ~]# head /etc/fstab
[rootlocalhost ~]# head /etc/group
[rootlocalhost ~]# head /etc/hostname
[rootlocalhost ~]# head /etc/hosts
[rootlocalhost ~]# head /etc/sysconfig/network-scripts/ifcfg-ens32 #查看存放DNS配置文件信息
[rootlocalhost ~]# head /etc/resolv.conf #使用-n指定显示文件前多少行内容
[rootlocalhost ~]# head -n 5 /etc/passwd
[rootlocalhost ~]# head -n 6 /etc/passwd
[rootlocalhost ~]# head -n 15 /etc/passwd
[rootlocalhost ~]# head -n 20 /etc/passwdtail命令用来显示文件末尾部分内容默认显示文件末尾10行内容 命令格式tail [选项] 参数 常用选项-n行数 指定显示的行数 -f 动态显示
[rootlocalhost ~]# tail /etc/passwd#使用“-n”指定显示文件末尾多少行内容
[rootlocalhost ~]# tail -n 5 /etc/passwd
[rootlocalhost ~]# tail -n 5 /etc/sysconfig/network-scripts/ifcfg-ens32
IPADDR192.168.0.50
PREFIX24
GATEWAY192.168.0.254
DNS1114.114.114.114
IPV6_PRIVACYno#动态查看文件内容
[rootlocalhost ~]# touch t1
rootlocalhost ~]# tail -f t1#另开一个终端向文件写入内容
[rootlocalhost ~]# echo 123 t121.rm 删除命令 rm英文全拼remove命令用于删除文件或者目录。 命令格式rm [-选项…] 目录或文件… 常用选项 -f 强制删除-r 删除目录***** 特殊字符系统常用符号用来代表任意所有字符
[rootlocalhost ~]# ls /opt
abc abc1 abc2 abc3 anaconda-ks.cfg hello.txt home rh student t1 t2 t3 t4 xx xxoo[rootlocalhost ~]# ls /mnt
hello home oooo student1 t1 t2 t3 t4 test test1 test2 test3#删除指定目录下文件
[rootlocalhost ~]# rm /opt/anaconda-ks.cfg
rm是否删除普通文件 /opt/anaconda-ks.cfgy #默认需要确认y|n#查看文件是否被成功删除
[rootlocalhost ~]# ls /opt
abc abc1 abc2 abc3 hello.txt home rh student t1 t2 t3 t4 xx xxoo[rootlocalhost ~]# rm /opt/hello.txt
rm是否删除普通空文件 /opt/hello.txty#同时删除目录下指定文件
[rootlocalhost ~]# rm /opt/t1 /opt/t2 /opt/t3 /opt/t4
rm是否删除普通空文件 /opt/t1y
rm是否删除普通空文件 /opt/t2y
rm是否删除普通空文件 /opt/t3y
rm是否删除普通空文件 /opt/t4y#查看文件是否被成功删除
[rootlocalhost ~]# ls /opt
abc abc1 abc2 abc3 home rh student xx xxoo#使用“-f”强制删除文件无需确认直接删除
[rootlocalhost ~]# rm -f /mnt/hello
[rootlocalhost ~]# ls /mnt
home oooo student1 t1 t2 t3 t4 test test1 test2 test3#同时强制删除多个文件
[rootlocalhost ~]# rm -f /mnt/t1 /mnt/t2 /mnt/t3 /mnt/t4
[rootlocalhost ~]# ls /mnt#删除目录
[rootlocalhost ~]# rm -r /opt/abc
rm是否删除目录 /opt/abcy[rootlocalhost ~]# ls /opt
abc1 abc2 abc3 home rh student xx xxoo#同时删除多个目录
[rootlocalhost ~]# rm -r /opt/abc1 /opt/abc2 /opt/abc3
rm是否删除目录 /opt/abc1y
rm是否删除目录 /opt/abc2y
rm是否删除目录 /opt/abc3y[rootlocalhost ~]# ls /opt
home rh student xx xxoo#同时强制删除多个目录
[rootlocalhost ~]# rm -rf /opt/home /opt/student /opt/xx /opt/xxoo
[rootlocalhost ~]# ls /opt
rh#创建目录与文件
[rootlocalhost ~]# touch /opt/t1
[rootlocalhost ~]# mkdir /opt/test
[rootlocalhost ~]# ls /opt
rh t1 test#rm命令在删除目录时包含改目录及目录下所有数据全部删除
[rootlocalhost ~]# rm -rf /opt/
[rootlocalhost ~]# ls /[rootlocalhost ~]# ls /mnt
home oooo student1 test test1 test2 test3#使用“*”通配任意所有字符删除/mnt目录下所有数据
[rootlocalhost ~]# rm -rf /mnt/*
[rootlocalhost ~]# ls /mnt22.软连接与硬连接
Linux中的链接文件类似于windows中的快捷方式软连接特点软连接可以跨分区可以对目录进行链接源文件删除后链接文件不可用软连接命令格式ln -s 源文件路径 目标路径注意创建链接时一定要写目录或文件的绝对路径哪怕是在当前路径下也要写绝对路径·
[rootlocalhost ~]# touch hello.soft
[rootlocalhost ~]# ls#创建软连接必须要绝对路径创建
[rootlocalhost ~]# ln -s /root/hello.soft /opt
[rootlocalhost ~]# ls /opt#查看连接文件详细属性
[rootlocalhost ~]# ls -l /opt/hello.soft lrwxrwxrwx. 1 root root 16 3月 21 14:28 /opt/hello.soft - /root/hello.soft#提示链接文件的权限最终取决于源文件的权限#普通用户验证[lisilocalhost ~]$ ls /opt
hello.soft
[lisilocalhost ~]$ ls -l /opt/hello.soft
lrwxrwxrwx. 1 root root 16 3月 21 14:28 /opt/hello.soft - /root/hello.soft
[lisilocalhost ~]$ cat /opt/hello.soft cat: /opt/hello.soft: 权限不够
#提示由于源文件存放于/root目录下而普通用户对/root目录没有任何权限所以普通用户无法查看#删除源文件
[rootlocalhost ~]# rm -f /root/hello.soft
[rootlocalhost ~]# ls#删除源文件后软链接文件不可用
[rootlocalhost ~]# ls -l /opt/hello.soft
lrwxrwxrwx. 1 root root 16 3月 21 14:28 /opt/hello.soft - /root/hello.soft#创建文件并创建软连接
[rootlocalhost ~]# touch hello.soft
[rootlocalhost ~]# ln -s /root/hello.soft /opt[rootlocalhost ~]# ls -l /opt/hello.soft
lrwxrwxrwx. 1 root root 16 3月 21 14:39 /opt/hello.soft - /root/hello.soft#删除链接文件后源文件仍然可用
[rootlocalhost ~]# rm -f /opt/hello.soft
[rootlocalhost ~]# ls
[rootlocalhost ~]# cat hello.soft #对目录创建软连接
[rootlocalhost ~]# ln -s /root/test1 /opt/[rootlocalhost ~]# ls -ld /opt/test1
lrwxrwxrwx. 1 root root 11 3月 21 14:44 /opt/test1 - /root/test13创建链接时一定要写目录或文件的绝对路径哪怕是在当前路径下也要写绝对路径
[rootlocalhost ~]# ln -s hello.soft /opt
[rootlocalhost ~]# ls /opt
hello.soft test1[rootlocalhost ~]# ls -l /opt/hello.soft
lrwxrwxrwx. 1 root root 10 3月 21 14:47 /opt/hello.soft - hello.soft硬链接特点硬连接不可以跨分区不可以对目录进行链接源文件删除后链接文件仍然可用 硬连接命令格式ln 源文件路径 目标路径
#创建文件并创建硬连接
[rootlocalhost ~]# touch hello.hard
[rootlocalhost ~]# ln /root/hello.hard /opt/
[rootlocalhost ~]# ls /opt
hello.hard hello.soft test1#向硬连接的源文件写入内容
rootlocalhost ~]# echo 123 /root/hello.hard #查看源文件内容
[rootlocalhost ~]# cat /root/hello.hard
123#查看链接文件内容以同步更新
[rootlocalhost ~]# cat /opt/hello.hard
123#向链接文件写入内容查看源文件以同步更新
[rootlocalhost ~]# echo xx /opt/hello.hard #擦看源文件以同步更新
[rootlocalhost ~]# cat /root/hello.hard
123
xx#硬连接文件的特点可以保持文件属性不发生改变
[rootlocalhost ~]# ls -l /root/hello.hard
-rw-r--r--. 2 root root 7 3月 21 14:55 /root/hello.hard
[rootlocalhost ~]# ls -l /opt/hello.hard
-rw-r--r--. 2 root root 7 3月 21 14:55 /opt/hello.hard#并且硬连接文件的i节点号相同
[rootlocalhost ~]# ls -i /root/hello.hard
33711090 /root/hello.hard
[rootlocalhost ~]# ls -i /opt/hello.hard
33711090 /opt/hello.hard#硬连接不允许对目录进行连接
rootlocalhost ~]# ln /root/test1 /opt
ln: /root/test1: 不允许将硬链接指向目录#硬连接源文件删除后链接文件仍然可用
[rootlocalhost ~]# rm -f /root/hello.hard
[rootlocalhost ~]# cat /opt/hello.hard
123
xx#向硬连接文件写入内容
[rootlocalhost ~]# echo abc /opt/hello.hard
[rootlocalhost ~]# cat /opt/hello.hard
123
xx
abc#硬连接不允许跨分区
[rootlocalhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm /└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 4.3G 0 rom
[rootlocalhost ~]# ln /root/hello.soft /boot
ln: 无法创建硬链接/boot/hello.soft /root/hello.soft: 无效的跨设备连接23.Linux命令的分类 内部命令bash程序自带的基本管理命令 外部命令有独立的外部可执行程序文件命令 type 用于区别内部命令与外部命令 which 用于查找可以执行程序文件位置
[rootlocalhost opt]# type ls[rootlocalhost opt]# type cat[rootlocalhost opt]# type hash[rootlocalhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[rootlocalhost ~]# hash
命中 命令1 /usr/bin/cat1 /usr/bin/ls[rootlocalhost opt]# hash -r
[rootlocalhost opt]#
[rootlocalhost opt]# hash
hash: 哈希表为空[rootlocalhost opt]# ls
hello.hard hello.soft t1 test1 test.txt
[rootlocalhost opt]# hash
命中 命令1 /usr/sbin/ls总结 shell程序是用户和系统之间的接口用于解释用户的命令查找命令对应的程序文件所在位置which 命令shell程序大多数存放在/etc/shells文件中系统默认使用的shell为/bin/bash查看当前使用的shellecho $SHELL区别内部命令与外部命令的方式typt 命令shell程序查找可执行程序文件路径定义在$PATH环境变量中shell查找的外部命令路径结果会记录到缓存的hash表中
24.help 命令帮助手册 help命令用于查看shell内部命令的帮助信息包括使用方法、选项等… 命令格式help [选项] 命令
#获取内部命令帮助信息
[rootlocalhost etc]# help cd#help无法获取外部命令的帮助信息
rootlocalhost etc]# help ls
bash: help: 没有与 ls 匹配的帮助主题。尝试 help help 或者 man -k ls 或者 info ls。[rootlocalhost etc]# type help
help 是 shell 内嵌#获取help命令本身的帮助信息
[rootlocalhost etc]# help help[rootlocalhost etc]# type cat
cat 是 /usr/bin/cat[rootlocalhost etc]# help cat
bash: help: 没有与 cat 匹配的帮助主题。尝试 help help 或者 man -k cat 或者 info cat。#查看命令帮助手册命令自带
[rootlocalhost etc]# cat --help
[rootlocalhost etc]# ls --help25.man 获取命令帮助手册 man 命令用于查看系统命令的帮助信息包括使用方法、选项、使用例子等…对比–help man 输出的信息更加详细 命令格式man [-选项] 命令 常用快捷操作 向下键向下移一行 向上键向上移一行 [Page Down] 向下翻一页 [Page Up] 向上翻一页 /关键字 #搜索关键字配合n向下查询、N向上查询 q 退出
[rootlocalhost etc]# man ls
[rootlocalhost etc]# man cat
[rootlocalhost etc]# man touch
[rootlocalhost etc]# man mkdir[rootlocalhost etc]# info ls持续更新中。。。