Linux study notes super detailed 0 basic (below) shell

The shell is a command interpreter that provides us with an interactive text console interface. We can enter commands through the terminal console, which are interpreted by the shell and handed over to the linux kernel for execution.

Shell is an interpreter, Bourne Again Shell, an enhanced version of the Bourne Shell command interpreter under Unix, bash shell is one of the distribution interpreters, and dash under debian, there are many sh commands in the bin directory, according to The type of operation to learn.

Help command: man

man command: view the specific operation of the command

man ls: View the basic usage of ls

There are also some system built-in commands with basic functions, such as cd exit, which are directly loaded into the resident system memory along with the shell (use help to view), and some other commands are called external commands. You can use the type command to determine what command it is. It shows that it is a shell... that is, an embedded command, and the other shows that it is an external command.

External commands can also use "command --help" to view information

Commonly used commands: ctrl+c to stop the process

Ctrl+L clear screen

file directory class

pwd: Print the working directory, showing the absolute path where it is currently located

cd : switch path

cd- : jump between two paths

ls: list all the contents of the current directory -a list all files including hidden files, etc. -l list the attribute permissions of files, etc.

Create delete folder

mkdir a: Create a folder named a

mkdir abc : create folders a and b and c

mkdir aa/b : create folder a and create folder b under folder a

mkdir -pa/b : Create folder a Create folder b under folder a

rmdir a : delete a folder a is an empty folder

Copy a file or folder

touch a : create a file

cp source dest : copy source to dest directory

cp source dest/b : Copy the source file to the b file under the dest path and directly overwrite the b file

cp -r source dest: Copy the source folder to the dest directory

Delete a folder or directory

rm -f deleteFile: delete file a directly

rm -rf a/ : Delete all files under folder a

