Linux basics (shortcut keys and basic commands)

Linux basics (shortcut keys and basic commands) study notes

shortcut key

CTRL  +  A      #光标移动到起始位置
CTRL  +  E      #光标移动到最后位置
CTRL  +  U      #删除此处至开始所有内容
CTRL  +  K      #删除此处至末尾所有内容
CTRL  +  L      #清屏
CTRL  +  C      #终止当前任务
CTRL  +  R      #关键词搜索历史命令快速执行

SHIFT + CTRL  +  C  #复制 
SHIFT + CTRL  +  V  #粘贴
SHIFT + CTRL  +  N  #新建窗口  

Order

命令 [参数]

View the parameters of the current command命令 --help
Please add image description

#列出文件的信息 默认为当前目录
ls
#参数
 -a, --all                  #不隐藏任何以 . 开始的项目
 -A, --almost-all           #列出除 ... 以外的任何项目
     --author               #与 -l 同时使用时,列出每个文件的作者
 -h, --human-readable       #与 -l 和 -s 一起,以易于阅读的格式输出文件大小(例如 1K 234M 2G等)
 -l				           #使用较长格式列出信息
 -r, --reverse			   #逆序排列
 -X                         #根据扩展名按字母顺序排序
 -t                         #按时间排序,最新的最前;参见 --time

Please add image description

d represents the path, l represents the link file, c character device file, b block device file.

The following three fields (r means read w means write x means execute - means not possible) owner | group member | other members

#显示或操纵历史列表 带行号显示历史列表,将每个被修改的条目加上 `*' 前缀
history
#参数
 -c	                       #删除所有条目从而清空历史列表
#!行号 可以快速执行行号内容
#改变 shell 工作目录
cd [-L|[-P [-e]] [-@]] [目录]
#.表示当前目录 ..表示上一级目录 -上次目录  ~表示家目录 /表示根目录
#打印当前工作目录的名字
pwd [-LP]

Linux structure

name effect
/boot Files required when Linux starts
/dev device file
/etc Configuration file
/home User's home directory
/media media files
/mnt Mount file path
/opt third-party software
/proc virtualization file
/root Administrator's home path
/run process file
/srv compressed file
/sys System Files
/usr Install and share files
/was Variable data log files
/tmp Temporary Files
/usr/bin Commonly available commands
/usr/sbin Commands available to Super users
/usr/lib 32-bit function library file
/usr/lib64 64-bit function library file

File processing

Create file OR folder

#若指定<目录>不存在则创建目录
mkdir [选项]... 目录...
 -v, --verbose               #每次创建新目录都显示信息
#创建文件
touch [选项]... 文件...

View Files

#显示文本文件内容
cat [文件名]
 -n, --number             #对输出的所有行编号
 -s, --squeeze-blank      #不输出多行空行

cat file1 file2 > file3      
#把file1和file2的内容输入到file3中

more  [文件名]            #描述:通常在看一篇很长的文件时都希望是从头  看到尾,在Linux中,more命令可以以一个page为单位来浏览文件。当使用more时,可看到屏幕的左下方有一个“--more--”的信息,这时若按下回车键,则会显示下一行;若按下空格键,则会显示下一个page
less  [文件名]             #描述:若按下空格键,则会显示下一个page, 按下回车键则一行行地下翻,按下b键往上翻一页

Copy files

#将指定<源文件>复制至<目标文件>,或将多个<源文件>复制至<目标目录>
cp [选项]... [-T] 源文件 目标文件
 或:cp [选项]... 源文件... 目录
 或:cp [选项]... -t 目录 源文件...

-s, --symbolic-link		#只创建符号链接而不复制文件

Delete Files

#删除文件 
rm  [文件]
 -f, --force         #强制删除。忽略不存在的文件,不提示确认
 -i                    #每次删除前提示确认
 -I                    #在删除超过三个文件或者递归删除前提示一次并要确认

Move files (rename)

<源文件>重命名为<目标文件>,或将<源文件>移动至指定<目录>
mv [文件名称] [搬移的目的地(或更改的新名)]
 -f, --force                  #覆盖前不询问
 -i, --interactive            #覆盖前询问
 -n, --no-clobber             #不覆盖已存在文件如果您指定了-i、-f、-n 中的多个,仅最后一个生效

Find files

#搜寻文件与目录
find [目录名] [选项]
 -name filename       #按名字查找
 -type x              #查找类型为x的文件(x包括:b,c,d,f,l等)
 -user username       #查找属主为username的文件
 -atime n             #查找n天以前被访问过的文件
 -mtime n             #查找n天以前被修改过的文件
 -cmin n              #查找n分钟以前被修改过的文件
 -exec cmd {
    
    }         #对查找出来的文件执行cmd命令,{}表示找到的文件,命令要以“\\;”结束
 #如
 #$find /home/lin -name hash  #在 /home/lin 目录下找寻名为 hash 的文件
 #$find / -name fs* -print  从 / 根目录开始搜寻所有以 fs 开头的文件,然后用参数 -print 印出符合条件的文件路径
 #$find.  -name *.c -exec rm-f{ }\\;  #表示在用户当前的目录,搜寻所有以 .c 为结尾的文件名*.c,然后用参数 -exec   执行 rm-f{ }\\; 删除全部以 .c 结尾的文件(注意大括号里面没有空格)

