目录
1、touch指令
touch+你想要创建的文件名
功能:在当前路径下创建一个普通文件
示例:在当前路径下创建一个test.txt文件
[root@ecs-67186 ~]# touch test.txt
2、mkdir指令
mkdir+目录名
功能:在当前路径下创建一个目录
mkdir -p 可以创建一长串路径
示例:在当前路径下创建一个dir的目录
[root@ecs-67186 ~]# mkdir dir
[root@ecs-67186 day1]# mkdir -p d1/d2/d3/4
使用tree命令就可以看到我们创建的一长串路径了
[root@ecs-67186 day1]# tree d1
d1
└── d2
└── d3
└── 43 directories, 0 files
一开始是默认没有tree的要自己下,可以使用:yum install -y tree 进行下载
3、ls指令
功能:显示当前路径下的文件名以及目录
ls也常与下列一些选项搭配使用
ls -a :列出目录下的所有文件,包括以.开头的隐含文件
ls -l :列出文件的详细信息。
ls -1 :一行只输出一个文件
注意:指令和选项之间要带空格,否则会出错
示例:
4、pwd指令
功能:显示用户当前所在的目录
示例:
[root@ecs-67186 day1]# pwd
/root/day1
5、cd指令
功能:切换工作目录
.作用:可以限定我们要执行的可执行程序在什么位置
..作用:帮助我们进行路径切换
cd ~ :当前用户的工作目录
cd - :返回最近访问目录
示例:
[root@ecs-67186 day1]# pwd
/root/day1
[root@ecs-67186 day1]# cd ..
[root@ecs-67186 ~]# pwd
/root[root@ecs-67186 ~]# cd ..
[root@ecs-67186 /]# pwd
/[root@ecs-67186 /]# cd ..
[root@ecs-67186 /]# pwd
/
其中/叫做路径分割符,第一个/我们称它为根目录,回退到只用一个/时,就不能回退了[root@ecs-67186 day1]# cd ~
[root@ecs-67186 ~]# pwd
/root
其实linux下的目录结构,本质上是一个多叉树结构
那么它的文件种类无非就两种:目录和文件或者空目录,其中目录中可以有其它目录或者文件,而文件下不能有目录或者其它文件。所以所有的普通文件或者空目录一定是叶子结点
绝对路径:从根目录开始一直到你所要找的文件,这一串路径就叫做绝对路径。
[root@ecs-67186 day1]# ls /root/day1/test.txt
/root/day1/test.txt
相对路径:不以根目录开始,而是以当前路径为参考点,这样定位文件的方式叫做相对路径[root@ecs-67186 day1]# ls d1/d2
d3
6、rmdir指令&&rm指令
rmdir是一个与mkdir相对的指令
功能:删除目录
常用选项:
rm -f : 强置删除,即使文件属性为只读(即写保护)
rm -r : 用递归的方式删除目录及其下所有文件
rm -i : 删除前询问是否要删除
不过-r和-f常常搭配使用,表示强置删除该目录下的所有文件
示例:
[root@ecs-67186 day1]# rm -rf d1
[root@ecs-67186 day1]# ll
total 4
drwxr-xr-x 2 root root 4096 Jul 31 10:21 dir
-rw-r--r-- 1 root root 0 Jul 31 10:21 test.txt[root@ecs-67186 day1]# touch d1
[root@ecs-67186 day1]# ll
total 4
-rw-r--r-- 1 root root 0 Aug 8 10:38 d1
drwxr-xr-x 2 root root 4096 Jul 31 10:21 dir
-rw-r--r-- 1 root root 0 Jul 31 10:21 test.txt
[root@ecs-67186 day1]# rm -i d1
rm: remove regular empty file ‘d1’? y
[root@ecs-67186 day1]# ll
total 4
drwxr-xr-x 2 root root 4096 Jul 31 10:21 dir
-rw-r--r-- 1 root root 0 Jul 31 10:21 test.txt
7、man指令
功能:访问Linux手册页
示例:[root@ecs-67186 day1]# man mkdir
按q键退出
如果你觉得你的man手册不全你可以执行一下这个命令: yum -y install -y man-pages 更新一下手册。
8、nano指令
功能:linux下的一个文件编辑器
如果没有的话可以下一个:yum install -y nano
示例:
[root@ecs-67186 day1]# nano test.txt
[root@ecs-67186 day1]# cat test.txt
#include <stdio.h>
int main()
{
printf("hello linux\n");
return 0;
}
退出编辑按Ctrl+x,然后按y确认保存,最后按回车就行了
9、cat指令
功能: 打印目标文件的内容
常用选项:
cat -b : 对非空输出行编号
cat -n : 对输出的所有行编号
cat -s : 不输出多行空行
与cat相对的还有一个tac,tac是倒着查看目标文件的内容
示例:
[root@ecs-67186 day1]# cat test.txt
#include <stdio.h>
int main()
{
printf("hello linux\n");
return 0;
}
[root@ecs-67186 day1]# tac test.txt
}
return 0;
printf("hello linux\n");
{
int main()
#include <stdio.h>[root@ecs-67186 day1]# cat -n test.txt
1 #include <stdio.h>
2 int main()
3 {
4 printf("hello linux\n");
5 return 0;
6 }
10、cp指令
功能:拷贝普通文件或目录
说明:cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中。若同时指定多个文件或目录,而最后的目的地并非一个已存在的目录,则会出现错误信息
常用选项:
cp -f : 强行复制文件或目录, 不论目的文件或目录是否已经存在
cp -i : 覆盖文件之前先询问用户
cp -r : 递归处理,将指定目录下的文件与子目录一并处理
示例:
[root@ecs-67186 day1]# cp test.txt /root
[root@ecs-67186 day1]# ll
total 8
drwxr-xr-x 2 root root 4096 Jul 31 10:21 dir
-rw-r--r-- 1 root root 69 Aug 8 11:06 test.txt
[root@ecs-67186 day1]# cd ..
[root@ecs-67186 ~]# tree
.
├── day1
│ ├── dir
│ └── test.txt
├── file.txt
├── hello.c
├── install.sh
├── project.tgz
├── test.c
└── test.txt2 directories, 7 files
11、mv指令
功能:1、更改文件或目录名(同等路径下) 2、将文件或目录从当前路径移动到新的路径中
常用选项:
mv -f :若目标文件已经存在,不会询问而直接覆盖
mv -i :若目标文件已经存在,就会询问是否覆盖
示例: