Linux Learning the

Linux Learning

VM (Virtual Machine)

It refers to a complete hardware system function, and then run a full computer system completely isolated environment is simulated by software

Common Linux commands

command English correspondence effect
ls list Check the contents of the current folder
pwd print work directory View the folder where the current d
cd [directory name] change directory Switch folders
mkdir [directory name] make directory Create a directory
rm [filename] remove Delete the specified file name
touch [filename] touch If the file does not exist, the new file
clear clear Clear screen

**Tips*

  • ctrl + shift + = enlarged font display terminal window
  • ctrl + - reduced font display terminal window

Terminal Command Format

command [-options] [parameter]

Description:

  • command: command name,
  • [-options]: The option can be used to control command
  • parameter: parameter passed to the command

Query --help

The abbreviation man manual

man command

Files and directories for commonly used commands

aims

  • View directory contents
    • ls
  • Change directory
    • cd
  • Create and delete
    • touch
    • rm
    • mkdir
  • Copy and move files
    • cp
    • mv
  • View the file contents
    • cat
    • more
    • grep
  • other
    • echo
    • Redirect >and>>
    • pipeline |

ls common options

parameter meaning
-a Print all subdirectories and files in the specified directory, including hidden files
-l Show details of the file as a list
-h -L displays the file size with the humane way

.xxx files are hidden

Hidden files and folders is mainly used to configure the functional parameters

File size of computer representation (science):

unit English meaning
byte B(Byte) Then the computer unit as a digital, usually binary number 8 e
thousand K (Kibibyte) 1KB = 1024 B, kilobytes (1024 = 2 ^ 10)
trillion M(Mebibyte) 1MB = 1024KB, MB
Gigabit G(Gigabyte) 1GB = 1024MB, gigabytes, terabytes
too T(Terabyte) 1T = 1024GB, terabytes, terabytes

ls using wildcards

Tsuhaifu meaning
* It represents any number of characters
? Represent any one character, at least one
[] It represents a set of characters match any of
[abc] Matches any a, b, c in a
[a-f] Match any from a to f within a range of

example:

以1开头的文件: 
>ls 1* 
1结尾的: 
>ls *1
带3的:
>ls *3*
所有带2的文件:
>ls ?2?.txt
查询1开头1结尾的
>ls 1?1.txt  (如果111.txt 11.txt 121.txt,只能取出111和121两个,?占用了一个位置,三位数)
查询1开头1结尾的
>ls 1*1.txt (111.txt 11.txt 121.txt 都能取出)
查询字符组:
>ls [13]21.txt 
>ls [1-3].txt
>ls [a-f].txt

Permissions:

img

Linux "ls -l" File List permissions Detailed

Disclaimer: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.

This link: https: //blog.csdn.net/JenMinZhang/article/details/9816853

1. ls -l command execution results are as follows (/ var / log):

drwxr-xr-x 2 root              root   4096 2013-08-07 09:43 apparmor
drwxr-xr-x 2 root              root   4096 2013-08-07 09:44 apt
-rw-r----- 1 syslog            adm   16802 2013-08-07 14:30 auth.log
-rw-r--r-- 1 root              root    642 2013-08-07 11:03 boot.log
drwxr-xr-x 2 root              root   4096 2013-08-06 18:34 ConsoleKit
drwxr-xr-x 2 root              root   4096 2013-08-07 09:44 cups
-rw-r----- 1 syslog            adm   10824 2013-08-07 11:08 daemon.log
drwxr-xr-x 2 root              root   4096 2013-08-07 09:45 dbconfig-common
-rw-r----- 1 syslog            adm   21582 2013-08-07 11:03 debug
drwxr-xr-x 2 root              root   4096 2013-08-07 09:45 dist-upgrade
-rw-r--r-- 1 root              adm   59891 2013-08-07 11:03 dmesg

The results show divided into seven (part):

In the first record Example

