文章目錄
Linux基本指令ls和cd
cd指令
進入想打開的目錄。
1 返回上一級目錄
lzs@LZS-Ubuntu:~/anaconda3$ cd ..
lzs@LZS-Ubuntu:~$
2 去往子文件夾
lzs@LZS-Ubuntu:~$ cd anaconda3/bin
lzs@LZS-Ubuntu:~/anaconda3/bin$
3 返回剛剛所在的目錄
lzs@LZS-Ubuntu:~/anaconda3/bin$ cd -
/home/lzs
4 向上返回兩次
lzs@LZS-Ubuntu:~/anaconda3/bin$ cd ../../
lzs@LZS-Ubuntu:~$
5 去往Home
lzs@LZS-Ubuntu:~/anaconda3/include$ cd ~
lzs@LZS-Ubuntu:~$
6 去往任何目錄
lzs@LZS-Ubuntu:~$ cd /home/lzs/anaconda3/bin
lzs@LZS-Ubuntu:~/anaconda3/bin$
ls指令
1 ls -l
輸出詳細信息
lzs@LZS-Ubuntu:~$ 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
顯示所有文件
lzs@LZS-Ubuntu:~$ 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
方便觀看
lzs@LZS-Ubuntu:~$ 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
查看幫助
lzs@LZS-Ubuntu:~$ ls --help
Linux基本指令touch,cp和mv
touch指令(新建文件)
lzs@LZS-Ubuntu:~/LinuxTest$ touch Test1.py Test2.doc Test3.ppt
lzs@LZS-Ubuntu:~/LinuxTest$ ls
Test1.py Test2.doc Test3.ppt
cp指令(複製文件)
1 複製文件
lzs@LZS-Ubuntu:~/LinuxTest$ cp Test1.py Test1copy.py
lzs@LZS-Ubuntu:~/LinuxTest$ ls
Test1copy.py Test1.py Test2.doc Test3.ppt
2 -i
(interactive:互動)提示信息,如果已經存在要複製的文件,加上-i
會給提示信息
lzs@LZS-Ubuntu:~/LinuxTest$ cp Test1.py Test1copy.py
lzs@LZS-Ubuntu:~/LinuxTest$ cp -i Test1.py Test1copy.py
cp:是否覆蓋'Test1copy.py'? y
lzs@LZS-Ubuntu:~/LinuxTest$
3 複製到文件夾下
lzs@LZS-Ubuntu:~/LinuxTest$ cp Test2.doc secondFile1/
4 複製文件夾,需要加上-R
(recursive)
lzs@LZS-Ubuntu:~/LinuxTest$ cp -R secondFile1/ secondFile2/
5 複製多個文件,複製名字部分相同的多個文件
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile2 Test1copy.py Test1.py Test2.doc Test3.ppt
lzs@LZS-Ubuntu:~/LinuxTest$ mkdir secondFile3
lzs@LZS-Ubuntu:~/LinuxTest$ cp Test* secondFile3
或者
lzs@LZS-Ubuntu:~/LinuxTest$ cp Test1.py Test2.doc secondFile4/
lzs@LZS-Ubuntu:~/LinuxTest$ cd secondFile4
lzs@LZS-Ubuntu:~/LinuxTest/secondFile4$ ls
Test1.py Test2.doc
mv指令(移動文件)
1 移動去另一個文件夾
lzs@LZS-Ubuntu:~/LinuxTest$ cp Test1.py Test2.doc secondFile4/
lzs@LZS-Ubuntu:~/LinuxTest$ cd secondFile4
lzs@LZS-Ubuntu:~/LinuxTest/secondFile4$ ls
Test1.py Test2.doc
2 重命名文件
lzs@LZS-Ubuntu:~/LinuxTest/secondFile1$ ls
Test1.py Test2.doc Test3.ppt
lzs@LZS-Ubuntu:~/LinuxTest/secondFile1$ mv Test1.py Test1mv.py
lzs@LZS-Ubuntu:~/LinuxTest/secondFile1$ ls
Test1mv.py Test2.doc Test3.ppt
3 查看幫助
直接加上--help
Linux基本指令mkdir,rmdir和rm
mkdir建立文件夾
lzs@LZS-Ubuntu:~/LinuxTest$ mkdir secondFile5
rmdir移除文件夾
只能移除空的文件夾
lzs@LZS-Ubuntu:~/LinuxTest$ rmdir secondFile5
rm移除文件
1 移除單個文件
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile3 Test1copy.py Test3.ppt
secondFile2 secondFile4 Test2.doc
lzs@LZS-Ubuntu:~/LinuxTest$ rm Test1copy.py
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile2 secondFile3 secondFile4 Test2.doc Test3.ppt
2 -i
或-I
有提示的移除文件(爲了避免誤刪)
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile2 secondFile3 secondFile4 Test2.doc Test3.ppt
lzs@LZS-Ubuntu:~/LinuxTest$ rm -i Test3.ppt
rm:是否刪除普通空文件 'Test3.ppt'? y
3 -r
或-R
用來刪除文件夾
lzs@LZS-Ubuntu:~/LinuxTest$ ls secondFile2
Test2.doc Test3.ppt
lzs@LZS-Ubuntu:~/LinuxTest$ rm -R secondFile2
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile3 secondFile4 Test2.doc
Linux基本指令nano和cat
nano
nano
是Linux的一款文字編輯攻擊,是最基本的terminal端的文本編輯,還可以寫代碼。
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile3 secondFile4 Test2.doc
lzs@LZS-Ubuntu:~/LinuxTest$ touch Test1.py
lzs@LZS-Ubuntu:~/LinuxTest$ nano Test1.py
lzs@LZS-Ubuntu:~/LinuxTest$ python Test1.py
This is a Python script
cat
cat
可以顯示文件內容,或者將某個文件裏的內容寫入到其他文件裏。
1 查看文件內容
lzs@LZS-Ubuntu:~/LinuxTest$ cat Test1.py
print("This is a Python script")
2 >
將文件內容放到另一個文件裏
lzs@LZS-Ubuntu:~/LinuxTest$ touch Test3.py
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile3 secondFile4 Test1.py Test2.doc Test3.py
lzs@LZS-Ubuntu:~/LinuxTest$ cat Test1.py>Test3.py
lzs@LZS-Ubuntu:~/LinuxTest$ cat Test3.py
print("This is a Python script")
3 >
將多個文件的內容打包放入另一個文件
lzs@LZS-Ubuntu:~/LinuxTest$ touch Test4.py
lzs@LZS-Ubuntu:~/LinuxTest$ cat Test1.py Test3.py>Test4.py
lzs@LZS-Ubuntu:~/LinuxTest$ cat Test4.py
print("This is a Python script")
print("This is a Python script")
4 >>
將內容添加在一個文件某尾
lzs@LZS-Ubuntu:~/LinuxTest$ touch Test5
lzs@LZS-Ubuntu:~/LinuxTest$ nano Test5
lzs@LZS-Ubuntu:~/LinuxTest$ ls
secondFile1 secondFile4 Test2.doc Test4.py Test5.py
secondFile3 Test1.py Test3.py Test5
lzs@LZS-Ubuntu:~/LinuxTest$ cat Test5>>Test1.py
lzs@LZS-Ubuntu:~/LinuxTest$ cat Test1.py
print("This is a Python script")
This is Test5.
Linux文件權限
ls查看權限
lzs@LZS-Ubuntu:~/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 [誰][怎麼修改][哪個文件]
lzs@LZS-Ubuntu:~/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
lzs@LZS-Ubuntu:~/LinuxTest$ chmod u-r Test5
lzs@LZS-Ubuntu:~/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 執行文件
lzs@LZS-Ubuntu:~/LinuxTest$ ./Test3.py
This is a Python script
三步缺一不可