Linux Basic Commands Chapter 1-First Look at the Way

Introduction to Linux

One, the basic principles of linux

  • 1. The '/' root is the source of the system, all files start from the root, and everything is a file.
  • 2. The file can contain uppercase and lowercase letters and numbers, but the standardized file should not start with a number
  • 3. Strictly case sensitive, cannot be used/as a file name
  • 4. Do not do unnecessary things and do things efficiently.

Second, Bash features

2.1, shell and bash features

  • 1. Type: sh, bash, zsh, tcsh, csh, ksh: view the shell command cat /etc/shell
  • 2. Support command history and completion
  • 3. Support pipeline, redirection, alias, support command line expansion
  • 4. Support file wildcard, regular expression, support variable, shell script
  • 5. ! Add keywords, only the last hop keyword command record can be executed;
  • 6, echo ¥HISTSIZE can only record at most one thousand historical commands.

2.2, Quotation marks supported by bash

Insert picture description here
Insert picture description here

2.3, bash common operations

  • 1, //Cursor jump
    • a.Ctrl+a/	//跳到命令行首
      
    • b.Ctrl+e 	//跳到命令行尾
      
    • c.Ctrl+u	//删除光标至命令行首的内容
      
    • d.Ctrl+k	//删除光标至命令行尾的内容
      
    • e.Ctrl+<--	//光标定位到离自己最近的一个单词前面
      
    • c.Ctrl+l	//清屏
      

+


3. Command

3.1 Command format

  • Command [options] [parameters]
    options: there can be zero or more (short options -; long options -;)
    parameters: the object of the command (there can be zero or more)

3.2, command type

Linux commands are divided into internal and external commands

  • 1. Internal commands (built-in shell); provided by bash, no need to install embedded in the kernel, help+command
  • 2. External command: There is an executable file with a name response under a certain path of the file system: the file path where the command exists can be found through whcich. Command ±-help

Footnote: type //Display the type of command specified by i

3.3, commonly used commands

  • 1, ls: The file types viewed are

Optional file type

- Ordinary file
d Directory file
c Character device, charater
l Link file link
s Socket file
  • The type of file
  • The number of hard links to the file,
  • The owner of the file, (owner)
  • The group to which the file belongs, (group)
  • The size of the file (in bytes), (size)
  • Timestamp (timestamp), the last time it was modified.
    Access //access
    modification // modify The content of the file has
    changed //change: matadta has no data.

Command syntax *

ls
-l View detailed information, the first is the type of file.
-d View the catalog itself
-a Do not ignore hidden files beginning with.
-h Unit conversion
-i Display the inode of the file
-r Display in reverse order
-R Recursive display

ls -l -d ana.cfg /tmp/ks can view multiple files at the same time.

  • 2. Alias ​​alias; the syntax used alias cdnet='cd /etc/syscpnfig' directly defines the alias to enter the directory.
    Insert picture description here
  • 3. cd change directory: change directory
    usage
  •  绝对路径和相对路径。
    
  •  cd 回到主目录,cd 回到上次目录,cd~回到用户主目录。
    
  •  cd - 来回切换,类似回看,直接与上次路径进行切换。
    
  • 4. pwd: current path, display the current location
  • 5. mkdir new folder, new directory
    - usage
mkdir description
-p (praent parent) Create subfolders after creating the parent folder.
-v (verbose verbose) Echo the process of creating a folder

Use Cases;
Insert picture description here

  • 6. rmdir delete directory: only one non-empty directory can be deleted

  • 7, tree: View the directory tree and display the contents of the current directory in a tree-like structure.
    example:
    Insert picture description here

  • 8, touch: create a file, divided into two ways: "made out of nothing", "leave the old and welcome the new-reset the time of the file"

  • 9, stat: view the status of the file, view the file's access time, modification time, change (file size) change (content change)
    such asInsert picture description here

  • 10, rm, remove move delete, delete file directory

Optional parameter
-r: delete recursively. This option
-f must be used when deleting a directory ; it is forced to delete without asking. :