第一列 : “drwxr-x---”  表识文件的类型 和文件权限 
第二列: “2”是纯数字 ,表示 文件链接个数
第三列 : “root” 表示文件的所有者 
第四列:“adm” 表示为文件的所在群组 
第五列:“4096”,表示为文件长度(大小)
第六列:“2013-08-07 11:03”,表示文件最后更新(修改)时间
第七列:“apache2” 表示文件的名称
详见下图:

img

2. The file type and file permissions, content is the list of the first column to the first record, for example :()

"Drwxr-x ---" Meaning: There are two parts, the first part is the row "d", the file type (directory or folder), the other is "rwxr-x ---" represents the file permissions , the authority has divided into three sections: namely "rwx", "rx" and "---" indicate, permissions and other user permissions of the file owner, file owning group permissions on the file.

(1) the file type, divided into the following categories:

d :目录 
- :文件 
l :链接 
s :socket 
p :named pipe 
b :block device 
c  :character device(2)文件权限 :
r :含义为 “可读”,用数字 4 表示 
w:含义为 “可写”用数字 2 表示
X(小X):含义为“可执行”用数字 1 表示
-:含义为“无权限”用数字0 表示
X (大X):含义为只有目标文件对某些用户是可执行的或该目标文件是目录时才追加x 属性。 
s:含义为 在文件执行时把进程的属主或组ID置为该文件的文件属主。方式“u+s”设置文件的用         户ID位,“g+s”设置组ID位。 
t :含义为保存程序的文本到交换设备上
3.文件权限的更改 :

Use the command: chmod file permissions file name [-R]

Command two ways:

(1) assign the appropriate permissions to the file that is direct:

chmod   a+x  auth.log   #含义为 给 auth.log 文件赋予所有者可执行权限 

(2) in lieu of using a digital rights:

E.g:

chmod 777 auth.log # auth.log meaning to confer any file readable, writable, executable permissions

Number Meaning See list below:

owner Groups other Three representatives of digital rights
r w x rwx rwx actual results
4 2 1 421 421 777
4 2 1 4 0 1 4 0 1 705

4. Change the owner of the file:

Command chown user file name, for example:

chmod mysql auth.log #含义为 把 文件 auth.log 的所有者更改为 mysql

5. Change the file's group

Command chgrp [-R] group name of the file name

E.g:

chgrp  -R  mysql  apache2  #含义为 ,把 目录apache2 的所在组更改为mysql

2. cd command

Change the current working directory

command meaning
cd Switch to the current user's home directory
d ~ Switch to the current user's home directory
cd . Keeping the current directory unchanged
cd .. Switch to the parent directory
cd - You can then switch back and forth between the two most recent working directory

3. Create and delete operations

3.1 touch

  • 如果文件不存在,可以创建一个空白文件
  • 如果已经存在,可以修改文件末次修改日期

3.2 mkdir

创建一个新的目录

-p 选项,可以递归创建目录

新建目录名称,不能与当前目录中已有目录和文件重名

3.3 rm

使用 rm 命令要小心,因为文件删除后不能恢复。记得备份

-f 强制删除,忽略不存在的文件,无需提示

-r递归地删除目录下地内容,删除文件夹时必须加此参数

3.4 拷贝和移动文件

命令 英文 作用
tree[目录名] tree 树状图列出文件目录结构
cp 源文件 目标文件 copy 复制文件或者目录
mv 源文件 目标文件 move 移动文件或者目录/文件或者目录重名

tree

-d 只显示目录

cp

  • cp 命令地功能时将给出的文件或目录复制到另一个文件或目录中,相当于 DOS 下的 copy 命令。

-f 已经存在的目标文件直接覆盖,不会提示

-i 覆盖文件前提示

-r 若给出的源文件时目录文件,则 cp 将递归复制该目录下的所有子目录和文件,目标文件b必须为一个文件名

mv

  • mv 用来移动文件或目录,也可以给文件目录重命名
  • -i 覆盖文件前提示

查看文件内容

命令 英文 作用
cat 文件名 concatenate 查看文件内容、创建文件、文件合并、追加文件内容等功能
more 文件名 more 分屏显示文件内容
grep 搜索文件文件名 grep 搜索文本文件内容