Find characters in file

#在文件中查找字符串
grep  [字符串] [文件名]
#如
#$grep tigger file1  
#在 file1文件中找寻tigger字符串
#$grep "big tigger" file1  
#在 file1文件中找寻 big tigger字符串
#$grep ′b$′ file1
#查找文件file1中所有以b结尾的行。
#$grep ′an.′ file2
#查找文件file2中所有以an为头两个字符的3个字符,包括any,and等。

^ Indicates the beginning of a line.
Indicates the end of a line
. . Represents any single character.

*Matches zero or more characters preceding *

Directory and file security

Every file or directory in the Linux system has its owner, group, and its usage permissions clearly defined. Users can use the following command to specify the file permissions in their home directory to protect their data and information and prevent others from illegal use.

#改变文件拥有者
chown   [用户账号]  [文件或目录名称]
#使用人: 该文件或目录的拥有者和root 用户
#描述:如果(假设账号是xLinux1)有一个名为file.list的文件,其拥有权要给予另一位账号为xLinux2的同事,则可用chown来完成此功能,当改变完文件拥有者之后,该文件虽然在xLinuxl的home目录下,但该用户已经无任何修改或删除这个文件的权限了,这点读者应特别注意。

#改变文件的所属组
chgrp  [组名称]  [文件或目录名称]
#使用人: root 
#描述: 该命令和chown用法一样,其功能是把文件或目录所属组改成另一个组。
#修改文件的权限
chmod   [权限参数]  [文件或目录名称]
#使用人: 每一位用户 
#描述: 前面在介绍ls命令时,已经介绍文件的权限形态,例如 –rwx-------。要设置这些文件的形态就用 chmod这个命令来设置,然而在使用chmod 之前需要先了解权限参数的用法。权限参数可以有两种使用方法:英文字母表示法和数字表示法
English letter representation

A file uses ten small cells to record the file permissions, and the first small cell represents the file type. "-" represents a normal file; "d" represents a directory file; "b" represents a block special file; "c" represents a character special file. Next, every three cells represent the permissions of a type of user. The first three small cells represent the permissions of the user itself, represented by u; the middle three small cells represent the permissions of the same group as the user, represented by g; the last three small cells represent the permissions of other users, represented by o. That is: -rwx------- belongs to user access rights, represented by u; -rwx- belongs to group user access rights, represented by g. -------rwx belongs to other users' access rights, represented by o. The permissions of each type of user are directly represented by r, w, Just link the letters.

Example:
-rwx-- chmod u+rwx file1
The user can read, write, and execute operations on file1;
-rw-- chmod u-x file1
delete the user's executable permissions on file1;
-rw-rw-r-- chmod g+rw,o+r file1
users in the same group can add permissions to file1 to read and write, and other users can only read.

Number representation

The numerical representation is represented by three digits XXX, with the maximum value being 777. The first number represents the user's access rights, the second number represents the user rights of the same group, and the third number represents the access rights of other users. The readable permission r introduced earlier is represented by the number 4, the writable permission w is represented by 2, and the executable permission x is represented by 1, that is: r=4 w=2 x=1 Assume that the user's permissions on file1
are rwx is readable, writable and executable. In numerical representation, the sum of 4, 2 and 1 equals 7, which means that the user can read, write and executable the file file1. Here rwx is equivalent to 4+2+1=7.

As for the permissions of users in the same group and other users, just specify the second and third digits in sequence. If you do not specify any permissions, add 0! Here are a few examples to help you understand. Please pay attention to the changes in numbers.
Example:
-rwx-------chmod 700 file1
Specify that the user's permissions on file1 are readable, writable, and executable;
-rw------- chmod 600 file1
specify that the user's permissions on file1 are readable and writable;
-rwxrwxrwx chmod 777 file1
specify that all users' permissions on file1 are readable, writable, and executable. In short, the digital representation is to divide the 3-digit number into 3 fields, and each field is an arbitrary combination of 4, 2, and 1.

disk storage command

Hard disk space is a limited resource. Users can use the following command to understand the current usage of hard disk space at any time.

#显示磁盘的使用
df   [可选参数]
 -a, --all             #包含虚拟、重复和无法访问的文件系统
 -k                    #显示系统所配置的每一个磁盘当前被占用的空间大小

Please add image description

#显示目录的使用
du   [可选参数]
 -c, --total           #显示总计信息
 -a, --all             #输出所有文件的磁盘用量,不仅仅是目录
 

Please add image description

process command

View progress

#查询正在执行的进程
ps

Please add image description

Terminate process

#终止正在执行的进程
kill 进程号
#如$kill -9 PID#无条件删除进程号为PID#的进程

Guess you like

Origin blog.csdn.net/Systemmax20/article/details/124544938