Linux 命令
1:创建一个目录
mkdir /data
2:查询你创建的data目录
ls -ld /data
递归创建目录
mkdir -p /a/b/c
查看目录结构
tree a
如果出现
[[email protected] ~]# tree a
-bash: tree: command not found
就使用 yum -y install tree
[[email protected] ~]# tree /a/
/a/
└── b
└── c
3:在data目录下建一个文件并且查看该文件
[[email protected] ~]# touch /data/zhouyang.txt
[[email protected] ~]# ls /data/
zhouyang.txt
一次创建多个文件
[[email protected] ~]# touch {zhangsan,li,wangwu}.txt
[[email protected] ~]# ls
anaconda-ks.cfg install.log install.log.syslog li.txt wangwu.txt zhangsan.txt
创建100个文件
[[email protected] ~]# for f in `seq 100`;do touch $f.txt;done
[[email protected] ~]# ls
100.txt 16.txt 22.txt 29.txt 35.txt 41.txt 48.txt 54.txt 60.txt 67.txt 73.txt 7.txt 86.txt 92.txt 99.txt wangwu.txt
10.txt 17.txt 23.txt 2.txt 36.txt 42.txt 49.txt 55.txt 61.txt 68.txt 74.txt 80.txt 87.txt 93.txt 9.txt zhangsan.txt
11.txt 18.txt 24.txt 30.txt 37.txt 43.txt 4.txt 56.txt 62.txt 69.txt 75.txt 81.txt 88.txt 94.txt anaconda-ks.cfg
12.txt 19.txt 25.txt 31.txt 38.txt 44.txt 50.txt 57.txt 63.txt 6.txt 76.txt 82.txt 89.txt 95.txt install.log
13.txt 1.txt 26.txt 32.txt 39.txt 45.txt 51.txt 58.txt 64.txt 70.txt 77.txt 83.txt 8.txt 96.txt install.log.syslog
14.txt 20.txt 27.txt 33.txt 3.txt 46.txt 52.txt 59.txt 65.txt 71.txt 78.txt 84.txt 90.txt 97.txt li.txt
15.txt 21.txt 28.txt 34.txt 40.txt 47.txt 53.txt 5.txt 66.txt 72.txt 79.txt 85.txt 91.txt 98.txt
[[email protected] ~]#
向文件里面追加内容
[[email protected] data]# echo "I am study Linux...." > zhouyang.txt
[[email protected] data]# cat zhouyang.txt
I am study Linux....
[[email protected] data]#
注意: > 重定向
> 表示把文件里面的内容重置
>> 在原有的文件里面追加内容
或者使用 VI 编译器
多文本内容追加
[[email protected] ~]# cat >>/data/zhouyang.txt<<EOF
> I am boy.
> Imiss you.
> EOF
[[email protected] ~]# cat /data/zhouyang.txt
I am study Linux....
I am boy.
Imiss you.
[[email protected] ~]#
拷贝一个文件到另一个目录下
[[email protected] ~]# cp /data/zhouyang.txt /tmp/
[[email protected] ~]# cat /tmp/zhouyang.txt
I am study Linux....
I am boy.
Imiss you.
将一个data目录移动到ROOT 下
mv /data /root/
删除一个文件
rm zhouyang.txt文件
如果不需要提示
rm -f zhouyang.txt
删除一个目录
rm -fr data
把一个文件中I love you 不让他显示
[[email protected] data]# cat >>file.txt<<EOF
> I miss you
> I live you
> I thik you
> EOF
[[email protected] data]#
[[email protected] data]# grep -v thik file.txt
I miss you
I live you
[[email protected] data]# cat file.txt|grep -v "I miss you"
I live you
I thik you
[[email protected] data]
使用 grep -v thik file.txt 或者 cat file.txt|grep -v miss 过滤不需要的内容
head -2 file.txt 过滤掉 I thik you ;
在显示的时候删除I thik you
[[email protected] data]# sed -e ‘/I thik you/d‘ file.txt
I miss you
I live you
sed -e(相当于编辑) ‘/删除的内容/d‘ file.txt(连接删除的文件)
sed -n(相当于取消默认的输出) /I love you/p file.txt
[[email protected] data]# cat >test.txt<<EOF
> list
> test
> miss
> EOF
[[email protected] data]# sed -n /miss/p test.txt
miss
[[email protected] data]#
输出除 miss 以外的字符
[[email protected] data]# sed -n /[^miss]/p test.txt
list
test
[[email protected] data]#
list
test
Linux 三剑客
sed awk grep
grep 擅长过滤
在 root目录下创建一个 /value/list/test 目录
[[email protected] ~]# mkdir -p /usr/local/value/list/test
[[email protected] ~]# ls
[[email protected] local]# tree /usr/local/value/
/usr/local/value/
└── list
└── test
2 directories, 0 files
[[email protected] local]#
在 /tmp 目录下创建一个 test.txt
/mnt 目录下创建一个 test.txt
把/tmp/test.txt 文件复制到 /mnt/test.txt路径下, 不显示提示
[[email protected] ~]# touch /mnt/test.txt
[[email protected] ~]# touch /ftp/test.txt
touch: 无法创建"/ftp/test.txt": 没有那个文件或目录
[[email protected] ~]# touch /tmp/test.txt
[[email protected] ~]# \cp -f /tmp/test.txt /mnt/
[[email protected] ~]#
或者使用全路径
/bin/cp -f /tmp/test.txt /mnt/
alias 别名