Only use -f to delete files, and -r to delete directories

  • 11. cp: copy
    Optional parameter
    -r: copy directory
    -f; forced copy. :
    -a; archive copy, often used for backup.
    -p; retain the original permissions when copying.
  • 12. mv, move move files, (rename locally), cut files (the target is cut at the remote end)
  • 13, cat: View file content ---- link multiple files, view multiple files, merge content, generate multi-line text.
  • 14. echo'hello' >abc write to the file echo echoes the written content,> one is to overwrite, >> two is to append. '
    cat >abc <<EOF When writing the file to abc, <<EOF will end writing when detecting this EOF. And >> append is the same, when EOF is detected, it will end writing.
  • 15, tac: Reinstall: link me to see and flashback print content to load to content.
  • 16, more: //View text content in full screen, only from front to back
  • 17, less: view the text content in full screen, you can view from front to back, or from back to front, use b to look forward, and space to look back
  • 18. head View the contents of the file from the head, the first 10 lines are viewed by default, and the number of lines can be specified by -n, head -10 abc to view the file
  • 19, tail looks at the content of the file from the end, the last 10 lines are viewed by default, you can also specify the number of lines with -n, tail -10 abc to view the last 10 lines of the file
  • 20, wc: text statistics, word count

Usage: -w counts words, -f counts lines, -c counts characters
such asInsert picture description here

  • 21, du statistics file size, -sh summary hunman summary information, s view directory, h view with unit.

如:
[root@Eryuege admin]# du -sh passwd
4.0K passwd

  • 22, df: Report file system disk space usage, -h displays in a human-friendly way, -i displays inode information

Such as:Insert picture description here

  • 23, hostname: view and temporarily set the host name, change the host name, restart will resume.
  • 24, hostnamectl: Permanently set the host name, command use method hostnamectl set-hostname host name, and then use bash to refresh the host name
  • 24, clear, please screen , clear all the contents of the terminal, shortcut key Ctrl + l
  • 25, whoami displays the currently logged-in user
  • 26, who displays all currently logged-in account information
  • 27, w, show all logged-in accounts and show what they are working on

Insert picture description here

  • 28, which View the location of the command.

[root@Eryuege admin]# which cd
/usr/bin/cd

  • 29, date //Display the current time, or set the time How to
    use
Options description
-s Set the time in characters, such as date -s '2020-10-17 10:30:00'
%Y years
%m month
%d date
%H Time
%M Minute
%S second

Insert picture description here

  • 30, cal perpetual calendar

Insert picture description here

  • 31. ldd checks the files that the command depends on. Remember not to move the files that the command depends on without taking a snapshot. The bloggers have encountered bloody lessons! ! !

  • 32, tar: file compression tool
    Compressed file classification
File extension Tools used
… Tar.gz tar
.tar.bz2 tar
.tar.xz tar
.zip zip universal cross-platform.

The compression ratio will become smaller and smaller.

How to use tar

Options Features
-c Create archive
-with Compressed into gz format
-j Compressed into bz2 format
-J Compressed into zx format
–V Show details
-t View the contents of the compressed package without decompression
-f 指定要压缩或解压缩的文件
-x 解压缩
组合键使用
-zcf 创建一个gz格式的压缩文件
-jcf 出啊关键一个bz2格式的压缩文件
-xvf 解压指定文件,并查看过程
-xf 解压指定文件
-C z指定解压的目录
zip压缩文件 zip 1.zip 1, 2 4 5 6 7 7可以将多个文件压缩进一个压缩文件
unzip 解压缩文件

Insert picture description here
安装依赖文件的方法Insert picture description here

3.3,文本处理之文本三剑客awk-sed-grep!!!

  • 1,cut :截取文本的内容,-d指定字段的分割符,默认是空格,-f指定要显示的字段。

Insert picture description here

  • 2,awk:取出指定列的内容;awk -F分割符 ’NR==行数{print $需要的列}‘ filename

