linux命令实践
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux命令实践相关的知识,希望对你有一定的参考价值。
7.pwd 显示当前所在目录8.cd 切换目录/进入目录中
cd ~ ===== cd 进入当前用户家目录
cd .. 进入当前目录的上一级目录
cd . 进入当前目录
cd - 回到上一次目录
9.mkdir 创建目录,默认创建一层目录
make directory
-p 递归创建目录
[[email protected] network-scripts]# mkdir /oldboy
[[email protected] network-scripts]# ls /oldboy/
[[email protected] network-scripts]# ls -l /oldboy/
total 0
[[email protected] ~]# mkdir /data/ole/li
mkdir: cannot create directory ‘/data/ole/li’: No such file or directory
[[email protected] ~]# mkdir -p /data/ole/li
10.ls 显示目录内容
list
参数 -l 显示详细信息,可以同时查看多个文件内容,输入具体路径
[[email protected] tmp]# ls
1.txt 1.txt.bak kobe kobe.bak
[[email protected] tmp]# ls -l kobe
total 0
[[email protected] tmp]# ls -l 1.txt
-rw-r--r-- 1 root root 0 Mar 28 17:18 1.txt
11.touch 创建文件和更改时间戳,可以递归创建文件,但是前面目录不存在会报错,需要前面的目录已经存在
[[email protected] tmp]# ls
[[email protected] tmp]# touch 1 2
[[email protected] tmp]# touch 1/2/3
touch: cannot touch ‘1/2/3’: Not a directory
[[email protected] tmp]# mkdir kobe
[[email protected] tmp]# touch kobe/24
[[email protected] tmp]# ls
1 2 kobe mary
[[email protected] tmp]# cd kobe/
[[email protected] kobe]# ls
24
touch 更改时间戳
[[email protected] tmp]# ls -l
total 0
-rw-r--r-- 1 root root 0 Mar 28 17:17 1.txt
[[email protected] tmp]# touch 1.txt
[[email protected] tmp]# ls -l
total 0
-rw-r--r-- 1 root root 0 Mar 28 17:18 1.txt
12.echo 输出信息到屏幕,一般配合touch和mkdir创建文件或者目录使用
[[email protected] ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[[email protected] ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
[[email protected] ~]# echo oldboy{0..10}
oldboy0 oldboy1 oldboy2 oldboy3 oldboy4 oldboy5 oldboy6 oldboy7 oldboy8 oldboy9 oldboy10
[[email protected] ~]# echo oldboy{01..10}.txt
oldboy01.txt oldboy02.txt oldboy03.txt oldboy04.txt oldboy05.txt oldboy06.txt oldboy07.txt oldboy08.txt oldboy09.txt oldboy10.txt
[[email protected] tmp]# echo kobe {13..15}
kobe 13 14 15
[[email protected] ~]# touch {11..20}.txt
[[email protected] ~]# ls
11.txt 14.txt 17.txt 20.txt hh
12.txt 15.txt 18.txt aa uu
13.txt 16.txt 19.txt anaconda-ks.cfg
[[email protected] ~]# mkdir {01..10}
[[email protected] ~]# ls
01 05 09 13.txt 17.txt aa
02 06 10 14.txt 18.txt anaconda-ks.cfg
03 07 11.txt 15.txt 19.txt hh
04 08 12.txt 16.txt 20.txt uu
- cp 复制文件或者目录,默认无法复制目录
-r 递归复制,复制目录和目录的内容
[[email protected] tmp]# cp kobe /root
cp: omitting directory ‘kobe’-----忽略
[[email protected] tmp]# cp -r kobe /root
[[email protected] tmp]# cd /root
[[email protected] ~]# ls
01 05 09 12 14 16 18 20 c hh
02 06 10 12.txt 14.txt 16.txt 18.txt 20.txt d kobe
cp的备份功能(文件和目录都可以)
[[email protected] ~]# cp /oldboy/oldboy.txt /oldboy/oldboy.txt.bak
[[email protected] ~]# cd /oldboy
[[email protected] oldboy]# ls
alex oldboy.txt oldboy.txt.bak
[[email protected] tmp]# ls
1.txt kobe
[[email protected] tmp]# cp kobe kobe.bak
cp: omitting directory ‘kobe’
[[email protected] tmp]# cp 1.txt 1.txt.bak
[[email protected] tmp]# ls
1.txt 1.txt.bak kobe
[[email protected] tmp]# cp -r kobe kobe.bak
[[email protected] tmp]# ls
1.txt 1.txt.bak kobe kobe.bak
以上是关于linux命令实践的主要内容,如果未能解决你的问题,请参考以下文章