Installation package
sudo dpkg -i ×××
View all installed software
dpkg --list
Uninstall a software
sudo apt-get --purge remove ×××
After installing half, then install termination
sudo apt-get install --reinstall ×××
The basic idea of two Linux
- Everything is a file
- Directory, block device, process, thread, pipes, etc. can be seen as a file
- Each software has identified uses
Common Commands
-
-r
Layer by layer traversal,-n
display line numbers -
man ××
Check the manual can help one command -
ls -l ×××
Details of xxx (a representation Show hidden) [display. If not specified ×××, displays all! ]- Add parameters
a
thatls -l ...
can show hidden files information! - It may also be used in conjunction with wildcard characters, such as
ls -al h*
, more information at the beginning of the file display h.
- Add parameters
-
fdisk -l
[Display] Disk Information -
ifconfig > test2.log
The output of the network configuration file is written totest2.log
a file -
/dev/null
Equivalent to the Recycle Bin -
tree -L 2
2 displays the tree layer -
jobs
View background processes -
At the command plus
&
, directly in the background. Such as,gedit log2.txt &
-
pipeline
××× | grep -i "×××"
[Used to find a string variable containing]ps -ef | more
[Space] to turn pagesps -ef | less
Page flipping up and down keys [] [enter or space/×××
can be used to find a character]
-
pwd
Displays the current absolute path, if the current path is a link, use thepwd -p
show the actual path -
mkdir -p 路径名
, With the-p
parameters, even though the latter path in some folder does not exist, it is created automatically. -
rm - rf ×××
Delete a file -
cp
cp log1 dir2
, Log1 file, dir2 is a foldercp ../dir3/log2 .
The current directory is dir2, achieve log2 copy files to the current directory dir3 dir2 directory.cp log2 /home/clay/log1
Log2 copy files to / home / directory under the clay, and to achieve copy and rename .- If the source file is a directory, you must add
-r
parameters.cp -r /etc .
Copy all files in the current directory to the directory tec-a
Parameters and-r
parameters are the same
cp -s log1 log.link
Copy log1 into a soft link [shortcut] .cp -u ~/.bashrc .bashrc
It occurs when two files are not the same, will be copied.
-
mv
mv dir3 dir2
Move all the files in the directory to the dir2 directory dir3
-
touch
- Create a new file
cat > file
This can also be done to create a new file operations
- Change timestamps of existing files
touch log1
Create a file log1touch file(1..5).txt
Create a file file1 ~ file5
- Create a new file
-
stat log1
It can be used to create log1 view, modification, and last access time -
file
[Identify the file type, file encoding format discriminating] -
ln
linkln -s log log_link
Create a soft link to the log ofln log log_link
Create a hard link to the log of
-
Find command
- Find command name
which
which ls
- Find the file name
whereis locate find
[whereis locate and use database lookups, fast. find the use of the hard disk for slow! ]whereis bash
- Just create or rename files locate just can not be found, we need to execute
updatedb
the command
find
- Search by file name
find / -name pam.conf
, From the root directory of exact match search and pam.conf filefind / -name “pam.conf*”
From the root directory containing the search pam.conf file
- Search by file size
find / -size 389c
, The search from the root directory file containing 389 bytes in sizefind / -size -1k
, The search from the root directory contains a file size less than 1k bytesfind / -size +1k
, The search from the root directory contains a file size greater than 1k bytes
- Search by file modification time
find ./ -mtime 7
, Modify the search from 7-8 days the root directory of the file that dayfind ./ -mtime -7
Search from the root directory, 7 days a modified filefind ./ -mtime +7
Search from the root directory, 7 days before the modified file
- Search by file name
- Search by file type
find / type d
Search from the root directory, type the directory (-
) file
- Search by file permissions
find / -perm 777
Search from the root directory permissions to 777 files
- Find command name
-
ps -ef
All processes used to view the full format -
grep
grep -n “author” ls.txt
Search author string ls.txt, where -n denotes a display of line numbers!grep -n [td]o ls.txt
Search to and do in ls.txt in. [] Represents t or d, which satisfy a.grep -n ^ls ls.txt
In ls.txt to begin with lsgrep -n 'gr..p' ls.txt
Find out the string contains "gr ×× p" ofgrep -n 'o\{3,5\}' ls.txt
Search contains 3 to 5 o string
-
chmod
-
ps -aux
=ps -ef
View all processes currently static displayps | more
-
top
The current dynamic display of all processes -
Terminate the process
ctrl + z
kill -9 进程号
-
Network-related
-
netstat
-
ifconfig
【和windows下的ipconfig
一样】 -
route
常用文件系统
- ext2
- Linux标准文件系统
- vfat
- 与Windows兼容的文件系统【FAT16、FAT32】,可作为windows和Linux交换文件分区
- NFS
- 网络文件系统
- swap【类似windows的虚拟内存】
- 专用交换分区
文件类型
- 普通文件【 通常是流式文件】
- 文件类型用
-
表示 - 可分为:纯文本文件、二进制文件、数据文件
- 文件类型用
- 目录文件【 用于表示和管理系统中的全部文件】
- 文件类型用
d
表示
- 文件类型用
- 设备文件【包括块设备文件(硬盘、U盘等)和字符设备文件(键盘)】
- 块设备文件类型用
b
表示,/dev/sda是块设备所在, - 字符设备文件类型用
c
表示,/dev/tty通常是字符设备所在。
- 块设备文件类型用
- 管道文件(fifo)【提供进程间通信的一种方式】
- 文件类型用
p
表示 - 解决多个程序同时存取一个文件造成的错误问题
- 文件类型用
- 链接文件【 用于不同目录下文件的共享】
- 文件类型用
l
表示
- 文件类型用
- 套接字文件【该文件类型与网络通信有关】
- 文件类型用
s
表示 - 同在/var/lib目录
- 文件类型用
目录
/
【Linux只有一个根目录】/bin
【系统下最基础的命令,如“ls、cp、del”。该目录下的文件是可执行的,普通用户都可以使用的命令。】/boot
【引导加载程序相关的文件,内核映像文件也常放于此处!】/etc
【系统的各种配置文件,如用户账号密码配置文件、系统初始化文件,安装的各种应用软件、服务的配置文件等】/usr
【用到的应用程序、文件等】/bin
【集中了所有用户命令,是系统的软件库】/include
【包含C语言头文件,用来描述C语言中用到的数据结构、函数和常量】/lib
【程序库文件,系统不变的数据文件】/sbin
【根文件系统不必要的系统管理命令,如多数服务程序】
/var
【经常变化的文件,如日志、数据库等】/sbin
【系统管理员使用的管理程序】/tmp
【系统临时文件】/dev
【设备文件,设备驱动程序】/home
【用户工作目录,个人配置文件】/root
【超级管理员文件夹】/lib
【根文件系统上的程序所需的共享库】/mnt
【系统管理员临时挂载系统的挂载点,】
分区
- 硬盘(硬盘必须分区才能使用)
- 磁盘分区:主分区(数量1~3个)
- 包括操作系统文件启动的硬盘分区
- 磁盘分区:扩展分区(需要分为逻辑分区才能使用。扩展分区数量可以0~1个,而逻辑分区无数量限制)
- 磁盘分区:主分区(数量1~3个)
/dev/sda1 ...
/dev/sda2 ...
/dev/sda5 ...
上例中,sd表示硬盘种类,a表示计算机上的第一块硬盘,1、2、5表示分区号。【扩展分区从5开始,故sda5为扩展分区,sda1和sda2为主分区】
- 挂载:将目录和分区对应起来,通过访问该目录来访问该分区!
shell【命令解析器】
内核的外层保护,完成用户与内核的交互。将用户命令解析为操作系统所能理解的指令,实现操作系统与用户之间的交互。
Tab
键自动补齐,或列出满足已打出字母的全部文件- 历史命令
- 输入
history
即可查看历史命令【默认保存可达1000个】,所有的这些命令是保存在~/.bash_history
- 上下方向键可查看之前运行过的命令
!+历史命令标号
即可运行对应的历史命令!!
即可运行上一条命令!+字符串
运行历史命令中与之相对应的命令,或列出满足已打出字母的历史命令history -c
清除历史命令ctrl+r
即可进入向后增量搜索模式,输入想要查找的命令相关字母,即可搜索出相关命令!
- 输入
- 快捷键
- 控制命令
ctrl + l
清屏ctrl + c
终止当前正在执行的命令ctrl + z
挂起命令,停止当前命令运行,使用fg
进行命令恢复ctrl + s
阻止屏幕输出,当前正在执行的命令不再打印信息!ctrl + q
允许屏幕输出,与ctrl + s
配套使用ctrl + d
退出当前的shellctrl + o
执行当前命令,并选择上一条命令
- 编辑命令
- 光标移动
ctrl + a
移动到命令行首ctrl + e
移动到命令行尾ctrl + f
向右移动一个字符ctrl + b
向左移动一个字符alt + f
向右移动一个单词alt + b
向左移动一个单词
- 删除
ctrl + u
从光标删除至命令行首ctrl + k
从光标删除至命令行尾ctrl + w
从光标删除至字首alt + d
从光标删除至字尾ctrl + d
删除光标处(后)的字符ctrl + h
删除光标前的字符(同backspace)alt + backspace
同ctrl + w
,分隔符有些差别ctrl + y
粘贴至光标后
- 光标移动
- 控制命令
重定向
- 输出重定向
- 【基本用法】
命令 > 文件
,该方式是覆盖的方式。如,ifconfig > test1.log
- 将网络配置信息写入到test1.log文件命令 >> 文件
,该方式是追加的方式。
- 【高级用法】
命令 >> 文件1 2 >> 文件2
,正确追加到文件1,错误追加到文件2命令 &>> 文件
,无论正确与否都追加到文件 =命令 >文件 2>&1
如,ifconfig eth0 > test1.log 2>&1
- 将错误信息保存到了test1.log文件!
- 【基本用法】
命令执行顺序
;
多个命令并列,顺序执行&&
前一个命令执行完毕才可以执行后一个命令||
前一个命令执行失败才执行后一个命令
环境变量
- 常用环境变量
- PATH【决定了shell在哪些目录去寻找命令和程序】
echo $PATH
显示当前系统的PATH变量【变量是路径;变量之间用冒号分割】export PATH=$PATH:/home
,设置临时的环境变量。【退出当前shell该环境变量不生效】【注意export新建变量时,等号左右不要加空格】- 修改用户主目录下的
~/.profile
文件或者~/.bashrc
中使用export,启用后【用source启用或者重启启用】永久生效。 【通常修改.bashrc
】 - 修改系统目录下的
profile
文件,也会永久生效【要慎重设置,尤其是ROOT用户登录】
- HOME【当前用户组目录】
- USER【查看当前的用户】
- LOGNAME【当前用户登录名】
- UID【当前用户的识别字】
- SHELL【当前用户使用的shell类型】
- TERM
- PWD【绝对路径】
- MAIL【用户邮件存放目录】
- HISTSIZE【保存历史命令的条数】
- HOSTNAME【主机名】
- PATH【决定了shell在哪些目录去寻找命令和程序】
- 系统全局配置文件
/etc/profile
【该文件是在登录到shell才会读取的文件】- 利用用户标识符(UID)来确定很多重要变量
- 用户配置文件
~/.bash_profile
【~
表示 /home目录】~/.bashrc
专用于当前用户的配置信息
- 如何让保存的环境变量配置立即生效呢?
source ×××
source .bash_profile
source ~/.bashrc
- 常用命令
env
显示所有的环境变量- 通常会很多,我们使用管道进行筛选出想要的:
env | grep -i "×××"
【"××ד是想要的字符串,-i表示忽略大小写】
- 通常会很多,我们使用管道进行筛选出想要的:
set
显示所有本地定义的shell变量【这个显示的全】unset
删除环境变量- unset -f:仅删除函数
- unset -v:仅删除变量
readonly
【修改变量或函数的属性为只读,即既不能修改,也不能删除。】readyonly ×××
即可设置环境变量
路径
- 绝对路径
- 完整路径
- 相对路径
..
上一个目录- 如从目录
usr/share/doc 到 /usr/share/man
可直接使用../man
- 如从目录
.
当前目录~
home目录-
上一个工作目录
当前用户主目录 ≠ 系统根目录
- 用户是指当前用户所在目录。如
/home/clay
,此时等同于cd ~
命令。- 若使用root用户,则在
/root
目录下
- 若使用root用户,则在
- 根目录是
/
,等同于cd /
链接
- 硬链接
- 两个或多个文件名与相同的
i
结点相关联,可以为单个文件创建一个或多个硬链接 - 以文件的副本的形式存在【大小跟源文件一样大】
- 源文件删除之后,对硬链接没有影响;源文件内容改变,硬链接内容不改变。
- 不能对目录文件做硬链接
- 不能再不同的文件系统之间做硬链接
- 两个或多个文件名与相同的
- 软链接(符号链接)【类似windows 的快捷方式】
- 软连接是一个新文件,具有不同的
i
结点号 - 以路径的形式存在
- 删除源文件,只删除了数据不会删除链接;源文件内容改变,软链接内容改变。
- 软连接可以跨文件系统
- 软链接可以对目录进行链接
- 软连接是一个新文件,具有不同的
正则表达式
- 以
^
开头,以$
结尾 [0-9]
匹配单个数字+
匹配一个多个字符串
用户
用户可分为超级用户root、系统用户和普通用户。
- 文件拥有者
owner
- 用户组
group
- 其他用户
others
- User configuration file stored in the
/etc/passwd
file- User profile is divided into seven fields
- Such as
clay:x:1000:1000:CLAY,,,:/home/clay:/bin/bash
- User passwords are stored in a
/etc/shadow
file - Creating a simple user
rain
adduser rain
Create a user- Delete users
userdel rain
- Delete users
passwd rain
set password
user group
- User group information stored in
/etc/group
the directory, groupadd ourgroup
Create a group ourgroupusermod -a -G ourgroup clay
Adding clay to ourgroup groupcat /etc/group | grep ourgroup
The group included members to view, verify whether to join the group success
Compression and Archive
- Common
gzip
andbzip2
the-9
expressed compress,-d
represents decompression gzip *
All files are compressedgunzip *
Unzip all filestar zcvf ls.tar.gz ls.txt
The ls.txt with gzip file compression package and pay attention to suffix specification.tar.gz
- Decompression with
zxvf
- Decompression with
tar jcvf ls.tar.gz ls.txt
The ls.txt file with bzip2 compression package and pay attention to suffix specification.tar.bz2
- Decompression with
jxvf
- Decompression with
vi Tool tips
- Under normal mode
- Input
12g
jumps to line 12. - dd delete a row
- yy copy a row
- attached to a line p
- Search: Under normal input mode
/要搜索的词
, press then
page - Alternatively: [In the command mode by
:
entering input Command mode. For example,:50,100s/m/M/g
the lines 50 to 100 m is replaced lowercase to uppercase M - Revoked:
- Input
- Save as:
:w 文件名