UNIX/Linux study notes

Table of contents

1. Storage contents of each UNIX/Linux file directory

2. Common UNIX/Linux commands

3. Common commands for file operations in UNIX/Linux

4. Use of wildcards

5. About file and folder permissions

6. Commands about users and user groups

7. How to enable ordinary users to have root permissions?

8. How to add a user to the sudo group?

9. Software package installation and shall programming related instructions

10. If centos does not have a network, how to configure the network card information so that the virtual machine can access the external network?

11. Differences between the three running modes of scripts

12. Shall basic related commands

13. Two methods of assigning values ​​to variables using the execution results of commands: `command` or $(command)

14. Scope of shall variable

15. Process management related commands

16. Disk management related commands


1. Storage contents of each UNIX/Linux file directory

1.bin: stores executable files (commands, scripts)

2.boot: stores the boot program

3.dev: Store device information

4.etc: Store system configuration files

5.lib: storage class library

6.mnt: Default location for external storage mounting

7.opt: ​​Default location for software installation

8.proc: stores process information

9.run: stores some variables and constants when the program is running

10.sbin: stores some commands that the administrator can execute

11.sys: stores system kernel information

12.srv: Data that needs to be extracted after the service is started

13.tmp, var: temporary file directory (files in tmp may be cleared when shutting down)

14.usr: Many user applications and files are placed in this directory, similar to the program files directory in Windows systems.

2. Common UNIX/Linux commands

1.whoami: Returns the user currently using the system

2.pwd: Return to the current directory location

3.echo:

        (1) Printing (similar to System.out.println in Java)

                Enter text: echo hello

                Output result: hello

        (2) Variables can also be defined in UNIX/Linux: name=yzp

                Input text: echo $name ("$" means the input is a variable)

                Output result: yzp

4.clear: clear screen operation

5.history: View the historical operations of input commands

        history -c: clear history

3. Common commands for file operations in UNIX/Linux

1.cd: Change the current working directory

        cd ..return to the previous directory

        cd ~ returns to the root directory of the current user

2.ll, ls: display all files in the current directory

        (1) ll: Display detailed information of the file

                 ls: displays visible files in the current directory

                 ls -a: Display all files in the current directory (including hidden files)

                 ls -l: Display detailed information about files in the current directory

        (2) Displayed file prefix

                -:document

                d: folder

                l: link (shortcut in Windows)

3.mkdir: Create folder

        mkdir -pa/b/c: Directly create a file a, a contains b, and b contains c (because the folders are created layer by layer, add "-p")

        mkdir -pa{b,c,d}: directly create folders ab, ac, ad (a is equivalent to a prefix name)

        mkdir -pa/{b,c,d}: Directly create folder a containing folders b, c, d

4.rmdir: delete the folder (the folder must be non-empty)

5.cp: Copy files

        Format: cp directory location to which the target file is to be moved

        cp -r: copy folder

6.mv: move files/rename files

        Format: mv directory location to which the target file is to be moved

                   mv file name modified from original file name

7.rm: delete files

        Format: rm file name

        rm -r folder name: delete the folder and its subdirectories

        rm -f filename: forcefully delete the file (no prompt message is displayed)

8.touch: Create a file

9.stat: View the status of files

10.ln (create file link)

        (1) Create soft link format: ln -s source file name link file name

                The soft link file and the original file are not the same file. The link file points to the source file.

        (2) Create a hard link format: ln  source file name link file name

                The hard link file and the original file point to the same memory address. When the original file is deleted, the hard link file is not affected.

sound, but the soft link file will have a null pointer.

                At the same time, whether it is a hard link file or a soft link file, as long as the content of the source file is modified, the link file will also change accordingly.