cat

  • cat 命令可以用来查看
  • 会一次显示所有内容,适合查看内容较少的文本文件

-b 对非空输出行编号

-n 对输出的所有行编号

Linux 中还有一个 nl 的命令 和 cat -b 的效果等价

more

  • 分屏显示文件内容,每次只显示一页内
  • 操作键:
    • 空格 显示手册的下一屏
    • Enter 一次滚动手册页的一行
    • b 回滚一屏
    • f 前滚一屏
    • q 退出
    • /word 搜索 word 字符串

grep

  • 强大的文本搜索工具
  • grep 允许对文本文件进行模式查找
    • 正则表达式
  • -n 显示匹配行及行号
  • -v 显示不包含匹配文本的所有行(相当于求反)
  • -i 忽略大小写

常用的两种模式查找:

  • ^a 行首,苏索以 a 开头的行
  • ke$ 行尾,搜索以ke 结束的行

其他

6.1 echo 文字内容

  • echo 会在终端中显示参数指定的文字,通常会和

    重定向

    联合使用

    • 如果直接输出文件,会自动创建新文件

6.2 重定向 > 和 >>

  • Linux 允许将执行命令重定向到一个文件
  • 将本应显示在终端上的内容输出/追加到指定文件中

其中

  • > 表示输出,会覆盖文件原有的内容
  • >> 表示追加,会将内容追加到已有文件的末尾

6.3 管道 |

  • Linux 允许将一个命令的输出可以通过管道作为另一个命令的输入
  • 可以理解现实生活中的管子

常用命令:

  • more:分屏现实内容
  • grep:在命令执行结果的基础上查询指定的文本

例子:

ls -al ~ | more

关机/重启

  • shutdown 选项 时间
  • -r 重新启动

提示:

  • 不指定选项和参数,默认表示1分钟之后关闭
  • 远程维护服务器,最好不要关闭系统,而应该重启系统

示例:

立即重启:
shutdown -r now 
立即关机
shutdown now
系统在今天的 20:25 关机
shutdown 20:25
系统十分钟之后关机
shutdown +10
取消之前的关机计划
shutdown -c

网卡和 IP 地址

命令 英文 作用
ipconfig configure a net work interface 查看/配置 计算机当前的网卡配置信息
ping ip地址 ping 检测 ip 地址是否正常
  • IP 地址时设置在网卡上的地址信息
  • 可以把电脑比作电话,网卡相当于 SIM 卡,IP地址相当于电话号码

IP 地址:

  • 每台联网的电脑上都有 IP 地址,是保证电脑之间正常通讯e额重要设置

ifconfig

例子:ifconfig , ifconfig | grep inet

远程登陆和复制文件

命令 对应英文 作用
ssh 用户名@ip secure shell 关机/重新启动
scp 用户名@ip: 文件名或路径 用户名@ip:文件名或路径 secure copy 远程复制文件

3.1 ssh 基础(重点)

在Linux 中 SSH 是非常常用的工具,通过SSH 客户端 我们可以连接到运行了SSH 的远程机器上

数据传输是加密的,可以防止信息泄露

数据传输是压缩的,可以提高传输速度

  • SSH 客户端是一种使用 Secure Sheel (SSH) 协议连接到远程计算机的软件程序

  • SSH 是目前较可靠,

    专为远程的路会话和其他网络服务

    提供安全性的协议

    • 利用SSH 协议 可以有效防止远程管理过程中的信息泄露
    • 通过SSH 协议 可以对所有传输的数据进行加密,也能够防止DNS 欺骗和 IP 欺骗
  • SSH 的另一项优点是传输的数据可以是经过压缩的,所以可以加快传输的速

1) 域名和端口号

域名

  • 由一串用点分隔的名字组成
  • 是IP 地址的别名,方便机翼

端口号 (相当于港口)

  • IP 地址:通过IP 地址找到网络上的计算机
  • 端口号:
    • SSH 服务器的默认端口是22,如果是默认端口号,在连接的时候可以省略
服务 端口号
SSH 服务器 22
WEB 服务器 80
HTTPS 443
FTP 服务器 21

