1:cd 命令讲解
#cd
[root@ecslinux-2021-0628 ~]# pwd #查看当前所在路径
/root
[root@ecslinux-2021-0628 ~]# cd /home/ #切换到指定目录:
[root@ecslinux-2021-0628 home]# pwd
/home
[root@ecslinux-2021-0628 home]#
#cd ~
[root@ecslinux-2021-0628 home]# cd /root/
[root@ecslinux-2021-0628 ~]# pwd
/root #为什么这里第一次cd和第二cd目录还是一样的呢?? 明明不一样的啊
[root@ecslinux-2021-0628 ~]# cd ~
[root@ecslinux-2021-0628 ~]# pwd
/root #因为cd ~ 是跳转到当前用户的家目录
[root@ecslinux-2021-0628 ~]#
#cd -
[root@ecslinux-2021-0628 ~]# cd /etc/yum.repos.d/
[root@ecslinux-2021-0628 yum.repos.d]# pwd
/etc/yum.repos.d
[root@ecslinux-2021-0628 yum.repos.d]# cd - #cd - 是返回本次目录的上一次所在的目录
/root
[root@ecslinux-2021-0628 ~]# pwd
/root
[root@ecslinux-2021-0628 ~]#
#cd ..
[root@ecslinux-2021-0628 etc]# cd /etc/yum.repos.d/
[root@ecslinux-2021-0628 yum.repos.d]# pwd
/etc/yum.repos.d
[root@ecslinux-2021-0628 yum.repos.d]# cd .. #cd ..和cd ../.. 都可以理解返回上一级目录 cd../..是上上级目录
[root@ecslinux-2021-0628 etc]# pwd
/etc
2:ls命令讲解, ls就是查看文件和目录的命令
这些事基本用到了,,有些大家看ls --help查看
#ls 查看当前目录下文件
[root@ecslinux-2021-0628 opt]# cd /opt/
[root@ecslinux-2021-0628 opt]# ls
nginx.conf
[root@ecslinux-2021-0628 opt]#
#ls -l || ll #这里个命令结果一样,都看当前文件的权限和家目录以及创建时间权限这个后面会说
[root@ecslinux-2021-0628 opt]# ls
nginx.conf
[root@ecslinux-2021-0628 opt]# ll
total 4
drwxr-xr-x 2 root root 4096 Jun 28 16:51 nginx.conf
[root@ecslinux-2021-0628 opt]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Jun 28 16:51 nginx.conf
[root@ecslinux-2021-0628 opt]#
#ls -a a=all 可以把全部文件输出出来
[root@ecslinux-2021-0628 opt]# cd /root
[root@ecslinux-2021-0628 ~]# ls
[root@ecslinux-2021-0628 ~]# ls
[root@ecslinux-2021-0628 ~]# ls
[root@ecslinux-2021-0628 ~]# ls
[root@ecslinux-2021-0628 ~]# ls
[root@ecslinux-2021-0628 ~]# 是真的没有数据吗??
[root@ecslinux-2021-0628 ~]# ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .cshrc .history .pki .ssh .tcshrc .viminfo
[root@ecslinux-2021-0628 ~]#
#ls -lh 显示文件大小
[root@ecslinux-2021-0628 etc]# ls -lh
total 1.4M
-rw-r--r--. 1 root root 16 Feb 26 17:27 adjtime
-rw-r--r-- 1 root root 1.5K Apr 1 2020 aliases
-rw-r--r-- 1 root root 12K Feb 26 17:38 aliases.db
drwxr-xr-x. 2 root root 4.0K Feb 26 17:37 alternatives
-rw------- 1 root root 541 Aug 9 2019 anacrontab
-rw-r--r-- 1 root root 55 Aug 8 2019 asound.conf
-rw-r--r-- 1 root root 1 Oct 31 2018 at.deny
drwxr-x---. 3 root root 4.0K Feb 26 17:36 audisp
drwxr-x---. 3 root root 4.0K Feb 26 17:36 audit
drwxr-xr-x. 2 root root 4.0K Feb 26 17:38 bash_completion.d
-rw-r--r-- 1 root root 2.8K Apr 1 2020 bashrc
drwxr-xr-x. 2 root root 4.0K Feb 3 00:34 binfmt.d
-rw-r--r--. 1 root root 38 Apr 29 2018 centos-release
-rw-r--r--. 1 root root 51 Apr 29 2018 centos-release-upstream
drwxr-xr-x. 2 root root 4.0K Oct 13 2020 chkconfig.d
-rw-r--r-- 1 root root 815 Feb 26 17:42 chrony.conf
-rw-r----- 1 root chrony 481 Aug 8 2019 chrony.keys
3mv:移动文件或改名
[root@ecslinux-2021-0628 opt]# touch n.conf #创建一个文件
[root@ecslinux-2021-0628 opt]# ls
n.conf
[root@ecslinux-2021-0628 opt]# echo "111111" >> n.conf
[root@ecslinux-2021-0628 opt]# cat n.conf
111111
#修改文件名称,和重命名一个道理,不会修改数据
[root@ecslinux-2021-0628 opt]# mv n.conf nginx.conf
[root@ecslinux-2021-0628 opt]# cat nginx.conf
111111
[root@ecslinux-2021-0628 opt]# ls
nginx.conf
[root@ecslinux-2021-0628 opt]#
#移动
[root@ecslinux-2021-0628 opt]# ls
nginx.conf
[root@ecslinux-2021-0628 opt]# mv nginx.conf /home/
[root@ecslinux-2021-0628 opt]# ls
[root@ecslinux-2021-0628 opt]# cd /home/
[root@ecslinux-2021-0628 home]# ls
nginx.conf
[root@ecslinux-2021-0628 home]#
4.touch文件创建
[root@ecs-eb3c ~]# touch k.txt
[root@ecs-eb3c ~]# ls
k.txt
[root@ecs-eb3c ~]# touch {1..100}.txt
[root@ecs-eb3c ~]# ls
100.txt 19.txt 28.txt 37.txt 46.txt 55.txt 64.txt 73.txt 82.txt 91.txt k.txt
10.txt 1.txt 29.txt 38.txt 47.txt 56.txt 65.txt 74.txt 83.txt 92.txt
11.txt 20.txt 2.txt 39.txt 48.txt 57.txt 66.txt 75.txt 84.txt 93.txt
12.txt 21.txt 30.txt 3.txt 49.txt 58.txt 67.txt 76.txt 85.txt 94.txt
13.txt 22.txt 31.txt 40.txt 4.txt 59.txt 68.txt 77.txt 86.txt 95.txt
14.txt 23.txt 32.txt 41.txt 50.txt 5.txt 69.txt 78.txt 87.txt 96.txt
15.txt 24.txt 33.txt 42.txt 51.txt 60.txt 6.txt 79.txt 88.txt 97.txt
16.txt 25.txt 34.txt 43.txt 52.txt 61.txt 70.txt 7.txt 89.txt 98.txt
17.txt 26.txt 35.txt 44.txt 53.txt 62.txt 71.txt 80.txt 8.txt 99.txt
18.txt 27.txt 36.txt 45.txt 54.txt 63.txt 72.txt 81.txt 90.txt 9.txt
5.mkdir目录创建
[root@ecs-eb3c ~]# mkdir file #创建file文件
[root@ecs-eb3c ~]# ls
100.txt 19.txt 28.txt 37.txt 46.txt 55.txt 64.txt 73.txt 82.txt 91.txt file
10.txt 1.txt 29.txt 38.txt 47.txt 56.txt 65.txt 74.txt 83.txt 92.txt k.txt
[root@ecs-eb3c ~]# mv *.txt file/ mv移动全部已txt结尾的文件
[root@ecs-eb3c ~]# ls
file
[root@ecs-eb3c ~]# cd file/ 进入file文件
[root@ecs-eb3c file]# ls
100.txt 19.txt 28.txt 37.txt 46.txt 55.txt 64.txt 73.txt 82.txt 91.txt
10.txt 1.txt 29.txt 38.txt 47.txt 56.txt 65.txt 74.txt 83.txt 92.txt
11.txt 20.txt 2.txt 39.txt 48.txt 57.txt 66.txt 75.txt 84.txt 93.txt
12.txt 21.txt 30.txt 3.txt 49.txt 58.txt 67.txt 76.txt 85.txt 94.txt
13.txt 22.txt 31.txt 40.txt 4.txt 59.txt 68.txt 77.txt 86.txt 95.txt
14.txt 23.txt 32.txt 41.txt 50.txt 5.txt 69.txt 78.txt 87.txt 96.txt
15.txt 24.txt 33.txt 42.txt 51.txt 60.txt 6.txt 79.txt 88.txt 97.txt
16.txt 25.txt 34.txt 43.txt 52.txt 61.txt 70.txt 7.txt 89.txt 98.txt
17.txt 26.txt 35.txt 44.txt 53.txt 62.txt 71.txt 80.txt 8.txt 99.txt
18.txt 27.txt 36.txt 45.txt 54.txt 63.txt 72.txt 81.txt 90.txt 9.txt
[root@ecs-eb3c file]# pwd
/root/file
[root@ecs-eb3c file]# mkdir /opt/file/k.file
mkdir: cannot create directory ‘/opt/file/k.file’: No such file or directory
#无法创建‘/opt/file/k.file
[root@ecs-eb3c file]# mkdir -p /opt/file/k.file
[root@ecs-eb3c file]# cd /opt/file/k.file/
[root@ecs-eb3c k.file]# ls
[root@ecs-eb3c k.file]# pwd
/opt/file/k.file
[root@ecs-eb3c k.file]#
mkdir: cannot create directory ‘/opt/file/k.file’: No such file or directory
#无法创建‘/opt/file/k.file 原因是file目录不存在,k.file目录也不存在。
此时应加上参数-p,即没有找到此目录就自动创建。
6.chmod--修改权限
我们权限分为了 rwx rwx rwx r是读权限为4 w是写权限为2 x是执行权限是1
rw- r-- r-- 分为 u:所有者 g:所在组 o:其他组 a:所有人(u、g、o的总和)
[root@ecs-eb3c file]# ll -l
total 0
-rw-r--r-- 1 root root 0 Jul 2 11:28 10.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 1.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 2.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 3.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 4.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 5.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 6.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 7.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 8.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 9.txt
[root@ecs-eb3c file]#
我们下面授权
第一种是我们数字授权
我们如上图看10.txt全是 644
我们给他一个执行权限 他们层级关系也就是 一个老师有组长,组长还有组员
[root@ecs-eb3c file]# chmod +711 10.txt
[root@ecs-eb3c file]# chmod +711 10.txt
[root@ecs-eb3c file]# ll -l
total 0
-rwxr-xr-x 1 root root 0 Jul 2 11:28 10.txt
还有一种授权是
[root@ecs-eb3c file]# chmod g+x 5.txt
[root@ecs-eb3c file]# ls -l
total 0
-rw-r-xr-- 1 root root 0 Jul 2 11:28 5.txt
[root@ecs-eb3c file]# chmod u+x 5.txt
[root@ecs-eb3c file]# ls -l
total 0
-rwxr-xr-- 1 root root 0 Jul 2 11:28 5.txt
取消授权用-符号
-rw-r--r-- 1 root root 0 Jul 2 11:28 8.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 9.txt
[root@ecs-eb3c file]# chmod u-r 8.txt
[root@ecs-eb3c file]# ls -l
--w-r--r-- 1 root root 0 Jul 2 11:28 8.txt
7.chown用法 属主和属组
[root@ecs-eb3c file]# chown root:tom 8.txt
[root@ecs-eb3c file]# ll -l
total 0
-rwxr-xr-x 1 root root 0 Jul 2 11:28 10.txt
-rwxr--r-- 1 root root 0 Jul 2 11:28 1.txt
---xr--r-- 1 root root 0 Jul 2 11:28 2.txt
-rwxr--r-- 1 root root 0 Jul 2 11:28 3.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 4.txt
-rwxr-xr-- 1 root root 0 Jul 2 11:28 5.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 6.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 7.txt
--w-r--r-- 1 root tom 0 Jul 2 11:28 8.txt
-rw-r--r-- 1 root root 0 Jul 2 11:28 9.txt
[root@ecs-eb3c file]#
8.echo输入文本
我们创建文件可以echo直接交互输入文本 >覆盖 >>追加
[root@ecs-eb3c file]# echo "netstat -pltun|grep 212" > 8.txt
[root@ecs-eb3c file]# cat 8.txt
netstat -pltun|grep 212
[root@ecs-eb3c file]# echo "netstat -pltun|grep 212a" >> 8.txt
[root@ecs-eb3c file]# cat 8.txt
netstat -pltun|grep 212
netstat -pltun|grep 212a
9.cat more less head
cat 是查看全部文件,但是文件内容太多看起来很麻烦我们可以用more
这里有百分% 按空格是已页来输出,,回车键是按行来输出 less 我理解其实和more是一样的
cat -n yanshi.json 显示行
[root@ecs-eb3c file]# head -n 10 yanshi.json 按照行数输入内容
{
"hops": [
{
"from": "CSV文件输入",
"to": "空值转换"
},
{
"from": "空值转换",
"to": "文件输出"
}
CP 复制
cp 就是把内容负责到其他地方
[root@ecs-eb3c file]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt yanshi.json
[root@ecs-eb3c file]# pwd
/root/file
[root@ecs-eb3c file]# cp 1.txt /opt/file/k.file/
[root@ecs-eb3c file]# ll /opt/file/k.file/
total 0
-rwxr--r-- 1 root root 0 Jul 2 12:06 1.txt
[root@ecs-eb3c file]#