文件管理

在linux中,一切皆文件,没有后缀之分 比如xxx.mp3文件 在linux中 没有mp3的区分

/目录下的文件

/ #第一层次结构的根、整个文件系统层次结构的根目录。

/bin/ #需要在单用户模式可用的必要命令(可执行文件);面向所有用户,例如:cat、ls、cp,和/usr/bin类似。

/boot/ #引导程序文件,例如:kernel、initrd;时常是一个单独的分区

/dev/ #必要设备, 例如:, /dev/null.

/etc/ #特定主机,系统范围内的配置文件。关于这个名称目前有争议。在贝尔实验室关于UNIX实现

文档的早期版本中,/etc 被称为/etcetra 目录,[7]这是由于过去此目录中存放所有不属于别处的所有东
西(然而,FHS限制/etc存放静态配置文件,不能包含二进制文件)。[8]自从早期文档出版以来,目录名称
已被以各种方式重新称呼。最近的解释包括反向缩略语如:"可编辑的文本配置"(英文 "Editable Text
Configuration")或"扩展工具箱"(英文 "Extended Tool Chest")。

/etc/opt/ #/opt/的配置文件

/etc/X11/ #X_Window系统(版本11)的配置文件

/etc/sgml/ #SGML的配置文件

/etc/xml/ #XML的配置文件

/home/ #用户的家目录,包含保存的文件、个人设置等,一般为单独的分区。

/lib/ #/bin/ and /sbin/中二进制文件必要的库文件。

/media/ #可移除媒体(如CD-ROM)的挂载点 (在FHS-2.3中出现)。

/lost+found #在ext3文件系统中,当系统意外崩溃或机器意外关机,会产生一些文件碎片在这里。当系统在开机启动的过程中fsck工具会检查这里,并修复已经损坏的文件系统。当系统发生问题。可能会有文件被移动到这个目录中,可能需要用手工的方式来修复,或移到文件到原来的位置上。

/mnt/ #临时挂载的文件系统。比如cdrom,u盘等,直接插入光驱无法使用,要先挂载后使用

/opt/ #可选应用软件包。

/proc/ #虚拟文件系统,将内核与进程状态归档为文本文件(系统信息都存放这目录下)。例如:uptime、 network。在Linux中,对应Procfs格式挂载。该目录下文件只能看不能改(包括root)

/root/ #超级用户的家目录

/sbin/ #必要的系统二进制文件,例如: init、 ip、 mount。sbin目录下的命令,普通用户都执行不了。

/srv/ #站点的具体数据,由系统提供。

/tmp/ #临时文件(参见 /var/tmp),在系统重启时目录中文件不会被保留。

/usr/ #默认软件都会存于该目录下。用于存储只读用户数据的第二层次;包含绝大多数的(多)用户工具和应用程序。

/var/       #变量文件——在正常运行的系统中其内容不断变化的文件,如日志,脱机文件和临时电子邮件文件。有时是一个单独的分区。如果不单独分区,有可能会把整个分区充满。如果单独分区,给大给小都不合适。
/etc
#系统重要配置文件, 以及常用服务配置文件

/var
#存放系统引导启动时产生的可变文件,文件通常动态更改的,例如: 缓存目录,日志文件

/run
#系统启动后, 运行的程序产生的运行时数据, 包括进程的pid文件,锁文件等

/home
#普通用户的主目录, 普通用户的家目录默认为/HOME/USERNAME

/root
#超级管理员的主目录, 普通用户无权操作

/tmp
#存放临时文件, 一般存放超过10天以上都会自动删除,可以更改删除临时文件的期限

/boot 
#存放系统引导时候需要的文件

/dev
#存放设备文件

/usr
#安装的软件, 共享库, 重要的子目录有

/usr/bin
#用户命令目录

/usr/sbin 
#管理员命令目录

/usr/local 
#本地自定义安装的软件

/etc目录

## 主机名配置文件
/etc/hostname
## 本地域名解析配置文件(本地DNS)
/etc/hosts
## 网卡配置文件
/etc/sysconfig/network-scripts/ifcfg-eth0
## DNS配置文件
/etc/resolv.conf
## 开机登录欢迎界面配置文件
/etc/motd
## 全局环境变量配置文件
/etc/profile
## 存放用户默认的环境变量配置文件
/etc/skel

————————系统用户相关 ↓
## 存放用户信息配置文件
/etc/passwd
## 存放用户密码信息的配置文件
/etc/shadow
## 存放用户组信息的配置文件
/etc/group
## 存放用户组密码信息的配置文件
/etc/gshadow

/var目录

## 系统日志
/var/log/messages
## 系统登录日志
/var/log/secure

/dev目录

## 系统中的第一块磁盘
/dev/sda
## 系统中的第一块磁盘的第一个分区
/dev/sda1
## 系统中第五块磁盘的第4个分区
/dev/sde4
## 黑洞
/dev/null
## 从该设备中可以源源不断的取出数据
/dev/zero
## 随机数设备
/dev/random
## 终端设备文件
/dev/pts/0 1 2 3

路径的定位

  • 绝对路径
    • 以 / 开头的路径 就是绝对路径 就是以根目录开头的
  • 相对路径
    • 不以 / 开头的路径 就是相对路径

cd

# 切换目录 change directory
cd
# 移动/切换目录
cd

# 语法
cd + [argument] (动作对象)

cd /etc
cd /etc/yum
## 如果你在etc目录下
cd yum

# 返回你当前所在目录的上一级目录
cd ..

# 返回当前登录用户的家目录
## 普通用户的家目录都在/home下有着和用户名相同的目录
cd

# 返回上一次所在的目录
cd -

## 查看当前所在路径指令
pwd
[root@web ~]# pwd
/root

特殊目录

. :代表当前目录  #相当于.也是一个文件 
..:代表上一级目录  #/目录也是有..文件的 不过/目录的上一级文件还是/目录

mkdir

目录创建指令↓
mkdir(make directory)
# 语法:
mkdir [OPTION]... DIRECTORY...
创建目录 [选项可有可无,可以有多个] 目录名字,也可以有多个
# 选项
-p:递归创建目录,如果目录已存在,则不创建,并且不报错
-v:打印,显示,目录的创建过程
# 用法
## 在当前目录下,创建一个名字为hg的文件夹
[root@web ~]# mkdir hg
[root@web ~]# ll
total 4
-rw-------. 1 root root 1285 Jun 30 05:20 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Jul  1 22:01 hg

## 在指定的路径下,创建名字叫one的文件夹
例在hg目录下创建one目录
[root@web ~]# mkdir hg/one
[root@web ~]# ll hg/
total 0
drwxr-xr-x. 2 root root 6 Jul  1 22:04 one

## 创建多个目录
[root@web ~]# mkdir 1 2 3 4
[root@web ~]# ll
total 0
drwxr-xr-x. 2 root root 6 Jul  1 23:11 1
drwxr-xr-x. 2 root root 6 Jul  1 23:11 2
drwxr-xr-x. 2 root root 6 Jul  1 23:11 3
drwxr-xr-x. 2 root root 6 Jul  1 23:11 4
创建多个文件用空格分隔

## 2 目录不能创建,hg文件已存在
[root@web ~]# mkdir hg
mkdir: cannot create directory ‘hg’: File exists

## 序列用法
[root@web ~]# mkdir {a..d}
[root@web ~]# ll
total 0
drwxr-xr-x.  2 root root    6 Jul  1 23:02 a
drwxr-xr-x.  2 root root    6 Jul  1 23:02 b
drwxr-xr-x.  2 root root    6 Jul  1 23:02 c
drwxr-xr-x.  2 root root    6 Jul  1 23:02 d
..表示那要创建文件的序列

[root@web ~]# mkdir hg{1,2,3,4}
[root@web ~]# ll
total 0
drwxr-xr-x. 2 root root 6 Jul  2 21:51 hg1
drwxr-xr-x. 2 root root 6 Jul  2 21:51 hg2
drwxr-xr-x. 2 root root 6 Jul  2 21:51 hg3
drwxr-xr-x. 2 root root 6 Jul  2 21:51 hg4
大括号内用,分隔你想要创建的多个文件夹

touch

创建普通文件指令↓
touch
只能创建出,可编辑的普通文件
# 语法
touch [OPTION]... FILE...
touch命令 [选项] 普通文件的文件名 可以写多个
touch创建文件,如果文件已存在,不报错,也不覆盖,只会修改文件的创建时间戳
[root@web ~]# ll
total 0
-rw-r--r--. 1 root root 0 Jul  2 21:54 hg

# 序列用法
[root@web ~]# touch {a..d}
[root@web ~]# ll
total 0
-rw-r--r--. 1 root root 0 Jul  2 21:55 a
-rw-r--r--. 1 root root 0 Jul  2 21:55 b
-rw-r--r--. 1 root root 0 Jul  2 21:55 c
-rw-r--r--. 1 root root 0 Jul  2 21:55 d

[root@web ~]# touch /opt/{1..3}
[root@web ~]# ll /opt
total 0
-rw-r--r--. 1 root root 0 Jul  2 21:56 1
-rw-r--r--. 1 root root 0 Jul  2 21:56 2
-rw-r--r--. 1 root root 0 Jul  2 21:56 3

# 报错案例
[root@web ~]# touch yyds/hg
touch: cannot touch ‘yyds/hg’: No such file or directory
touch想要创建文件,必须该文件的上级目录要存在

tree

## tree指令安装↓
rm -fr /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y tree
回车 等待完成

## 语法
tree [option]... 路径
[root@web ~]# tree /tmp
/tmp
├── docker-compose
├── docker.tar.gz
├── runc-process1529623674
├── vmware-root_528-2957714671
├── vmware-root_534-2957583592
├── vmware-root_535-4290690870
└── vmware-root_538-2999460707

4 directories, 3 files

## 选项
-L:后面接空格数字,查看指定层级的目录
[root@web ~]# tree -L 1 hg/
hg/
└── 1

[root@web ~]# tree -L 3 hg
hg
└── 1
    └── 2
        └── 3

-d:只看所有的目录,不看普通文件
[root@web ~]# tree -d hg/
hg/
└── 1
    └── 2
        └── 3
            └── 4
                └── 5
                    └── 6
                        └── 7
                            └── 8
                                └── 9

mv

mv(move)
# 语法
mv [option]... source dest
mv [选项] 源文件... 目标路径
[root@web ~]# mv /root/hg/1 /root
[root@web ~]# ll
total 8
drwxr-xr-x  3 root root   15 Jul  2 22:20 1
-rw-------. 1 root root 1512 Apr 11 16:23 anaconda-ks.cfg
drwxr-xr-x  2 root root    6 Jul  2 22:26 hg
[root@web ~]# tree hg/
hg/

0 directories, 0 files

## 注意,目标路径,必须是一个目录,如果目标路径不存在,则是改名

cp

## 指令:cp(copy)
## 语法↓
cp [option]... source dest
cp [选项] 源文件... 目标路径
注:默认只能拷贝文件
## 用法
[root@web ~]# cp ip.sh 1
[root@web ~]# tree 1
1
├── 2
│   └── 3
│       └── 4
│           └── 5
│               └── 6
│                   └── 7
│                       └── 8
│                           └── 9
└── ip.sh

##报错案例
[root@web ~]# cp hg 1
cp: omitting directory ‘hg’
无法cp目录

## 选项↓
-t:目标路径 源文件 #可以将源文件和目标路径前后位置调换

-p:保存文件属性
[root@web ~]# cp -p ip.sh hg/
[root@web ~]# ll
total 8
drwxr-xr-x  3 root root   28 Jul  2 22:31 1
-rw-------. 1 root root 1512 Apr 11 16:23 anaconda-ks.cfg
drwxr-xr-x  2 root root   19 Jul  2 22:33 hg
-rw-r--r--  1 root root  195 Apr 12 09:11 ip.sh
[root@web ~]# ll hg
total 4
-rw-r--r-- 1 root root 195 Apr 12 09:11 ip.sh
## -p以后cp管过来的文件保存了文件原来的属性 最直观的就是文件时间的改变

-r:递归复制,复制目录及目录下的所有文件
[root@web ~]# cp -r 1 hg
[root@web ~]# ll hg
total 4
drwxr-xr-x 3 root root  28 Jul  2 22:34 1
-rw-r--r-- 1 root root 195 Apr 12 09:11 ip.sh

-a:相当于-rp,既可以拷贝目录,又可以保持文件属性

## -i:提示。系统默认的就是cp -i
[root@web ~]# cp ip.sh hg
cp: overwrite ‘hg/ip.sh’? 
## 避免提示有两种方法
1.使用转义符:让转义符后面的内容,做它自己
[root@web ~]# \cp ip.sh hg
[root@web ~]# /bin/cp ip.sh hg

## 复制并改名
cp ip.sh hg/i.sh
[root@web ~]# ll hg
total 8
drwxr-xr-x 3 root root  28 Jul  2 22:34 1
-rw-r--r-- 1 root root 195 Jul  2 22:38 ip.sh
-rw-r--r-- 1 root root 195 Jul  2 22:42 i.sh
- 存在,并且i.sh是个普通文件:则提示是否要覆盖,输入y则覆盖,输入n则不覆盖
- 存在,并且i.sh是个目录:将ip.sh放到hg/i.sh目录下,不改名
- 不存在:复制到/tmp下,并且改名为abc
##注:当拷贝文件有多个源文件的情况下,最后一个必须是目录,不能是普通文件,也不能不存在

rm

## 指令:rm(remove)
默认,只能删除普通文件
## 语法↓
rm [OPTION]... FILE...
rm 选项... 文件...
## 用法↓
[root@web ~]# rm anaconda-ks.cfg 
rm: remove regular file ‘anaconda-ks.cfg’? y
[root@web ~]# ll
total 4
drwxr-xr-x 3 root root  28 Jul  2 22:31 1
drwxr-xr-x 3 root root  40 Jul  2 22:42 hg
-rw-r--r-- 1 root root 195 Apr 12 09:11 ip.sh

## 报错
[root@web ~]# rm 1
rm: cannot remove ‘1’: Is a directory
1是一个目录不能直接删除

## 选项
[root@web ~]# rm anaconda-ks.cfg 
rm: remove regular file ‘anaconda-ks.cfg’? y
-i:提示
#和上面的cp一样 提示你是否删除文件 避免提示的方法也是1.使用转义符2.使用命令的绝对路径

-r:递归删除
[root@web ~]# rm -r 1
rm: descend into directory ‘1’? y
rm: descend into directory ‘1/2’? y
rm: descend into directory ‘1/2/3’? y
rm: descend into directory ‘1/2/3/4’? y
rm: descend into directory ‘1/2/3/4/5’? y
rm: descend into directory ‘1/2/3/4/5/6’? y
rm: descend into directory ‘1/2/3/4/5/6/7’? y
rm: descend into directory ‘1/2/3/4/5/6/7/8’? y   
rm: remove directory ‘1/2/3/4/5/6/7/8/9’? y
rm: remove directory ‘1/2/3/4/5/6/7/8’? y
rm: remove directory ‘1/2/3/4/5/6/7’? y
rm: remove directory ‘1/2/3/4/5/6’? y
rm: remove directory ‘1/2/3/4/5’? y
rm: remove directory ‘1/2/3/4’? y   
rm: remove directory ‘1/2/3’? y
rm: remove directory ‘1/2’? y
rm: remove regular file ‘1/ip.sh’? y
rm: remove directory ‘1’? y
#可以选择目录再一个个确认删除里面的各个文件

-f:force 强制删除
[root@web ~]# rm -fr /*
强制删除当前目录的全部文件(一天一个优化小技巧)

-d:只能删除空目录

cat

## 指令:cat(只能查看文件内容)
## 语法
cat [OPTION]... [FILE]...
cat 选项... 普通文件...
## 用法
[root@web ~]# cat ip.sh 
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
systemctl restart network

## 报错
[root@web ~]# cat 1
cat: 1: No such file or directory
1是个目录

## 选项
-n:number 打印行号,显示行号
[root@web ~]# cat -n ip.sh 
     1  read -p 'Input Net IP' IP
     2  eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
     3  eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
     4  sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
     5  systemctl restart network

-E:end ,查看文件每一行的结尾,以$符表示
[root@web ~]# cat -E ip.sh 
read -p 'Input Net IP' IP$
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`$
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`$
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"$
systemctl restart network$

-T:Tab,查看文件中每一行内容是否含有制表符 以^I表示一个制表符
[root@web ~]# cat -T 1.txt 
1^I
2
3^I^I
4

5^I^I^I^I
#一个制表符表示为8个空格

-A既显示制表符,又显示文件的结尾
[root@web ~]# cat -A 1.txt 
1^I$
2$
3^I^I$
4$
$
5^I^I^I^I$

## 拓展
#用cat创建文件并写入内容
[root@web ~]# cat >>1.abc<<EOF
> abc
> 123
> EOF
[root@web ~]# cat 1.abc 
abc
123
# >><<:重定向符号 EOF:(End Of) 以....结尾,不是固定用法,规范用法

more

## 指令: more
# 语法:more 文件名
按回车,一行一行向下显示
按空格,一页一页向下显示
Ctrl + b:向上查看
Ctrl + f:向下查看

## 指令:less
# 语法:less 文件名
Ctrl + b:向上查看
Ctrl + f:向下查看
按回车,一行一行向下显示
按空格,一页一页向下显示
输入/关键字,高亮显示,所有匹配到的内容
按n,查找下一个关键字
Shift + n 查找上一个关键字

-----------------------------------------------

## 指令:head
# 语法:head 文件名
默认显示一个文件的前10行内容
[root@web ~]# head 1.txt 
1   
2
3       
4

5
## 选项
-n:指定查看文件开头的前N行
[root@web ~]# head -n 1 1.txt 
1   

## 指令:tail
# 语法:tail 文件名
默认显示一个文件的后10行内容
[root@web ~]# tail /etc/passwd
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin

## 选项
-n:指定查看文件末尾的后N行
[root@web ~]# tail -n 5 /etc/passwd
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin

-f:follow,跟踪,动态跟踪一个文件的末尾

grep

|:管道符
# 作用:将管道符左边命令的标准输出,交给管道符右边命令的标准输入来处理
[root@web ~]# cat ip.sh | grep 'a'
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
systemctl restart network
#xshell上a为高亮显示

## 指令
grep:过滤输出内容

用以下文本示例:
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
systemctl restart network

## 特殊符号:
^:以...开头
[root@web ~]# grep '^e' ip.sh 
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
##xshell上e为高亮

$:以...结尾
[root@web ~]# grep 'P$' ip.sh 
read -p 'Input Net IP' IP
#^要内容的在前面 $要在内容的后面

*:匹配*前面的内容至少0次或多次
 [root@web ~]# grep 'P*' ip.sh 
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
systemctl restart network
#0次或多次 所以全部显示了

.:匹配任意字符
[root@web ~]# grep 'P.' ip.sh 
read -p 'Input Net IP' IP
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"

## 选项
-n:打印行号 number
[root@web ~]# grep -n 'e' ip.sh 
1:read -p 'Input Net IP' IP
2:eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
3:eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
4:sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
5:systemctl restart network

-A:after 查看过滤内容的后N行
[root@web ~]# grep -A 1 '|' ip.sh 
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
systemctl restart network

-B:before 查看过滤内容的前N行
[root@web ~]# grep -B 1 '|' ip.sh 
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"

-C:center 查看过滤内容的前、后N行
[root@web ~]# grep -C 1 '=' ip.sh 
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"

-v:取反
[root@web ~]# grep -v '=' ip.sh 
read -p 'Input Net IP' IP
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
systemctl restart network

-E:可以过滤多个结果
[root@web ~]# grep -E '0|-' ip.sh 
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"

-o:只打印出过滤内容
[root@web ~]# grep -o '0' ip.sh 
0
0
0

-i:不区分大小写
[root@web ~]# grep -i 'P' ip.sh 
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"

#[a-zA-Z]虚拟机内所有字母不管大小
[root@web ~]# grep '[a-zA-Z]' ip.sh 
read -p 'Input Net IP' IP
eth0=`ifconfig eth0 | awk 'NR==2{print $2}'`
eth1=`ifconfig eth1 | awk 'NR==2{print $2}'`
sed -i "s#${name##*.}\|${name1##*.}#$IP#g /etc/sysconfig/network-scripts/ifcfg-eth{0,1}"
systemctl restart network
#xshell所以字母为高亮

rz,sz

## 安装lrzsz
yum install -y lrzsz

## 如何把虚拟机的文件下载到windows里
#指令:sz
sz 文件名

## 如何把windows的文件上传到虚拟机里
#指令:rz

## 外网下载命令wget
安装wget
yum install -y wget

wget 下载地址 

-O:指定下载的位置和文件的名字

which

## 查找命令位置的命令 which
[root@web ~]# which yum 
/usr/bin/yum

#which 只能查找命令

sort

sort
## 语法
sort [选项]... File...
# 注意:默认按照每一行的第一个字符进行排序,如果字符相同就往后推,字母按照a-z的顺序排序,排序不修改源

文件内容
[root@web ~]# cat 1.txt 
b:3
c:2
a:4
e:5
d:1

[root@web ~]# sort 1.txt 
a:4
b:3
c:2
d:1
e:5
# 注意:默认按照每一行的第一个字符进行排序,如果字符相同就往后推
## 选项
-t:指定分隔符
[root@web ~]# sort -t ':' 1.txt 
a:4
b:3
c:2
d:1
e:5

-k:指定按照某一列,进行排序
[root@web ~]# sort -t ':' -k 2 1.txt 
d:1
c:2
b:3
a:4
e:5

-n:按照阿拉伯数字排序
[root@web ~]# sort -t ':' -k 2 -n 1.txt 
d:1
c:2
b:3
a:4
e:5

-r:reverse 倒叙排序
[root@web ~]# sort -rnt ':' -k 2 1.txt 
e:5
a:4
b:3
c:2
d:1
#rn的顺序可以调换 但t一定要在后面

uniq

## 指令: uniq
## 语法↓
uniq [选项]... 文件名...
## 注意,去重内容,必须是连续的行,必须要配合sort先排序,再去重,去重也不会修改源文件的内容
## 选项
-c:count 统计
[root@web ~]# sort 1.txt 
1
2
3
4
5
6
6
7
7
9
[root@web ~]# sort 1.txt | uniq
1
2
3
4
5
6
7
9

cut

##指令:cut(截取)
## 语法
cut [选项]... 文件名...
## 注意:cut默认没有分隔符
## 选项
-d:指定分隔符
-f:取列,选择要打印的列内容
-c 按字符集截取

wc

## 指令↓
wc:统计文件的行数,统计文件的单词数量,统计文件的字符数量
## 语法
wc [选项]... 文件名...
例↓
[root@14:53:14wudidesangege ~]\ wc /etc/services 
 11176        61033     670293 /etc/services
(文件行数) (单词数量) (字符数量)   #注:不找到选项时是默认显示三个选项的内容的

## 选项
-l:line 行,统计行数
[root@web ~]# wc -l /etc/services 
11176 /etc/services

-w:word 单词,统计单词数
[root@web ~]# wc -w /etc/services 
61033 /etc/services

-c:char 字符,统计字符数
[root@web ~]# wc -c /etc/services 
670293 /etc/services

echo

## 所见即所得
[root@web ~]# echo 1
1
[root@web ~]# echo 666
666

##拓展
#echo内容重定向到一个文件中
[root@web ~]# echo 123 > 123.txt
[root@web ~]# cat 123.txt 
123