Linux 简单教程

文章目录

 

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
  • 1

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

 

三步缺一不可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值