2) SSH 客户端的简单使用

ssh [-p xx] user@remote
  • user 是在远程计算机上的用户名,如果不指定为当前用户
  • remote 远程机器的地址,可以是 IP/域名,或者是后面提到的别名
  • -p port 是 SSH Server 监听的端口,如果不指定,就为默认值 22

提示:

  • 使用 exit 退出当前用户的登陆

注意:

  • ssh 这个终端命令只能在 Linux 或者Unix 系统下使用
  • 如果在 Windows 系统中,可以安装 PuTTY 或者 XShell 客户端软件

XShell 和 Putty 在连接的时候无法连接

解决方法:

首先需要安装好 ssh

http://www.360kuai.com/mob/transcoding?url=9cfbb68b0badebf05&cota=4&kuai_so=1&tj_url=xz&sign=360_e39369d1&refer_scene=so_2

方法/步骤4:

使用gedit修改配置文件"/etc/ssh/sshd_config"

打开"终端窗口",输入"sudo gedit /etc/ssh/sshd_config"-->回车-->把配置文件中的"PermitRootLogin without-password"加一个"#"号,把它注释掉-->再增加一句"PermitRootLogin yes"-->保存,修改成功。

3.2 scp (掌握)

  • scp 就是 secure copy, 是一个在 Linux 下用来进行远程拷贝文件的命令
  • 地址格式与 ssh 基本相同,需要主义的是,在指定端口时用的是大写的 -P而不是小写的
# 把本地当前目录下的 01.py 文件 复制到远程家目录下的 Desktop/01.py 
注意:`: `后面的路径如果不是绝对路径,则以用户的家目录作为参照路径
scp -P port user@remote:Desktop/01.py 01.py

# 把远程 家目录下的 Desktop/01.py 文件复制到本地当前目录下的01.py
scp -P port user@remote:Desktop/01.py 01.py

# 加上 -r 选项可以传送文件夹
# 把当前目录下的 demo 文件夹复制到远程 家 目录下的 Desktop
scp -r demo user@remote:Desktop

# 把远程家目录下的Desktop 复制到当前目录下的 demo 文件夹
scp -r user@remote:Desktop demo
  • -r 若给出的软文件是目录文件,则scp 将递归复制该目录下的所有子目录和文件,目标文件必须为一个目录名
  • -P 若远程 SSH 服务器的端口不是 22,需要使用大写字母 -P 选项指定端口

注意:

  • scp 这个终端命令只能在 Linux 或者 UNIX 系统下使用
  • 如果在 Windows 系统中,可以安装 PuTTY ,使用 pscp 命令行工具,或者安装FileZilla 使用 FTP 进行文件传输

FIleZilla 在传输文件时,使用的是 FTP 服务 而不是 SSH 服务,

  • FTP 模式 :因此端口号应该设置为21

3.3 SSH 高级(知道)

  • 免密码登陆
  • 配置别名

免密码登陆步骤

  • 配置公钥
    • 执行 ssh-keygen 即可生成 SSH 钥匙
    • 执行 ssh-copy-id -p port user@remote,可以让远程服务器记住我们的公钥

用户权限相关命令

英文 s缩写 s数字代号
read r 4
write w 2
excute x 1

1566914734493

硬连接数= 文件数

01chmod 简单使用

  • chmod 可以修改 用户/组 对 文件/目录 的权限
  • 命令格式如下:

chmod +- rwx 文件名|目录名

02 组管理 终端命令

提示:创建组/删除组 的终端命令都需要通过 sudo 执行

命令 作用
groupadd 组名 添加组
groupdel 组名 删除组
cat /etc/group 确认组信息
chgrp 组名 文件/目录名 修改文件/目录的所属组

提示:

  • 组信息保存在 /etc/group 文件中
  • /etc 目录是专门用来保存系统配置信息的目录 用户管理

用户管理 终端命令

都需要sudo

3.1 创建用户/设置密码/删除用户