分割符不指定默认是空格, 取 正 数 值 的 内 容 , N R 指 定 行 数 , N F 指 定 最 后 一 列 , 可 以 通 过 取正数值的内容,NR指定行数,NF指定最后一列,可以通过 NRNF(NF-2)查看倒数第二列的内容

  • 3,sed:处理行的内容;sed [option] ’需要处理的动作‘ filename

-n 关闭默认的打印动作。只打印需要处理的动作。
如“
[root@Eryuege admin]# sed -n ‘1s/root/123/p’ passwd
123❌0:0:root:/root:/bin/bash

sed ’1s/123/abc/g‘ abc 处理第一行的123替换位abc并打印。

参数 描述
1 表示第一行
s 表示修改替换
c 表示改变
a 表示追加内容
g 表示全部,如果1表示第一个匹配
D 删除
p 打印

Insert picture description here

  • 4,gerp 过滤文本的内容
  • 4.1,grep egrep fgrep

:根据模式搜索文本,并将符合模式的文本显示出来。
:使用基本正则表达式定义的模式来过滤文本的命令。
(Pattern 模式) 文本字符和正则表达式的元字符组合而成的匹配条件。

选项参数

选项 描述
-i 忽略大小写
- - color 匹配带的内容高亮显示
-v 显示没有被模式匹配到的行
-o 只显示被模式匹配到的字符串
-E 使用扩散正则表达式,grep -E相当于使用egrep
-q 静默模式,不输出任何信息
-A(after后) 1 被模式匹配到的内容以及其后面一行的内容都显示出来
-B (before前)1 被模式匹配到的内容以及其前面一行的内容都显示出来
-C (前后)1 被模式匹配到的内容以及其前后的行各显示1行。

示例:
root@Eryuege ~]# grep -A 2 ‘hell’ ac
hell world
cat
han de
[root@Eryuege ~]# grep -B 2 ‘hell’ ac
1231
heloo
hell world
[root@Eryuege ~]#

  • 4.2,,fgrep 不支持正则表达式,执行行速度快

实例:[root@Eryuege ~]# cat ac |grep ‘world’
hell world

  • 5,sort:默认神曲排序,不是桉数值大小排序的.
    用法
sot选项 描述
-n 根据数值大小进行排序
-r 逆序排序
-t 字段分隔符
-k 以那个字段为关键字进行排序
-u 去重,排序后相同的行至显示一次
-f 排序是忽略字符大小写
uniq选项 描述
-c 显示文件中行重复的次数
-d 只显示重复的行
-u 只显示未重复的行

通过-E多个内容同时查找|通过正则表达式进行查找
[root@Eryuege ~]# grep -E ‘123|ha’ ac
1231
han de

4,获取帮助:

  • 1,通过man命令查看手册。
  • 2,通过–help查看简要帮助说明
  • 3,通过pinfo查看详细手册说明。

//内部命令

help COMMAND
//外部命令
COMMAND --help
//在线文档
info COMMAND
//命令手册 manual
man COMMAND
//文档
/usr/share/doc

whatis COMMAND //用于查看COMMAND出现在man的哪一章节中。

//man是分章节的,以下是每一章节的内容介绍:
1 用户命令(/bin,/usr/bin,/usr/local/bin);
2 系统调用;
3 库调用;
4 特殊文件(设备文件);
5 文件格式(配置文件 的语法);
6 游戏;
7 杂项(Miscellaneous);
8 管理命令(/sbin,/usr/sbin,/usr/local/sbin)

//man manual note:
[] //optional
<> //required
... //can appear multiple times
| //choose one more
{} //group
name //command name and function brief description
SYNOPSIS //usage Description, including the available options
DESCRIPTION //Detailed description of the command function, possibly including the meaning of each option
OPTIONS //Description of the meaning of each option
FILES //Configuration files related to this command
BUGS //Report bug
EXAMPLES //Examples
SEE ALSO //Also reference

//man flips the screen, flips
one screen backward//SPACE flips one screen
forward //b
flips one line backward//enter
flips one line forward//k

//Find
/KEYWORD //backward
? KEYWORD //forward
n //next
N //previous
q //exit

Guess you like

Origin blog.csdn.net/LBJ19224/article/details/109129286