网站建设作业,云南网络公司网站建设,企业法治建设工作计划,养生网站模板下载#x1f4a5;1、Linux基本指令
1.1 mv 指令
mv指令是move的缩写#xff0c;用来移动或重命名文件、目录#xff0c;经常用来备份文件或目录。 mv old_name new_name#xff1a; 重命名文件或目录mv file /path/to/directory#xff1a; 移动文件到指定目录 roothcss-ecs…1、Linux基本指令
1.1 mv 指令
mv指令是move的缩写用来移动或重命名文件、目录经常用来备份文件或目录。 mv old_name new_name 重命名文件或目录mv file /path/to/directory 移动文件到指定目录 roothcss-ecs-8f13:~/112# ls -l
total 8
drwxr-xr-x 2 root root 4096 Sep 16 20:13 dir
-rw-r--r-- 1 root root 78 Sep 16 20:04 test.c
roothcss-ecs-8f13:~/112# mv test.c name.c
roothcss-ecs-8f13:~/112# mv dir mydir
roothcss-ecs-8f13:~/112# ls -l
total 8
drwxr-xr-x 2 root root 4096 Sep 16 20:13 mydir
-rw-r--r-- 1 root root 78 Sep 16 20:04 name.c
roothcss-ecs-8f13:~/112# mv name.c ../
roothcss-ecs-8f13:~/112# ls -l ../
total 12
drwxr-xr-x 3 root root 4096 Sep 16 20:16 112
-rw-r--r-- 1 root root 78 Sep 16 20:04 name.c
drwx------ 3 root root 4096 Sep 16 11:32 snap
roothcss-ecs-8f13:~/112# ls -l
total 4
drwxr-xr-x 2 root root 4096 Sep 16 20:13 mydir
roothcss-ecs-8f13:~/112# mv mydir ../
roothcss-ecs-8f13:~/112# ls -l ../
total 16
drwxr-xr-x 2 root root 4096 Sep 16 20:16 112
drwxr-xr-x 2 root root 4096 Sep 16 20:13 mydir
-rw-r--r-- 1 root root 78 Sep 16 20:04 name.c
drwx------ 3 root root 4096 Sep 16 11:32 snap
roothcss-ecs-8f13:~/112# ls -l
total 0
roothcss-ecs-8f13:~/112# 1.2 cat 指令
语法 cat [选项] [文件] 功能 读取文件内容并将其输出到标准输出设备通常是终端或屏幕 常用选项 -b 对非空行输出行编号-n 对输出的所有行编号-s 不输出多行空行 roothcss-ecs-8f13:~/112# pwd
/root/112
roothcss-ecs-8f13:~/112# touch test.c
roothcss-ecs-8f13:~/112# ls
test.c
roothcss-ecs-8f13:~/112# nano test.c
roothcss-ecs-8f13:~/112# cat test.c
#include stdio.hint main()
{printf(hello world\n);return 0;
}
roothcss-ecs-8f13:~/112# cat -b test.c1 #include stdio.h2 int main()3 {4 printf(hello world\n);5 return 0;6 }
roothcss-ecs-8f13:~/112# cat -n test.c1 #include stdio.h2 3 int main()4 {5 printf(hello world\n);6 return 0;7 }
roothcss-ecs-8f13:~/112# cat -s test.c
#include stdio.hint main()
{printf(hello world\n);return 0;
}
roothcss-ecs-8f13:~/112# cat会把文件中的所有内容显示出来因此cat不适合看大文本适合看小文本。
如果cat后什么都不跟则通常情况下我们从键盘输入什么屏幕上就输出什么。
roothcss-ecs-8f13:~/112# cat
hello world
hello world
Are you ok?
Are you ok?tac指令 功能和cat相反逆序打印文件内容。
roothcss-ecs-8f13:~/112# ls
mydir name.c
roothcss-ecs-8f13:~/112# tac name.c
}return 0;printf(hello world\n);
{
int main()#include stdio.h
roothcss-ecs-8f13:~/112# 1.3 echo 指令
功能 echo 文本 在终端命令行界面上输出文本echo 文本文件如果文件不存在则新建 将文本写入到文件中 roothcss-ecs-8f13:~/112# ls -l
total 4
drwxr-xr-x 2 root root 4096 Sep 16 20:13 mydir
roothcss-ecs-8f13:~/112# echo hello world
hello world
roothcss-ecs-8f13:~/112# echo hello worldtest.txt
roothcss-ecs-8f13:~/112# ll
total 16
drwxr-xr-x 3 root root 4096 Sep 16 20:41 ./
drwx------ 7 root root 4096 Sep 16 20:23 ../
drwxr-xr-x 2 root root 4096 Sep 16 20:13 mydir/
-rw-r--r-- 1 root root 12 Sep 16 20:41 test.txt
roothcss-ecs-8f13:~/112# cat test.txt
hello world
roothcss-ecs-8f13:~/112# 1.4 重定向
Linux下一切皆文件Linux下显示器、键盘、网卡、普通文件等都可以看作文件只不过显示器只有写方法向显示器打印其实就是向显示器文件写入无法从显示器读取数据。键盘只有读方法。而普通文件具有读写两个功能。 echo指令默认把后面跟的文本写入显示器文件中。cat指令后面如果没有跟任何文件则默认从键盘文件中读取数据然后写入到显示器文件中。
上面我们用echo 文本输出重定向文件将文本写入到文件中如果文件不存在则新建。
roothcss-ecs-8f13:~/112# ll
total 12
drwxr-xr-x 3 root root 4096 Sep 16 22:47 ./
drwx------ 7 root root 4096 Sep 16 20:23 ../
drwxr-xr-x 2 root root 4096 Sep 16 21:57 dir/
roothcss-ecs-8f13:~/112# echo hello worldtest.txt
roothcss-ecs-8f13:~/112# cat test.txt
hello world
roothcss-ecs-8f13:~/112# echo Are you ok? test.txt
roothcss-ecs-8f13:~/112# cat test.txt
Are you ok?
roothcss-ecs-8f13:~/112# echo aa test.txt
roothcss-ecs-8f13:~/112# cat test.txt
aa
roothcss-ecs-8f13:~/112# 通过测试我们还可以得出如果指定的文件里面有内容则会先清空原内容然后再写入并不是覆盖。 当文件不存在时文件名可以新建空文件当文件存在时文件名可以清空文件内容 roothcss-ecs-8f13:~/112# ll
total 12
drwxr-xr-x 3 root root 4096 Sep 16 22:58 ./
drwx------ 7 root root 4096 Sep 16 20:23 ../
drwxr-xr-x 2 root root 4096 Sep 16 21:57 dir/
roothcss-ecs-8f13:~/112# test.txt
roothcss-ecs-8f13:~/112# ll
total 12
drwxr-xr-x 3 root root 4096 Sep 16 22:58 ./
drwx------ 7 root root 4096 Sep 16 20:23 ../
drwxr-xr-x 2 root root 4096 Sep 16 21:57 dir/
-rw-r--r-- 1 root root 0 Sep 16 22:58 test.txt
roothcss-ecs-8f13:~/112# echo Are you ok? test.txt
roothcss-ecs-8f13:~/112# ll
total 16
drwxr-xr-x 3 root root 4096 Sep 16 22:58 ./
drwx------ 7 root root 4096 Sep 16 20:23 ../
drwxr-xr-x 2 root root 4096 Sep 16 21:57 dir/
-rw-r--r-- 1 root root 12 Sep 16 22:59 test.txt
roothcss-ecs-8f13:~/112# cat test.txt
Are you ok?
roothcss-ecs-8f13:~/112# test.txt
roothcss-ecs-8f13:~/112# ll
total 12
drwxr-xr-x 3 root root 4096 Sep 16 22:58 ./
drwx------ 7 root root 4096 Sep 16 20:23 ../
drwxr-xr-x 2 root root 4096 Sep 16 21:57 dir/
-rw-r--r-- 1 root root 0 Sep 16 22:59 test.txt
roothcss-ecs-8f13:~/112# cat test.txt
roothcss-ecs-8f13:~/112# 用指定文件写入内容会把原内容删除掉如果我们就不想删除原始内容将新内容追加到原始内容后可以用追加重定向实现。
roothcss-ecs-8f13:~/112# cat test.txt
roothcss-ecs-8f13:~/112# echo Are you ok? test.txt
roothcss-ecs-8f13:~/112# cat test.txt
Are you ok?
roothcss-ecs-8f13:~/112# echo Hello test.txt
roothcss-ecs-8f13:~/112# cat test.txt
Are you ok?
Hello
roothcss-ecs-8f13:~/112# 除了和进行输出还有输入重定向符号。前面我们说了如果cat后面什么都不跟则默认从键盘上取数据。所以如果我们用输入重定向符号指定文件则会输出文件中的内容。
roothcss-ecs-8f13:~/112# cat test.txt
Are you ok?
Hello
roothcss-ecs-8f13:~/112# cat test.txt
Are you ok?
Hello
roothcss-ecs-8f13:~/112#