文章目录
Linux基本指令ls和cd
cd指令
进入想打开的目录。
1 返回上一级目录
[email protected]:~/anaconda3$ cd ..
[email protected]:~$
2 去往子文件夹
[email protected]:~$ cd anaconda3/bin
[email protected]:~/anaconda3/bin$
3 返回刚刚所在的目录
[email protected]:~/anaconda3/bin$ cd -
/home/lzs
4 向上返回两次
[email protected]:~/anaconda3/bin$ cd ../../
[email protected]:~$
5 去往Home
[email protected]:~/anaconda3/include$ cd ~
[email protected]:~$
6 去往任何目录
[email protected]:~$ cd /home/lzs/anaconda3/bin
[email protected]:~/anaconda3/bin$
ls指令
1 ls -l输出详细信息
[email protected]:~$ ls -l
总用量 100
drwxrwxr-x 23 lzs lzs 4096 6月 15 10:50 anaconda3
drwxrwxr-x 2 lzs lzs 4096 7月 1 20:49 bin
drwxrwxr-x 5 lzs lzs 4096 7月 1 20:53 catkin_ws
drwxrwxrwx 8 lzs lzs 4096 6月 28 21:20 Coursera_deep_learning
drwxrwxr-x 4 lzs lzs 4096 6月 15 12:03 cuda
-rw-r--r-- 1 lzs lzs 8980 6月 14 20:01 examples.desktop
drwxrwxr-x 5 lzs lzs 4096 8月 5 09:44 lzs
drwxrwxr-x 2 lzs lzs 4096 7月 1 16:32 MachineLearning
drwxr-xr-x 11 lzs lzs 4096 6月 15 12:38 NVIDIA_CUDA-9.0_Samples
drwxrwxr-x 3 lzs lzs 4096 7月 1 20:49 opt
drwxrwxr-x 8 lzs lzs 4096 10月 7 14:04 PycharmProjects
drwxrwxr-x 3 lzs lzs 4096 8月 4 20:06 RobotLearning
drwxrwxrwx 2 lzs lzs 4096 9月 26 10:15 Shared
drwxrwxr-x 15 lzs lzs 4096 3月 9 2018 tutorials-master
drwxrwxr-x 5 lzs lzs 4096 7月 1 19:11 tutorial_ws
drwxr-xr-x 2 lzs lzs 4096 6月 15 04:07 公共的
drwxr-xr-x 2 lzs lzs 4096 6月 15 04:07 模板
drwxr-xr-x 2 lzs lzs 4096 6月 15 04:07 视频
drwxr-xr-x 3 lzs lzs 4096 6月 15 10:16 图片
drwxr-xr-x 6 lzs lzs 4096 9月 26 20:59 文档
drwxr-xr-x 2 lzs lzs 4096 7月 1 20:46 下载
drwxr-xr-x 3 lzs lzs 4096 7月 1 13:41 音乐
drwxr-xr-x 2 lzs lzs 4096 10月 7 22:15 桌面
2 ls -a显示所有文件
[email protected]:~$ ls -a
. .gnupg .rnd
.. .gvfs RobotLearning
anaconda3 .ICEauthority .roboware-studio
.astropy .ipython .ros
.bash_history .java .sdformat
.bash_logout .jupyter Shared
.bashrc .keras .sogouinput
.bashrc-anaconda3.bak .local .sudo_as_admin_successful
bin lzs tutorials-master
.cache MachineLearning tutorial_ws
catkin_ws .mozilla .vscode
.compiz .mplayer .Xauthority
.conda .nano .xinputrc
.config .nv .xsession-errors
Coursera_deep_learning NVIDIA_CUDA-9.0_Samples .xsession-errors.old
cuda opt 公共的
.dbus .pki 模板
.dmrc .presage 视频
examples.desktop .profile 图片
.gazebo .PyCharm2018.1 文档
.gconf PycharmProjects 下载
.gitconfig .python_history 音乐
.gnome .python_history-07882.tmp 桌面
3 ls -lh方便观看
[email protected]:~$ ls -a
. .gnupg .rnd
.. .gvfs RobotLearning
anaconda3 .ICEauthority .roboware-studio
.astropy .ipython .ros
.bash_history .java .sdformat
.bash_logout .jupyter Shared
.bashrc .keras .sogouinput
.bashrc-anaconda3.bak .local .sudo_as_admin_successful
bin lzs tutorials-master
.cache MachineLearning tutorial_ws
catkin_ws .mozilla .vscode
.compiz .mplayer .Xauthority
.conda .nano .xinputrc
.config .nv .xsession-errors
Coursera_deep_learning NVIDIA_CUDA-9.0_Samples .xsession-errors.old
cuda opt 公共的
.dbus .pki 模板
.dmrc .presage 视频
examples.desktop .profile 图片
.gazebo .PyCharm2018.1 文档
.gconf PycharmProjects 下载
.gitconfig .python_history 音乐
.gnome .python_history-07882.tmp 桌面
4 ls --help查看帮助
[email protected]:~$ ls --help
Linux基本指令touch,cp和mv
touch指令(新建文件)
[email protected]:~/LinuxTest$ touch Test1.py Test2.doc Test3.ppt
[email protected]:~/LinuxTest$ ls
Test1.py Test2.doc Test3.ppt
cp指令(复制文件)
1 复制文件
[email protected]:~/LinuxTest$ cp Test1.py Test1copy.py
[email protected]:~/LinuxTest$ ls
Test1copy.py Test1.py Test2.doc Test3.ppt
2 -i (interactive:互动)提示信息,如果已经存在要复制的文件,加上-i会给提示信息
[email protected]:~/LinuxTest$ cp Test1.py Test1copy.py
[email protected]:~/LinuxTest$ cp -i Test1.py Test1copy.py
cp:是否覆盖'Test1copy.py'? y
[email protected]:~/LinuxTest$
3 复制到文件夹下
[email protected]:~/LinuxTest$ cp Test2.doc secondFile1/
4 复制文件夹,需要加上-R(recursive)
[email protected]:~/LinuxTest$ cp -R secondFile1/ secondFile2/
5 复制多个文件,复制名字部分相同的多个文件
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile2 Test1copy.py Test1.py Test2.doc Test3.ppt
[email protected]:~/LinuxTest$ mkdir secondFile3
[email protected]:~/LinuxTest$ cp Test* secondFile3
或者
[email protected]:~/LinuxTest$ cp Test1.py Test2.doc secondFile4/
[email protected]:~/LinuxTest$ cd secondFile4
[email protected]:~/LinuxTest/secondFile4$ ls
Test1.py Test2.doc
mv指令(移动文件)
1 移动去另一个文件夹
[email protected]:~/LinuxTest$ cp Test1.py Test2.doc secondFile4/
[email protected]:~/LinuxTest$ cd secondFile4
[email protected]:~/LinuxTest/secondFile4$ ls
Test1.py Test2.doc
2 重命名文件
[email protected]:~/LinuxTest/secondFile1$ ls
Test1.py Test2.doc Test3.ppt
[email protected]:~/LinuxTest/secondFile1$ mv Test1.py Test1mv.py
[email protected]:~/LinuxTest/secondFile1$ ls
Test1mv.py Test2.doc Test3.ppt
3 查看帮助
直接加上--help
Linux基本指令mkdir,rmdir和rm
mkdir建立文件夹
[email protected]:~/LinuxTest$ mkdir secondFile5
rmdir移除文件夹
只能移除空的文件夹
[email protected]:~/LinuxTest$ rmdir secondFile5
rm移除文件
1 移除单个文件
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile3 Test1copy.py Test3.ppt
secondFile2 secondFile4 Test2.doc
[email protected]:~/LinuxTest$ rm Test1copy.py
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile2 secondFile3 secondFile4 Test2.doc Test3.ppt
2 -i或-I有提示的移除文件(为了避免误删)
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile2 secondFile3 secondFile4 Test2.doc Test3.ppt
[email protected]:~/LinuxTest$ rm -i Test3.ppt
rm:是否删除普通空文件 'Test3.ppt'? y
3 -r或-R用来删除文件夹
[email protected]:~/LinuxTest$ ls secondFile2
Test2.doc Test3.ppt
[email protected]:~/LinuxTest$ rm -R secondFile2
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile3 secondFile4 Test2.doc
Linux基本指令nano和cat
nano
nano是Linux的一款文字编辑攻击,是最基本的terminal端的文本编辑,还可以写代码。
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile3 secondFile4 Test2.doc
[email protected]:~/LinuxTest$ touch Test1.py
[email protected]:~/LinuxTest$ nano Test1.py
[email protected]:~/LinuxTest$ python Test1.py
This is a Python script
cat
cat可以显示文件内容,或者将某个文件里的内容写入到其他文件里。
1 查看文件内容
[email protected]:~/LinuxTest$ cat Test1.py
print("This is a Python script")
2 >将文件内容放到另一个文件里
[email protected]:~/LinuxTest$ touch Test3.py
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile3 secondFile4 Test1.py Test2.doc Test3.py
[email protected]:~/LinuxTest$ cat Test1.py>Test3.py
[email protected]:~/LinuxTest$ cat Test3.py
print("This is a Python script")
3 >将多个文件的内容打包放入另一个文件
[email protected]:~/LinuxTest$ touch Test4.py
[email protected]:~/LinuxTest$ cat Test1.py Test3.py>Test4.py
[email protected]:~/LinuxTest$ cat Test4.py
print("This is a Python script")
print("This is a Python script")
4 >>将内容添加在一个文件某尾
[email protected]:~/LinuxTest$ touch Test5
[email protected]:~/LinuxTest$ nano Test5
[email protected]:~/LinuxTest$ ls
secondFile1 secondFile4 Test2.doc Test4.py Test5.py
secondFile3 Test1.py Test3.py Test5
[email protected]:~/LinuxTest$ cat Test5>>Test1.py
[email protected]:~/LinuxTest$ cat Test1.py
print("This is a Python script")
This is Test5.
Linux文件权限
ls查看权限
[email protected]:~/LinuxTest$ ls -l
总用量 28
drwxrwxr-x 2 lzs lzs 4096 10月 8 21:00 secondFile1
drwxrwxr-x 2 lzs lzs 4096 10月 8 20:54 secondFile3
drwxrwxr-x 2 lzs lzs 4096 10月 8 20:56 secondFile4
-rw-rw-r-- 1 lzs lzs 48 10月 8 21:19 Test1.py
-rw-rw-r-- 1 lzs lzs 0 10月 8 20:40 Test2.doc
-rw-rw-r-- 1 lzs lzs 33 10月 8 21:15 Test3.py
-rw-rw-r-- 1 lzs lzs 66 10月 8 21:16 Test4.py
-rw-rw-r-- 1 lzs lzs 15 10月 8 21:19 Test5
-rw-rw-r-- 1 lzs lzs 0 10月 8 21:18 Test5.py
chmod修改权限
chmod [谁][怎么修改][哪个文件]
[email protected]:~/LinuxTest$ ls -l
总用量 28
drwxrwxr-x 2 lzs lzs 4096 10月 8 21:00 secondFile1
drwxrwxr-x 2 lzs lzs 4096 10月 8 20:54 secondFile3
drwxrwxr-x 2 lzs lzs 4096 10月 8 20:56 secondFile4
-rw-rw-r-- 1 lzs lzs 48 10月 8 21:19 Test1.py
-rw-rw-r-- 1 lzs lzs 0 10月 8 20:40 Test2.doc
-rw-rw-r-- 1 lzs lzs 33 10月 8 21:15 Test3.py
-rw-rw-r-- 1 lzs lzs 66 10月 8 21:16 Test4.py
-rw-rw-r-- 1 lzs lzs 15 10月 8 21:19 Test5
-rw-rw-r-- 1 lzs lzs 0 10月 8 21:18 Test5.py
[email protected]:~/LinuxTest$ chmod u-r Test5
[email protected]:~/LinuxTest$ ls -l
总用量 28
drwxrwxr-x 2 lzs lzs 4096 10月 8 21:00 secondFile1
drwxrwxr-x 2 lzs lzs 4096 10月 8 20:54 secondFile3
drwxrwxr-x 2 lzs lzs 4096 10月 8 20:56 secondFile4
-rw-rw-r-- 1 lzs lzs 48 10月 8 21:19 Test1.py
-rw-rw-r-- 1 lzs lzs 0 10月 8 20:40 Test2.doc
-rw-rw-r-- 1 lzs lzs 33 10月 8 21:15 Test3.py
-rw-rw-r-- 1 lzs lzs 66 10月 8 21:16 Test4.py
--w-rw-r-- 1 lzs lzs 15 10月 8 21:19 Test5
-rw-rw-r-- 1 lzs lzs 0 10月 8 21:18 Test5.py
[谁]
- u: 对于 User 修改
- g: 对于 Group 修改
- o: 对于 Others 修改
- a: (all) 对于所有人修改
[怎么修改]
- +, -, =: 作用的形式, 加上, 减掉, 等于某些权限
- r, w, x 或者多个权限一起, 比如 rx
[哪个文件]
- 施加操作的文件, 可以为多个
一个使用Python的技巧
给文件添加x权限,比如给.py文件添加x权限,可以直接执行。
1 给文件添加x权限
2 给python脚本添加一句话
#!/usr/bin/python3
不用修改
3 执行文件
[email protected]:~/LinuxTest$ ./Test3.py
This is a Python script
三步缺一不可