11.cat、tac、more、less

        (1) cat: View file content (-n: print line numbers, and blank lines will also have line numbers)

                 cat file name (view files under this path)

                 cat path/ file name (view files under other paths)

        (2) tac: View the file contents in reverse order of line numbers

        (3) more: When the file content is large, the content is displayed on one page (the entire screen)

                Press "enter" to display one more line

                Press "b" to display one less page (one full screen)

                Press "Space" to display one more page (one full screen)

                Press "q" to exit

                Press "h" to display more shortcut key functions

        (4) less: directly display the entire file content.

12.head、tail

        Format: head -x file name: display the first x lines of a file

                   tail -x filename: displays the last x lines of a file

                   head -10 filename | tail -1: Display line 10 of the file

                   The function of "|" (pipeline) is equivalent to passing the previous result to the following command in the form of parameters (the output of one command is connected through a pipe as the input of another command)

13.find: Find the location of the file

        Format: find / -name file name: fully search for the location of a file

                   find path-name file name: Find the location of a file in a certain directory

14.vi: Open a file

        (1) Open the file

                vi file name: open normally

                vi +x filename: open the file and locate the file at line x

                vi + filename: open the last line

                vi +/Specify character file name: Open the location of the specified search character, press "n" to find the next one, press "N" to find the previous one

        (2) Three modes

                Edit mode: each key has its shortcut function

                Input mode (insert): input what you press

                Last line (command line) mode: You can enter specific instructions in vi

        (3) Switch between three modes (the default is editing mode)

                Edit mode—>Input mode: Press "i"

                Input mode—>Edit mode: Press "esc"

                Edit mode—>Last line mode: Press ":"

        (4) Commonly used shortcut functions in editing mode

 G : Last line      gg : Jump to the first line      ZZ : Save and exit

"x"gg : Jump to line x      dd : Delete a line     "x"dd : Delete line x      u : Go back to the previous operation (undo)

"." : roll back the operation performed by u     yy : copy a line     "x" yy : copy line x      p : paste

"x"p : Paste x times      x : Cut      "x"x : Cut x characters      r : Replace, then enter a character to replace

        (5) Last line mode

set nu : display the line number      set nonu : do not display the line number

w : save      q! : Force exit without saving      wq : Save and exit

/String : Search for the specified string (press "n" to find the next one, press "N" to find the previous one)

s/A/Q/g : Replace character A with Q ("g" replaces all the current lines, otherwise only replaces the first one in the current line)

g/A/s//Q/g : Replace all A’s in the file with Q

15. Decompression command

        (1)tar

                Packaging format: tar -cvf packaged name file name

                Unpacking format: tar -xvf file name

                Compression format: tar -zcvf compressed name file name

                Decompression format: tar -zxvf file name

                        Adding the -C parameter when decompressing means decompressing to the specified folder: tar -zxvf file name -C usr/local

        (2)zip、unzip

                Decompression format: zip -r compressed name file name

                Compression format: unzip file name

                To use zip or unzip, you need to install it manually: yum install zip unzip -y

16.grep: Find the specified data from the document and list the entire line of text containing the search data

                Format: grep searches the files for content search

                           grep -n finds the file where the content is found (finds the location of the specified content in the file and displays the line number)

                           grep -v finds files whose contents are searched ( reverse search : displays lines that do not contain the specified content)

                           grep -i searches the files for which the content is searched ( ignoring case to find the specified content )

                           grep ^ Find files where content is found (finds the entire line of content starting with ...)

                           grep search content $  find file (find the entire line of content ending with ...)

                grep can search multiple files at the same time: grep search file 1 file 2

4. Use of wildcards

        (1)*: represents 0 or more characters

        (2)? : represents 1 character

        (3) [abcd]: any character in abcd (the content in the square brackets can be switched at will)

        (4) [az]: any character in az

                []You can write multiple characters to represent any number of characters defined in brackets

5. About file and folder permissions

- --- --- --- (respectively indicating file type; u owner permissions; g all group permissions; o other people permissions)

Permissions document Folder (directory)
r read View file contents Can list the contents of a directory (first name only)

w

write Modify file content

