Linux基本指令
环境:VMware Workstation
1.mkdir指令
linux@ubuntu:~$ mkdir test //创建一个大目录test,在里面执行我们的指令操作.养成好习惯,
不然以后用久系统中会有一堆乱七八糟不知道是什么的目录
linux@ubuntu:~$ cd test //进入test文件夹中
linux@ubuntu:~/test$ mkdir test1 //创建test1文件夹
linux@ubuntu:~/test$ mkdir test2 //创建test2文件夹
linux@ubuntu:~/test$ cd test1 //进入test1文件夹中
linux@ubuntu:~/test/test1$ //"$" 前多了test1即表示已在test1文件夹目录下
linux@ubuntu:~/test/test1$ ls
hello.txt
linux@ubuntu:~/test$ cdtest1 //cd test1少了空格的错误示范,进入失败
No command 'cdtest1' found, did you mean:
'cctest1' from package 'leptonica-progs' ( universe)
cdtest1: command not found
2.touch指令
linux@ubuntu:~/ test/ test1$ touch hello. txt / / 创建hello. txt
linux@ubuntu:~/ test/ test1$ ls / / 显示目录中的内容
hello. txt
linux@ubuntu:~/ test/ test1$ gedit hello. txt / / 编辑hello. txt
^Z
[ 1] + Stopped gedit hello. txt
linux@ubuntu:~/ test/ test1$ ls
hello. txt
[ 1] + Killed gedit hello. txt
linux@ubuntu:~/ test/ test1$ cp hello. txt . . / test2 / / 将hello. txt拷贝到test2目录
linux@ubuntu:~/ test/ test1$ ls
hello. txt
linux@ubuntu:~/ test/ test1$ cd . . / test2 / / 进入test2目录中
linux@ubuntu:~/ test/ test2$ ls / / 显示目录中的内容
hello. txt
3.mv指令和rm指令
linux@ubuntu:~/test/test2$ mv hello.txt hello //将hello.txt改名为hello
linux@ubuntu:~/test/test2$ ls
hello
linux@ubuntu:~/test/test2$ rm hello //删除hello文件
linux@ubuntu:~/test/test2$ ls //文件夹中没文件直接跳到下一个指令行
linux@ubuntu:~/test/test2$ cd .. /test1 //返回test1目录
linux@ubuntu:~/test/test1$ ls
hello.txt
4.编译C文件
linux@ubuntu:~/test/test1$ gedit hello.c //创建并编辑文件hello.c
linux@ubuntu:~/test/test1$ gedit hello.c
^C //保存好hello.c 后回到指令界面按ctrl+c退出编辑
linux@ubuntu:~/test/test1$ gcc -o hello hello.c //编译hello.c生成可执行文件hello
linux@ubuntu:~/test/test1$ ls
hello hello.c hello.txt
linux@ubuntu:~/test/test1$ ./hello //执行hello
hello world! linux@ubuntu:~/test/test1$ cd.. //显示出了hello world!
编写c程序时注意代码规范,不然就像下面一样,一堆错误,不过多写几遍就可以记住错误,避免下次再犯
5.压缩和解压指令
linux@ubuntu:~/test/test1$ cd //cd退出到home目录下
linux@ubuntu:~$ cd test //重新进入最开始创建的test目录
linux@ubuntu:~/test$ ls
test1 test2
linux@ubuntu:~/test$ tar zcvf test.tar.gz test1 //将目录test1压缩为test.tar.gz文件
test1/
test1/hello.c
test1/hello
test1/hello.txt
linux@ubuntu:~/test$ mkdir tmp //创建tmp目录
linux@ubuntu:~/test$ cp test1.tar.gz tmp //这里出现错误,因为前面压缩的文件名test1.tar.gz tmp写错了
cp: cannot stat `test1.tar.gz': No such file or directory
linux@ubuntu:~/test$ tar zcvf test1.tar.gz test1 //将目录test1压缩为test1.tar.gz文件
test1/
test1/hello.c
test1/hello
test1/hello.txt
linux@ubuntu:~/test$ ls
test1 test1.tar.gz test2 test.tar.gz tmp
linux@ubuntu:~/test$ rm test.tar.gz //rm删除指令,删除test.tar.gz文件
linux@ubuntu:~/test$ ls
test1 test1.tar.gz test2 tmp
linux@ubuntu:~/test$ cp test1.tar.gz tmp //将压缩为文件test1.tar.gz拷贝到tmp目录
linux@ubuntu:~/test$ cd tmp
linux@ubuntu:~/test/tmp$ ls
test1.tar.gz
linux@ubuntu:~/test/tmp$ tar zxvf test1.tar.gz //将压缩为文件test1.tar.gz解压
test1/
test1/hello.c
test1/hello
test1/hello.txt
linux@ubuntu:~/test/tmp$ ls
test1 test1.tar.gz
开始学习的时候会觉得难记,与其背背然后忘记,还是多动手比较好,其实实操过程中可以发现错误,记忆效果是最好的