linux基本命令
linux系统文件和目录是以单根的倒置数来组织。
"/"表示根。
大小写:linux中的文件和目录严格区分大小写。
分割:linux中路径以"/"分割和window相反。
![](https://img.haomeiwen.com/i4176128/0503ca2409345481.png)
ls -l 等价于ll
![](https://img.haomeiwen.com/i4176128/92a4161365e6d6a9.png)
mkdir 命令
![](https://img.haomeiwen.com/i4176128/7f9ea9bea256bd3e.png)
[root@localhost srv]# mkdir -p a/b/c
[root@localhost srv]# ls
rm命令 无敌删除(文件和目录)
-f 表示暴力删除
-r 表示循环删除
image.png
[root@localhost srv]# rm -f a/b/c/123.txt
[root@localhost srv]# ls a/b/c/
报错:表示删除的不是一个文件
[root@localhost srv]# rm -f a
rm: cannot remove 鈥榓鈥? Is a directory
[root@localhost srv]# rm -rf a
[root@localhost srv]# ls
cp拷贝命令
![](https://img.haomeiwen.com/i4176128/9506b70ec7924805.png)
[root@localhost srv]# mkdir 1 2
[root@localhost srv]# ls
1 2 a
[root@localhost srv]# cd 1
[root@localhost 1]# ls
[root@localhost 1]# touch 123.txt
[root@localhost 1]# ls
123.txt
[root@localhost 1]# cd ..
[root@localhost srv]# cp 1/123.txt 2/
[root@localhost srv]# ls 2/
123.txt
赋值目录 cp -r
cp -r 1/ 2/ 表示把1目录赋值到2/目录下
[root@localhost srv]# cp -r 1/ 2/
[root@localhost srv]# ls
[root@localhost srv]# cd 2
[root@localhost 2]# ls
1 123.txt
![](https://img.haomeiwen.com/i4176128/48d3b14ce5857601.png)
mv 移动文件及目录
把2目录移动到1目录下
[root@localhost srv]# ls
1 2 a
[root@localhost srv]# mv 2/ 1/
[root@localhost srv]# ls
1 a
重新命令
把123.txt 命名为1234.txt
[root@localhost 1]# ls
123.txt 2
[root@localhost 1]# mv 123.txt 1234.txt
[root@localhost 1]# ls
1234.txt 2
cat 查看文件
内容少了可以多了用more
![](https://img.haomeiwen.com/i4176128/2ea7a4e9511b88b6.png)
more 分屏查看文件内容
空格表示下一页
![](https://img.haomeiwen.com/i4176128/5df4ee68cb838416.png)
head 查看头部内容
head -5 查看前五行数据
![](https://img.haomeiwen.com/i4176128/efa1fa06aa1e8b07.png)
tail 查看尾部内容
![](https://img.haomeiwen.com/i4176128/32e85994c241139b.png)
.和./表示当前目录
![](https://img.haomeiwen.com/i4176128/605ed09760a6fc5d.png)
..和../表示父目录
![](https://img.haomeiwen.com/i4176128/29ce51dc842ba0c5.png)
![](https://img.haomeiwen.com/i4176128/06fb1c595b35e78c.png)
../在mkdir中的应用
![](https://img.haomeiwen.com/i4176128/a3417387a03a3a75.png)
所有的命令都可以用 当前目录./ 、父目录../、还和易使用相对路径和绝对路径。
du命令统计文件或者目录的大小
-s表示:占用空间大小
-h:人性化显示 kb、M,G
实例
显示etc下的文件占用大小
![](https://img.haomeiwen.com/i4176128/08aa9857958a2f3c.png)
显示etc本机目录下的所有文件占用大小
![](https://img.haomeiwen.com/i4176128/6cecea6dc50232df.png)
grep 在文件中查找符合条件的行
例如在password文件中查找 含有 root的行
![](https://img.haomeiwen.com/i4176128/67418a47c84d703b.png)
find 在目录中查找符合条件的文件或者目录
![](https://img.haomeiwen.com/i4176128/e6a6e36145138851.png)
![](https://img.haomeiwen.com/i4176128/4b9deaa7e7159791.png)
注意 -type d 和f的使用
![](https://img.haomeiwen.com/i4176128/59c16a917974f069.png)