rm -rf /* : Delete all file content in the root directory, don't try! ! ! ,,

mv move files and directories or rename

mv /temp/movefile /target : move movefile to /target

mv /temp/movefile /target/newmovefile : Move the movefile file to /target and rename the file to newmovefile

mv name newName: rename name to newName

cat

cat file name: View file content is suitable for viewing files with few file contents

cat -n file name: view the contents of the file and display the line number

more file content split screen viewer

The more command is a text filter based on the VI editor, which displays the content of the text file page by page in a full-screen manner, and several shortcut keys are set in the command

space turn page

Enter next line

b page forward

= View the current line

less is used to view the content of the file in split screen. The function is similar to more but more powerful than more. It supports various display terminals. When displaying text content, it does not load all the content but loads the content according to the display needs.

Shift+G to end

g : to the beginning

/Keywords: search n find down N find up

? Keyword: Search n Find Up N Find Down

q: leave less

echo : output content to the console

-e : support backslash-controlled character conversion

Input and output redirection

ls -l > a.txt The content of the list is written to a.txt (overwrite)

ls -al >> a.txt The contents of the list are written to a.txt (append)

head file name: display the first 10 lines of the file

head -n5 filename: display the first 5 lines of the file

tail file name: display the last 10 lines of the file

tail -n5 filename: display the last 5 lines of the file

tail -f file: track all updates of the document in real time (ctrl+s pause monitoring ctrl+q resume monitoring ctrl+c end monitoring)

ln: soft link, also known as symbolic link, similar to the shortcut in windows, has its own data block, mainly storing the path of linking other files

ln -s [原文件或目录] 软链接名

histoty :查看执行过的命令

histoty n :查看最近执行过的n条命令

histoty -c :清空历史命令

时间日期类

date :显示当前时间

date +%Y :显示当前年份

date +%m :显示当前月份

date +%d :显示当前是哪一天

date “+%Y-%m-%d:%H:%M:%S” :显示当前年月日时分秒

date +%s:显示时间戳(1970年到现在的秒数)

date -d ‘1 days ago’:一天前的时间

date -d ‘-1 days ago’:一天后的时间

date -s ‘时间’:设置系统当前的时间

ntpdate : 获取当前系统的正确时间

cal 查看日历

cal 年份:查看一年的日历

用户权限类

useradd 用户名:添加新用户

useradd -g 组名 用户名

passwd 用户名 :更改用户密码

可以通过“id 用户名”来查看用户是否创建成功

userdel -r 用户名:删除用户

cat /etc/passwd:查看创建了哪些用户

who:查看自己在哪个用户下

whoami:查看自己在哪个用户下

udo :设置普通用户具有root权限,在etc/sudoers里进行用户的添加

usermod -g 组名 用户名 :修改用户属于哪个组

userdel 用户名 :删除用户名

groupmod -n 新组名 原组名 :修改用户属于哪个组

groupdel 组名:删除组名

文件权限:

Linux是典型的多用户系统,不同的用户拥有不同的地位,文件的拥有权限也不一样。

ll 或者ls -l: 查看文件属性

-代表文件,d代表目录,l代表链接文档

chown 更改后用户 文件名:改变文件或者文件夹所有者

chown -R 更改的用户 文件名: 改变文件夹所有者

chgrp 更改后的用户组 文件或目录:改变所属组

搜索查找类:

find :将从指定的目录向下递归遍历其各个子目录,将满足条件的文件显示在终端

find [搜索范围] [选项] :搜索范围是文件夹 不指定默认从当前文件夹开始

例如:find /root -size +10M:找到root目录下10M以上的文件

locate :快速定位文件路径,利用事先建立的系统中所有的文件名称以及路径的locate数据库实现快速定位给定的文件,该指令无需遍历整个文件系统,查询速度快,为了确保查询结果的准确,管理员必须定期更新locate时刻。

locate 文件名字:快速搜索文件

该数据库是每天更新一次的,为了保证查找的准确性,第一次运行前,要更新,更新命令是:

updatedb

which 命令 :查找命令的路径

whereis 命令:查找命令的具体目录

grep 过滤查找以及“|”管道符

|:表示前一个命令的处理结果输出传递给后面的命令处理

grep 选项 查找内容 源文件

例如:ls grep -n test file.cfg :查找file文件里test在第几行出现过 然后显示出来

压缩解压类

gzip /gunzip

gzip 文件:压缩文件只压缩*.gz文件,

gunzip 文件.gz:解压缩文件命令

总结:只能压缩文件不能压缩目录,压缩文件不能保留原来的文件,同时压缩多个文件会产生多个压缩文件不会打包

zip/unzip

zip *.zip:file:压缩file文件为*.zip

zip -r *.zip:file:压缩file目录为*.zip

unzip -d<目录> *.zip:解压缩*.zip文件指定放到-d后的目录下

总结:可以保留原来的文件和目录,可以打包

tar 打包

tar [选项] XXX.tar.gz 将要打包进去的内容

打包且压缩:tar -zcvf file.tar.gz 1.txt 2 3.cfg:将1 2 3文件或者目录打包并压缩到file.tar.gz中

解包:tar -zxvf file.tar.gz -C /tmp :解压 file.tar.gz到/tmp

磁盘管理类

du (disk usage):磁盘占用情况

du 目录/文件:显示子文件的磁盘使用情况

df:查看磁盘空间的使用情况

df [选项] :列出文件系统的整体磁盘使用情况,检查文件系统的磁盘空间占用情况

选项:-h:以易于阅读的方式展示

lsblk -f:查看详细的设备挂载情况,显示文件系统信息

进程管理类

计算机中一个正在执行的程序或者命令被叫做进程

启动之后一直存在常驻的进程被叫做服务

分为前台显示进程和后台服务进程

ps :查看系统中的进程

ps aux|grep xxx :查看系统中的所有进程

ps -ef|grep xxx :查看子父进程之间的关系

ps aux详细信息:

想要查看进程的CPU占用率和内存占用率 可以使用aux

查看进程的父进程id 可以使用ef

kill:终止进程

kill [选项] 进程号:通过进程号杀死进程 (选项 :-g 强迫进程立即停止)

killall 进程名称:通过进程名称杀死进程

pstree:查看进程树

-p :显示进程的PID

-u :显示进程的所属用户

top:实时监控系统进程状态

top [选项]:

网络状态

netstat:显示网络状态和端口占用信息

netsat -anp | grep 进程号:查看该进程网络信息

netsat -nlp | grep 端口号:查看网络端口的占用情况

crontab:系统定时任务

crontab [选项]

重启crond服务:systemctl restart crond

然后设置定时任务

进入crontab编辑页面,会打开vim编辑定时任务:*****执行的任务

例如:

Guess you like

Origin blog.csdn.net/m0_56366502/article/details/129078091