Can create and delete files in the directory

(Including changing the name of the file)

x execute executable run file Can enter the directory (cannot view the directory contents)

        (1) Symbol method: Modification of file (folder) permissions

                chmod [ugo] [+-=] [rwx] file or folder name

                Permissions can be added at the same time : chmod u+r,g+w file or folder name

        (2) Digital method

                r:4        w:2        x:1(rw-:6        r-x:5        -wx:3)

                chmod 421 aaa.txt (the permissions of the aaa file are - r-- -w- --x)

                chmod 735 aaa.txt (the permissions of aaa files are - rwx -wx rx)

        (3) chomd -r... (modify the permissions of the folder and all subfolders)

6. Commands about users and user groups

        (1) chown: everyone who modifies the file or folder

                Format: chown the user file name to be modified.

        (2) chgrp: Modify all groups of a file or folder

                Format: chgrp group file name to be modified

        (3) useradd/groupadd: add user/group

                Format: useradd username

                           groupadd group name

                           useradd -m username (create a user and create this user's home directory)

                           useradd -g group name user name (create a user and set the group of this user)

        (4)sudu: Allow ordinary users to execute some super management commands

        (5) passwd: Set the password of a certain user

                Format: passwd username to set password

        (6) su: switch users

                Format: su user to switch

        (7) exit: Exit the current user and return to the previous user (which user you switched from)

       (8) userdel/groupdel: delete user/group

                Format: userdel username

                           groupdel group name

                           userdel -r username (delete user and user's home directory)

                           userdel -f username (forced deletion, that is, even if the user to be deleted is already logged in, you can also add the -f parameter to force the user to be deleted)

        (9) usermod/groupmod: modify users/groups

                Format: usermod -g The group name to be changed to user name (modify the initial group to which the user belongs)

                           usermod -G Additional group to be modified User name (modify the additional group to which the user belongs)

                           groudmod -n Group name to be modified Group name (modify group name)

        (10) groupmems: can manage members of the user's main group

                Format: groupmems -g root -a yzp (add new member yzp to root group)

                           groupmems -g root -d yzp (remove member yzp from root group)

                           groupmems -g root -l (display all members of the root group)

                           groupmems -g root -p (remove all members of the root group)

        (11) newgrp : You can select a group from the user's additional groups as the user's new initial group

7. How to enable ordinary users to have root permissions?

        Directly modify the UID and GID of a user in the /etc/passwd file to 0 to have root permissions.

8. How to add a user to the sudo group?

        

  1. The sudoers file in the etc directory is the file related to the sudo group.
  2. But the sudoers file only has read permissions, so we added write permissions to it.
  3. Use the vim editor to add the ordinary user yzp to the sudo group.

9. Software package installation and shall programming related instructions

        (1) rpm: package management (query instructions)

                rpm -qa: Query all installed rpm packages

                rpm -q software package name: Check whether the software package has been installed

                rpm -qi software package name: Query the detailed information of a certain software package (name, version, installation time, etc.)

                rpm -qf file full path name: query which software package a file belongs to

                rpm -ql software package name: Query what files this software package contains

                rpm -e software package name: delete a certain software package (a prompt message will appear: deleting this software package may cause a certain software to not run properly)

                rpm -e --nodeps package name: forcefully delete a package (no prompt message is displayed)

        (2) yum command:

                yum install package name: Download and install the corresponding software package, and install all dependency packages at once

                yum list | grep software package name: Query the software list (check whether yum has software that needs to be installed)

        (3) Use the GCC compiler to compile the files step by step and complete them in one step.

                  1) Complete in one step

                        

                  2) Completed step by step (-o parameter: specify the name of the executable program)

      ① Generate preprocessor (gcc -E xxxx.c -o xxxx.i)

      ②Compile (gcc -S xxxx.c -o xxxx.s)

      ③Compile (gcc -c xxxx.c -o xxxx.o)

      ④Connect (gcc xxxx.o -o name.exe)

      ⑤Run the program (./name.exe)

                            

        (4) shell script programming

                1) sh xxx.sh: Run a certain shall file (no need to modify the user’s execution permission x)

                2) Define variables: variable name = value (without spaces)

                3) Unset variable: unset variable name

                4) Use the env and export commands to view the current environment variables of the system (environment variables are variables shared by multiple files)

                5) Declare static variables: readonly variable name (static variables cannot be revoked)

                6) Define environment variables (global variables)

                export variable name = value (set a global variable, note: it must be defined in /etc/profile)

                source configuration file (make the modified configuration file take effect immediately)

                        Global variables (environment variables);/etc/profile (environment variable configuration file)

                        Before outputting the defined environment variables, be sure to use the source command to make them effective.

        (5) Position parameter variable

                shall x.sh aaa bbb (enter several parameters when executing the shall file, and the script information can be obtained in the script)

                                     

                                    

                         Parameters: $0: The file name of the current script:

                                    $n: n is a number, 0 is the command itself, 1~9 represents 1~9 parameters, parameters greater than ten should be enclosed in braces, such as ${10}

                                    $*: represents all parameters in the command line and is treated as a whole

                                    $@: represents all parameters in the command line, but will be treated separately

                                    $#: represents the number of all parameters in the command line

                        Other shall special variables (parameters):

                                    $$: Returns the process ID (PID) of the current shall

                                    $?: Returns whether the previous command was successfully executed (0 means success, non-0 means failure or exception)

        (6) Conditional judgment

                Basic syntax: [ xxx ] (there must be spaces on both sides of the content xxx; [ ] returns true if it is not empty, otherwise false)

                Judge sentences:

                        1) Comparison of two strings

                              =: Used to compare whether two strings are equal

                             -z: Used to determine whether the string is empty, if so it returns true

                             -n: used to determine whether the string is empty, if not, returns true;

                            ==: used to determine whether two strings are equal

                            ! =: Determine whether two strings are not equal

                            -a: Returns true when both expressions are true (AND operation)

                            -o: As long as one of the two expressions is true , it returns true (or operation)

                           ! : Returns false when the expression is true , otherwise returns true (XOR operation)

                        2) Comparison of two integers