命令 作用 说明
useradd -m -g 组新建用户名 添加新用户 -m 自动建立用户家目录 -g 指定用户所在的组否则会建立一个同名的组
passwd 用户名 设置用户密码 如果是普通用户,直接用户passwd
userdel -r 用户名 删除用户 -r 选项会自动删除用户家目录
cat /etc/passwd | grep 用户名 确认用户信息 新建用户后,用户信息会保存在 /etc/passwd 文件中

提示:

  • 创建用户是,如果忘记添加 -m 选项最简单的就是删除,重新创建
  • 创建用户时,默认会创建一个用户名同名的组名
  • 用户信息保存在 /etc/passwd 文件中
例子
sudo useradd -m -g jj-group zhangsan
ls - l /home
2:
sudo passwd zhangsan

如果 添加用户 不加-m:

1566916446672

1566916468933

passwd 权限 是root

3.2 查看用户信息

  • id[用户名] 查看用户UID和GID 信息
  • who 查看当前所有登陆的用户列表
  • whoami 查看当前登陆账户名

1566916616568

用户名:密码:用户代号:开发组:全名:家目录:

--- 跳过若干

磁盘进程

02 磁盘信息

  • df -h disk free 现实磁盘剩余空间
  • du -h disk usage 现实目录下的文件大小

03 进程信息

  • ps aux

    process status 查看进程的详细状况

    • a 显示终端上所有进程包括其他用户的进程
    • u 显示进程的详细状态
    • x 显示没有控制终端的进程
  • top

    动态显示运行中的进程并且排序(动态)

    • q 退出
  • kill[-9]进程代号 种植指定代号的进程 -9 表示强行终止

其他命令

查找文件 find

find 命令功能非常强大,通常用来在 特定的目录下搜索符合条件的文件

  • find [路径] -name ".py" 查找指定路径下扩展名是.py 的文件
  • If you omit the path, it means the search in the current folder
  • Before learning wildcard, when you use the find command can be used simultaneously
例子1:
搜索桌面目录下,文件名包含1 的文件
find -name "*1*"
2. 搜索桌面目录.txt扩展名
find -name "*.txt"
3. 搜索桌面目录下,以数字 1 开头的文件
find -name "1*"

Soft connection

  • windows shortcuts
  • ln -s 被连接的源文件 连接文件 Role: founding documents of soft link

note:

  • Without -s option to create hard links
    • Two files take up hard disk space the same size, almost no work
  • After the source file using the absolute path, you can not use relative paths, so you can easily move linked files can still be used normally

Walkthrough goal:

  1. The movement of the desktop 01.py directory to demo / b / c directory
  2. New soft connection FirstPython 01.py in the desktop directory

example:

ln -s demo/b/c/01.py 01_xiangdui

Packing and compression

  • Windows rar
  • Mac zip
  • Linux tar.gz

Packed file

tar -cvf 打包文件.tar 被打包的文件/路径

Decompression

tart -xvf 打包文件.tar
  • cGenerate archive files, create a file package
  • xUnlock the archive
  • v Set out in detail the process of filing then file showing progress
  • f Specify the archive file name Well, f must be behind the .tar file, it is necessary to finally put option

Compression / decompression

1) gzip

  • tar and gzip command can be used in combination to achieve compression and file packaging
    • tar is responsible for packing, but not compression
    • Compressed with gzip, tar extension after the package is generally used xxx.tar.gz

The most common linux on when xx.tar.gz

  • tart command has an option can -zbe called gzip
  • format:
tar -zcvf 打包文件.tar.gz 被压缩的文件/路径
# 解压缩文件
tar -zxvf 打包文件.tar.gz
# 解压缩到指定文职
tar -zxv 打包文件.tar.gz -C 目标路径     (路径必须存在)

2) bzip2 (two pronunciation)

  • tar command in conjunction with bzip2 (gzip usage and the same)
    • Extension for general use xxx.tar.bz2
    • Use -jthe command call
# 压缩
tar -jcvf 打包文件.tar.bz2 被压缩的文件/路径..
# 解压缩文件
tar -jxvf 打包文件.tar.bz2

Software Installation

Guess you like

Origin www.cnblogs.com/521world/p/11592620.html