Linux basic command learning

Maybe no more good night 2021-11-25 17:49:55
linux basic command learning

Command learning

Current directory

View the current working directory -pwd( Absolute path )
pwd The command displays the current working directory location of the user , The working directory is the default location for users to operate files or other subdirectories .
As shown in the figure :

Linux Basic command learning _ operating system

Switch the user's working directory (~ Represents the current user's home directory )

  1. cd Target location : Switch to the target location
  2. cd ~ or cd: If the target location is not specified , Switch to the host directory of the current user
  3. cd -: Switch to the last execution cd The directory before the command
  4. Absolute path : The path starting from the root directory , No matter which path you are in, you can accurately switch to the specified directory
  5. Relative paths : The path starting from the current directory

Relative path representation

           form                                     explain                           Example       
Use directory name or file name directly Represents a subdirectory in the current working directory 、 The location of the file cd groub2/
With a dot “.” start Indicates that the current working directory is used as the starting point cd ./grub.conf
With two dots “. .” start Represents the directory above the current directory ( Parent directory ) As a starting point . ./vmlinuz
With “~ user name ” Form begins Indicates starting from the specified user's host directory ~teacher
With “~” Form begins Indicates that starting from the current user's Host Directory ~

The list shows the contents of the catalog -ls

ls Common options for

  • -l
    In long format (Long) Show a list of files and directories , Including authority 、 size 、 Last update time and other details .ll Command and ls-l Function the same
  • -a
    Show all (All) Information about subdirectories and files , Include the name with a point number "." Hidden directories and hidden files at the beginning .
  • -A
    And -a The function of options is basically similar to , But there are two special hidden directories that won't be displayed , That is to say, the ".“ And... Representing the parent directory ". ."
  • -d
    Show directory (Directory) Its own attributes , Instead of showing the contents of the catalog .
  • -h
    To be more human (Human) Displays the size of a directory or file in the same way , The default size is in bytes (B) , Use -h Option will be displayed as KB、MB Equal unit . This option needs to be combined with -l Use options together .
  • -R
    By recursion (Recursive) Displays all the contents of the specified directory and its subdirectories
  • –color
    Color different files in character mode . The default is on .
    Usually , Dark blue means the directory ,, White means general document , Green means executable file , Yellow means device file , Red means compressed file , Sky blue indicates soft connection file
  • -i
    Showing files and directories inode Number

Linux Basic command learning _ operating system _02

Add : use ls -l Command to view a directory will get a 7 A list of fields

  • The first 1 Field : File property word
    The first character represents the type of file
    "-” Indicates that the file is a normal file
    "d” Indicates that the file is a directory
    “l” Indicates that the file is a soft link file . Be similar to windows Next shortcut
    The first 1 After the character 9 A letter indicates the permission bit of the file or directory :
    r The watch is read ( see 、 download )、w Said to write ( add to 、 change 、 Delete 、 Upload )、x Indicates execution ( Run the file 、 Toggle directory )
    The first three represent the file owner ( Belong to ) Authority , The middle three represent the permissions of the group to which the file belongs , The last three represent the permissions of other users .

  • The first 2 Field : Number of file hard links
    If a file is not a directory , This field indicates the number of hard links the file has
    If it's a directory , Is the first 2 Field represents the number of subdirectories in the directory .
    If you create an empty directory , The second field of this directory is 2, Indicates that there are two subdirectories under the directory .

Linux Basic command learning _linux_03

  • The first 3 Field : file \ Directory owner
  • The first 4 Field : file \ The group of the directory owner
  • The first 5 Field : The space occupied by the file ( Soft recognition is in bytes ) If it's a directory , Indicates the size of the directory , Not the total size of the directory and the files under it .Linux Everything in the system is documented , So a directory is also a kind of file .
  • The first 6 Field : file \ Last access or modification time of the directory
  • The first 7 Field : file name , If it's a symbolic link ( Soft link file ), Then there will be a “->” The arrow symbol , The next root is the file name it points to

Combining wildcards
“?”: Represents any character , There is one character
“*”: Represents any number of characters , It can be 0 A or 1 One or more
“[]”: Indicates that any character in a character group can be matched [abc]、[a-f]

Linux Basic command learning _shell_04

Set alias -alias

  1. Simplify the common 、 A longer order