-lt : less than           -le : less than or equal to       -eq : equal to

-ne : not equal to     -gt : greater than              -ge : greater than or equal to

        

                        3) Judge based on file permissions

-r : Whether there is read permission      -w : Whether there is write permission -x: Whether there is execution permission

                        4) Judge by file type

                                -f: whether the file exists and is a normal file

                                -L: whether the file exists and is a linked file

                                -e: whether the file exists

                                -s: whether the file exists and is not empty

                                -d: Does the folder exist?

                        5) Compare files

                                xxx -nt yyy: Returns true when the xxx file is newer (created earlier) than the yyy file

                                xxx -ot yyy: Returns true when the xxx file is older (created later) than the yyy file

                                xxx -ef yyy: Returns true when the xxx file and the yyy file are the same file

                        

        (7) Process control if statement

                Basic syntax (single branch):

if[  条件判断式  ]         #[  ]两边必须有空格
then
   语句
fi                        #fi为if语句结束语

                Basic syntax (multiple branches):

if[  条件判断式  ]          #[  ]两边必须有空格
then
  语句
elif[  条件判断式  ]
then
  语句
fi                          #fi为if语句结束语

                        (then can be written in the above way, or it can follow [ ];)

        (8) Process control case statement

                Basic syntax:                       

case  $变量名  in
"值1")
   如果变量值等于值1,则执行该语句
;;
"值2")
   如果变量值等于值2,则执行该语句
;;
......省略其他分支......
*)
   如果变量值不等于以上的所有值,则执行该语句
;;
esac

        (9) for loop

                Basic syntax:                       

for(( 初始值;循环条件;迭代语句 ))        #内括号两边都有空格
do
   代码
done

        (9) while loop

                Basic syntax:                       

while  [ 条件判断式 ]        #while与[ ]之间有空格,[ ]与判断式之间也有空格
do
   代码
done

        (10) The read statement reads console input

                Basic syntax: read [parameter] variable name (the user enters a value and assigns it to the variable)

                Parameters: -p: Give a prompt message

                           -n x: read x characters

                           -t: Given a time limit (in seconds) for reading the value, if no input is entered within the specified time, it will automatically exit.

        (11) Custom function               

function  函数名  ()
{
   函数体
   返回值
}

                         

                                                                                         

10. If centos does not have a network, how to configure the network card information so that the virtual machine can access the external network?

     1. Use the ifconfig command to check the network parameters. At this time, the ens33 network card does not have an IP address and a gateway.

        2. Enter the configuration file /etc/sysconfig/network-scripts/ifcfg-ens33 of the ens33 network card and modify the ONBOOT parameter to "yes" .

        3. At this time, use the service network restart command to restart the network service (authentication is required)

        4. At this time, check that the ens33 network card already has an IP address and gateway.

    

11. Differences between the three running modes of scripts

   

        1. Source command: Read and run the shall file directly in the current bash environment, and the file does not require execution permission. (This command can be replaced by . , for example: source xxx.sh is equivalent to . xxx.sh )

        2. ./command: Create a child process to read and run the shall file, but the file must have execution permissions

        3. Sh command: Like the ./ command, create a sub-process in the bash environment to read and run the shall file, and the file does not require execution permission.

12. Shall basic related commands

1. Define variables (no quotes, single quotes, double quotes)

        (1) Single quotation marks: Whatever the content in the single quotation marks is, it will be output, that is, it will be output unchanged.

        (2) Double quotation marks: When outputting, the variables and commands inside the quotation marks will be parsed instead of being output intact.

        (3) No quotation marks: Variables and commands will also be parsed during output, but if there are spaces during definition, an error will occur.   

2. Output variable values ​​(two methods), line wrap output, and non-line wrap output

         (1) By default, the output is newline

         (2) The -n parameter is output without line breaks.

 3. Modify variable values, add new content, and output

        (1) Modify the variable value and redefine it

        (2) Add new content: Add new content after "$variable name" or add new content after ${variable name}

4. Output redirection">",">>"

        (1) ">": followed by a file name, the content of the original file is " overwritten ", that is, the content of the original file is cleared.

        (2) ">>": followed by a file name, indicating " append " new content based on the original file

5. Enter redirection "<"

        "<": Change the data originally entered from the keyboard to read from the file 

        

13. Two ways to assign values ​​to variables using the execution results of commands ` command ` or $( command )

14. Scope of shall variable

1. Global variables: can be used in the entire current Shell process. This is called a global variable. The variables defined in shall are

is a global variable (at this time variable a is defined in the custom function, but can also be used outside the function, proving that it is a global variable,

instead of just inside the function)

2. Local variables: They can only be used inside the function and are called local variables (add the local command before the variable to make the global variable

as local variables)

3. Environment variables: Some variables can also be used in child processes, called environment variables.

        (1) Use bash to enter the shall subprocess, and use the exit command to exit;

        (2) By default, global variables cannot be used in the shall sub-process. In this case, you need to use the export command to import the variables.

As an environment variable, it can be used in the child process.

        (3) Environment variables can also be defined in /etc/profile.

 