alias Command alias =‘ command ’ ###“=” There must be no spaces on either side

  • 1.
  1. Remove alias
unalias Command alias

  • 1.
[[email protected] ~]# alias myls='ls -alh'

  • 1.
  • 2.

Linux Basic command learning _ operating system _05

Statistics directory and file space occupancy -du

  1. Count the specified directory ( Or document ) The amount of disk space occupied
 du [ Options ] [ File or directory …]

  • 1.
  1. Common options
  • -a : Include all files when calculating disk space usage , It's not just catalogues
  • -h : In a more humane way ( Default to KB Count , But it doesn't show units ) Show the statistics
  • -s : Only count the total size of the occupied space , Instead of counting every subdirectory 、 File size

Linux Basic command learning _shell_06

  • a key :–max-depth=n —— Count all less than or equal to n The total size of the directory of the layer
    In the production environment, the system disk is occupied. To find the cause of the exception, you need to find the directory layer by layer
    for example : According to the statistics /var/log The size of the space occupied by the directory
 ​du -h --max-depth=1/var/log/

  • 1.

Linux Basic command learning _ operating system _07

notes : Options -a and -s Do not use at the same time

Create a new directory mkdir

  1. Create a new empty directory
mkdir [ Options ] Directory location and name

  • 1.
  • Add multiple directories at a time and directly add (mkdir abc 123)
  • -p: Create nested multiple directories at once

for example : Create a file in the current directory called public_html A subdirectory

 mkdir public_html

  • 1.

for example : Create directory /aa, stay /aa Create subdirectories under the directory bb, stay /aa/bb Create subdirectories under the directory cc

 mkdir -p aa/bb/cc

  • 1.

Linux Basic command learning _linux_08

Create an empty file touch

  1. Update the time stamp of the file
  2. Often used to create multiple new empty files
    touch file …
    for example :
    Create two empty files
touch aa bb

  • 1.

The file names are aa.txt and bb.txt:

touch {aa,bb}.txt

  • 1.

Create two different suffixes with the same file name

touch aa {.jpg,.png}

  • 1.

Linux Basic command learning _linux_09

Create link file In

  1. Create link file -In
    Create a linked file for a file or directory , Be similar to Windows System shortcuts
    Link file type
  • Soft link ( Also known as symbolic links ln -s)
    When establishing a soft connection, the source file needs to be represented by an absolute path . The source file location remains unchanged , Soft link file locations are useful wherever they are , Changing the file location relative to the path will invalidate
    example :ln -s Source file or directory … Linked file or target location
 ln -s /root/bb.txt /opt/BB.txt

  • 1.
  • Hard links ( Only to understand )
    ln Source file or directory … Linked file or target location
    The source file is represented as an absolute path , Hard links are relative to creating an alias file , The source file is still useful after deletion

Linux Basic command learning _ operating system _10

Linux Basic command learning _linux_11

Copy files or directories cp

Files or directories that will need to be copied ( Source ) Rebuild a , And save it as a new file or directory

  1. cp [ Options ]… Source file or directory … Target file or directory …
  2. cp Common options
  • -f: Do not remind when overwriting a file or directory with the same name as the target , And direct forced replication
  • -i: Remind the user to confirm when overwriting a file or directory with the same name as the target
  • -p: Permission to save files when copying 、 Attributes such as owner and time stamp remain unchanged
  • -r: This option must be used when copying directories , Means to copy all files and subdirectories recursively
    notes : When copying multiple files or directories , The target location must be a directory , And the target directory must already exist .
cp letc/host.conf /etc/host.conf.bak
cp host.conf{ ,.bak}
mkdir yum_bak
cp -r /etc/ yum.repos.d /etc/ yum.conf yum_bak/

  • 1.
  • 2.
  • 3.
  • 4.

Delete files or directories rm

  1. rm [ Options ] Files or directories to delete …
  2. Common options
  • -f: Do not remind when deleting files or directories , And directly force deletion .
  • -i: Remind users to confirm when deleting files or directories .(y Said to delete ,n Means not to delete )
  • -r: This option must be used when deleting directories , Means to delete the entire directory tree recursively ( Use with caution ).
    notes : Do not directly delete existing directories or configuration files in the system , To avoid unexpected failures
 rm -rf /etc/yum.repos.d/*

  • 1.

When deleting files in the directory, it is recommended to switch to the directory first and then execute rm -rf command

 cd /etc/ yum.repos.d/
rm -rf/*( Use caution )

  • 1.
  • 2.

Move files or directories mv

  1. Specify file or directory transfer location
  2. If the destination location is the same as the source location , It is equivalent to performing rename operation
mv [ Options ] … Source file or directory … Target file or directory

  • 1.
 example :mv /aa /opt ### Move to the root directory aa Directory to opt Under the table of contents

  • 1.
  1. mv The command can only rename a single file , You can use rename Command to batch modify the file name
 example : rename jpg gif *.jpg
renaem Old name New name Target file

  • 1.
  • 2.

Batch modify file name :rename

mv The command can only rename a single file , You can use rename Batch modify file name

rename Old characters New character Target file

  • 1.
 Example :rename jpg gif *.jpg ### Put all the jpg The format file is changed to gif Format

  • 1.

Find the directory where the command file is stored which

which command | The program name // By default, when the first target is found, it will not continue to find
which -a command | The program name // Find... In all search paths

  • 1.
  • 2.
  • 3.
 Example :which ls
which history

  • 1.
  • 2.

Use which When looking for internal commands , The corresponding program will not be found

Find a file or directory find

  1. Recursively , According to the name of the target 、 type 、 Size and other attributes for fine search
find [ Find the range ] [ Find the condition type ]

  • 1.
  1. Common types of search criteria
Find type keyword                       explain                      
Search by name -name Search by the name of the target file ( Name and “ ” Double quotes , Allow to use “*” And “?” wildcard
Check by file size -size Search based on the size of the target file , In general use “+”、“-” Number is set to be greater than or less than the specified size as the search condition , Common units of capacity include kB( Be careful k It's lowercase )、MB、GB
Search by file owner -user Search according to whether the file belongs to the target user
Find by file type -type Find according to the type of file , File types include ordinary files (f)、 Catalog (d)、 Block device file (b): A device that reads data in chunks ( Hard disk , Memory , CD drive ) Character device file (c) A device that reads data as a single character ( keyboard , mouse )
  1. Use find Command to implement multiple search conditions
  • Use logical operators between expressions
  1. “-a” And (and) ### It means that you need to meet
  2. “-o” Express or ( or) ### Indicates that only one of the
 Example :find /boot -size +1024k -a -name "vmlinuz"
find /boot -size +1024k -o -name "vmlinuz"

  • 1.
  • 2.

The experiment is shown in the figure below :

Linux Basic command learning _linux_12

Linux Basic command learning _shell_13

  1. find And exec usage
  • -exec Parameters are followed by Linux command , It's a semicolon ";" For the end sign , Because semicolons have different meanings in different systems , So add the backslash escape character before the semicolon “\”.
    {} For the front find Find out the file name .
  • find The command matches all the normal files in the current directory , And in -exec Use... In the options ls-l The command lists them
find /boot -name "vm*" -a -type f -exec ls -l {} \;

  • 1.

Linux Basic command learning _linux_14

Priority of executing commands

  • First priority
    Command to specify the path . Absolute path /root/ Or relative path ./
  • Second priority
    Alias specified command alias pwd=/root/
  • Third priority
    Internal orders
  • Fourth priority
    hash command .
    Linux There will be one under the system hash surface , When you first turned it on, this hash Table is empty , Every time you execute an order , hash The table records the path of the command , It's like caching . For the first time shell By default, the interpreter will start from PATH Path to find the path of the command , The second time you use this command ,shell The interpreter first looks at hash surface , Without that order, I would go PATH Find... Under the path .hash Tables increase the speed of command calls .
  • Fifth priority
    adopt PATH Defined find order find
  • If none of the above can be found , Will report “ Command not found …” Error of
本文为[Maybe no more good night]所创,转载请带上原文链接,感谢

  1. La distribution Linux d'Amazon est maintenant entièrement basée sur Fedora
  2. org.springframework.web.bind.MissingServletRequestParameterException
  3. Built in constraints and functions of MySQL Foundation (2)
  4. Basic operation of MySQL Foundation (I)
  5. Introduction to Java zero foundation 3: Java data types
  6. 从零开始搭建EasyDarwin环境——Linux系统开发环境搭建Golang
  7. Redis source Concise Analysis 02 - SDS String
  8. Construire l'environnement easydarwin à partir de zéro - - construire l'environnement de développement du système Linux golang
  9. javaweb代码是正确的,但是第一行代码就报错了
  10. **** | Java | 后端开挂:3行代码写出8个接口
  11. Java || 看了大二学长写的代码,我竟开始默默的模仿了。。。
  12. Java | 手把手教你实现一个抽奖系统(Java版)
  13. Java | Manuel pour vous apprendre à mettre en œuvre un système de loterie (version Java)
  14. Java | | après avoir lu le Code que j'ai écrit en deuxième année, j'ai commencé à imiter silencieusement...
  15. Java | back - end Pending: 3 - line Code write 8 Interfaces
  16. Le Code Web Java est correct, mais la première ligne de code est incorrecte
  17. Android网络编程之Http通信
  18. Android網絡編程之Http通信
  19. Http communication for Android Network Programming
  20. 数据结构实验八 领会图的两种主要储存结构和图的基本运算算法设计
  21. Hibernate数据校验简介
  22. The story of spring
  23. Il a dépensé 270 000 yuans pour soulever Xiaopeng p7 et a parcouru 3 627 km. Le propriétaire du véhicule a partagé 6 avantages et inconvénients.
  24. 阿里蚂蚁花呗团队面试题:spring+分布式+jvm+session+redis
  25. 【Java入门100例】14.字符串排序——compareTo()
  26. 【Java入门100例】13.修改文件扩展名——字符串替换
  27. Leetcode 79. Word Search [C + + / java detailed problem]
  28. Introduction à la vérification des données hibernantes
  29. Expérience de la structure des données
  30. Spring cloud gateway practice 2: more routing configuration methods
  31. Java network programming - summary overview
  32. 基于语法树的 Java 代码自动化插桩
  33. 云原生 Spring Boot 应用配置 Prometheus + Grafana 监控(保姆级)
  34. Spring cloud gateway practice 2: more routing configuration methods
  35. Jenkins file one line of code to deploy. Net program to k8s
  36. Java network programming - summary overview
  37. Cloud Native Spring Boot application configuration Prometheus + grafana Monitoring (baby - sitter)
  38. Insertion automatique de code Java basée sur l'Arbre syntaxique
  39. Le SUV phare de Xiaopeng, Xiaopeng G9, a fait ses débuts au salon de l'automobile et s'est tenu en position C dans la nouvelle force?
  40. Docker 从入门到实践系列四 - Docker 容器编排利器 Docker Compose
  41. 6年老猿带你掌握Spring Boot实现定时任务的动态增删启停
  42. disruptor笔记之六:常见场景,java教程从入门到精通pdf百度云
  43. Pourquoi InnoDB n'utilise - t - il pas un cache LRU naïf?
  44. Java Reflection (2): quelques opérations de base de reflection
  45. 6年老猿帶你掌握Spring Boot實現定時任務的動態增删啟停
  46. Les singes âgés vous permettent de maîtriser le démarrage et l'arrêt dynamiques des tâches programmées par Spring boot
  47. Docker From Beginning to Practice Series IV - docker Container chorégraphe Clean docker Composition
  48. 编写 java 程序,为家用电脑 ipv6 自动更新 goddy dns 记录(ddns)
  49. java jvm-old gc耗时几十s,导致系统告警
  50. Disruptor note 6: scénario commun, tutoriel Java de l'introduction à la maîtrise du PDF Baidu Cloud
  51. 编写Java程序启动脚本最佳实践
  52. How to get the correct Linux user's documents, music videos and other directories?
  53. Java JVM Old GC prend des dizaines de s, ce qui provoque une alarme système
  54. Écrivez un programme Java pour mettre à jour automatiquement les enregistrements DNS goddy (ddns) pour l'ordinateur domestique IPv6
  55. 編寫Java程序啟動脚本最佳實踐
  56. Meilleures pratiques pour écrire des scripts de démarrage de programmes Java
  57. Notes sur springcloud Eureka
  58. Ajout, suppression et modification simples de mybatis
  59. Java - carte mémoire de l'objet
  60. Why did docker lose to kubernetes? Docker employee readme!