15. Process management related commands

        1. Use "&" to put the command into the Bash background to run without affecting the terminal window. The process put into the background is still running.

         2. Jobs command: View processes put into the background

                Parameters: -l lists the PID number and process name of the process

                           -p only lists the PID number of the process

                           -r only lists running processes

                           -p List only stopped processes

        The "+ " sign indicates that this is the most recent command placed in the background, and it is also the default job to be restored when the job is resumed.

        "- " indicates the second to last command placed in the background, and the third and subsequent tasks do not have the "+-" mark.

        3. bg command: Restart the suspended process in the background

                Format: bg job number

             fg command: restore the background process to the foreground and start running again

                Format: fg job number

        4. at command: Set to execute a certain one-time command at a certain time

                Format: at [parameter] [time]

                Parameters: -l: List all jobs currently waiting to be run

                           -c job identification number: displays the actual content of the at job 

                           -d  job identification number: delete a job

                Time format:

                HH:MM [ am|pm] [Month] [Date] [Year],如11:10 am Jan 18 2022

                HH:MM YYYY-MM-DD,如11:10 2022-01-18

                MMDDYY , MM/DD/YY , indicating the current time of the specified date, such as 011822 , 01/18/22

                Specific time : For example, now represents the current time, noon represents 12:00 pm , midnight represents 12:00 am , and Teatime represents 4:00 pm.

                time + n [minutes | hours | days | weeks] means execution at a certain time after a certain point in time. For example, now + 3 hours means 3 hours after the current time.

         5. crontab command: Set tasks that need to be executed periodically

                Format: crontab [parameter] (usage is similar to vim editor)

                Parameters: -e: Edit the contents of a user's crontab file. If no user is specified, it means editing the crontab file of the current user.

                           -l: Display the contents of a user's crontab file. If no user is specified, it means displaying the contents of the current user's crontab file.

-r: Delete a user's crontab file                            from / var/spool/cron . If no user is specified, the current user's crontab file will be deleted by default. 

special symbols

meaning

*(Asterisk)

represents any time

The first "*"  is the minute of the hour ( minute 0~59

The second "*"  is the hour of the day ( hour 0~23

The third "*"  is the day of the month ( day 1~31

The fourth "*"  is the month of the year ( month 1~12

The fifth "*"  is the day of the week ( week 0~7 ( 0 and 7 both represent Sunday)

, (comma)

Represents discontinuous time. For example, " 0 8 , 12 , 16*** command " means that at 8:00 ,

The command is executed once at 12:00 and 16:00 .

- (middle bar)

Represents a continuous time range. For example, "0 5 ** 1-6 command " means 5:00 am from Monday to Saturday 

Execute commands separately.

/ (forward slash)

Represents how often it is executed. For example, "*/10**** command " means executing the command every 10 minutes.

time

meaning

45 22 *** command

Execute the command at 22:45

0 17 ** 1 command

Execute the command at 17:00 every Monday

0 5 1 , 15** command

Execute the command at 5:00 am on the 1st and 15th of each month

40 4 ** 1-5 command

Execute the command at 4:40 a.m. every Monday to Friday

* /10 4 *** command

At 4 a.m. every day , execute the command every 10 minutes

                Example: Execute at 11:30 pm every Friday : write " process test " to the process_test.txt file

         6. ps command: Check what processes are currently in the system

                Format: ps [parameter]

                Parameters: -a: Display all process information of the current terminal

                           -u: Display process information in user format

                           -x: Display process information in user format

                           -l: Only list processes generated by the current shall

                           -ef: Display all current processes in full format ( display UID, PPIP, C and STIME fields )

                           -aux: View all process information in the system

                Instruction description:

USER : user name      PID : process number      %CPU : percentage of CPU occupied by the process     

%MEM : The percentage of physical memory occupied by the process     VSZ : The size of the virtual memory occupied by the process (Kb)

RSS : Size of physical memory occupied by the process (Kb)      TTY : Terminal information

STAY:

-D : Sleep state that cannot be awakened, usually used in I/O situations       -R : The process is running.

-S : The process is in sleep state and can be awakened

-T: Stop state, which may be paused in the background or the process is in a debugging state

-W: memory interaction status (invalid starting from 2.6 kernel)

-X : Dead process (should not appear)

-Z : Zombie process (the process has been terminated, but some programs are still in memory)

-< : high priority (the following status occurs in BSD format)

-N : low priority      -L : locked into memory

-s : Contains child processes      -l : Multi-threaded (lowercase L ) -+: In the background

START : process startup time      TIME : total time the process uses CPU

COMMAND : The command and parameters used to start the process

        7. lsof command: List the files that have been opened in the system. Through the lsof command, we can find the corresponding file

Process information , you can also find the files opened by the process based on the process information.

                Format: lsof [parameter]

                Parameters: -c string: only list files opened by processes starting with string

                           -d: List all files called by the process in a directory

                           -u: Only list files opened by a certain user's process

                           -p PID: Only list files opened by a certain PID process

        8. kill and killall, nice and renice commands

                Format: kill [parameter] process number (terminate a process through the process number)

                           killall process name (terminate a process including all its child processes)

                           nice [-x] command (set the process priority related to a command to x, but cannot set the running process)

                           renice [x] -p process number (modify the priority of a process to x, ordinary users can only modify the priority to be lower than the previous one, and can set the running process )

                Kill parameter: -9: means forcing the process to stop immediately (some processes may ignore the kill command)

         9. pstree command: View the correlations and dependencies between processes (displayed in tree form)

                        Format: pstree [parameter]

                        Parameters: -u: Display the user name of the process

                                   -p: Display the PID of the process 

         10. top command: View dynamic changes in process information, refreshed every 3 seconds by default

                        Format: top [parameter]

                        Parameters: -d number: Specifies the interval for each refresh of the top command, in seconds

                                   -n number: Specifies the maximum number of refreshes before the top command ends

                                   -u username: only monitor the process information of the specified user

In the display window of the top command, you can also use the following keys to perform interactive operations :

? : Display help in interactive mode;

P : Sort by CPU usage, this option is the default;

M : Sort by memory usage;

N : Sort by PID ;

T : Sorted according to the cumulative operation time of the CPU ;

k : Give a signal to a process according to PID . Generally used to terminate a process, signal 9 is a forced termination signal;

r : Reset the priority ( Nice ) value of a process according to its PID ;

q : Exit the top command;

16. Disk management related commands

1. lsblk command: n The lsblk command displays all disks and disk partitions in the system in a tree structure

        Parameters: -f: display detailed information

(If a new hard disk is added, the system must be restarted to take effect.) Restart the system with the reeboot command.

2. fdisk/gdisk command: create a new partition for the hard disk

        Format: fdisk/gdisk device file name

        Use n in the command to create a partition, d to delete a partition, q to view the created partition, w to save and exit, and q to exit without saving.


[yzp@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
 
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
 
Device does not contain a recognized partition table
使用磁盘标识符 0xdf03b737 创建新的 DOS 磁盘标签。
 
命令(输入 m 获取帮助):m            
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-2097151,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-2097151,默认为 2097151):
将使用默认值 2097151
分区 1 已设置为 Linux 类型,大小设为 1023 MiB
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。

3. mkfs command: format the disk (the UUID of the partition just created will only appear after formatting)

        Format: mkfs -t ext4 device file name

4. Mount command: Mount a partition to a directory

        Format: mount device name mounting directory    (the mounting directory is arbitrary)

        Use this command to realize that the mount will become invalid after restarting, that is, the mount point will disappear after restarting.

How to achieve permanent mounting? Mount by modifying /etc/fstab

5. umount command: cancel mounting

        Format: umount mount point/device name

6. df command: displays the space usage of the entire file system (spare hard disk) 

        Format: df [parameter]

        Common parameters: -a: Display all file systems , including /proc , / sysfs and other system-specific file systems

-h: Display the file system space in the units of KB , MB or GB                           that people are accustomed to

7. du command: Calculate the disk space occupied by a directory or file

        Commonly used parameters: -a: Display the capacity of all directories and files

-h: Use the KB , MB or GB units                           that people are accustomed to displaying the capacity.

Guess you like

Origin blog.csdn.net/weixin_64709241/article/details/124386550