content
- I met a Linux
- Linux Basic Commands
First understanding Linux
1. The characteristics of Linux
Openness, multi-user, multi-task, good user interface, device independence, rich network functions, reliable system security, good portability
2. Composition of the Linux system
3. Main functions of the Linux kernel
To interact with computer hardware, realize hardware programming control and interface operation, schedule access to hardware resources, and provide a high-level execution environment and virtual interface to hardware for the user program on the computer
** is divided into: ** process scheduling, file management, memory management, interprocess communication and network interface
4. Common Shell programs
**Bourne Shell(SH) : ** oldest and most widely used
**Korn Shell(KSH) : ** Extension to Bourne Shell, compatible with Bourne Shell
**C Shell(CSH) : ** Syntax and C-class, powerful, but incompatible with Bourne Shell
**Bourne Again Shell(BASH) : ** is a Shell developed by the Free Software Foundation (GNU). It is the default Shell in Linux. BASH is not only compatible with Bourne Shell, but also inherited the advantages of Korn Shell and C Shell
Linux basic commands
1. File and directory operation commands
The ls command
Command format: **ls [option] [directory name]
** Function The ** command lists all subdirectories and files in the target directory
Common parameters:
-a,-all lists all contents in the current folder. The -o file at the beginning lists everything in the current folder, with details, but not groups-lSame as above, including group information -t sort by changed time -v sort the order of the nearest textCopy the code
The CD command
** command format: ** CD [directory name]
** Function The ** command switches the current directory to dirName
Common parameters:
/ Go to the system root directory. ~ Go to the user home directory; - Return to the directory you were in before entering this directory.. Return to parent directoryCopy the code
The PWD command
** Command format: ** PWD
** Function: ** View the full path of current Working Directory
** Common parameters: ** Generally, no parameters are required
The mkdir command
**mkdir [options] directory…
** Function: ** You can use the mkdir command to create a folder or directory named DirName in a specified location. The user who wants to create a folder or directory must have write permission on the parent folder of the file being created. The name of the created folder (directory) cannot be the same as the name of the file in its parent directory (parent folder), that is, the directory cannot have the same name (case sensitive).
Common parameters:
-z: Sets the security context. This parameter is valid when SELinux is used. -m< target properties > or --mode< target properties > Sets the permission of the directory while creating the directory; -p or --parents Create a parent directory if the parent directory is not already created; --version Displays version information.Copy the code
The rm command
Format: **rm [options] file…
** Delete one or more files or directories in a directory. If the -r option is not used, rm will not delete the directory. If you use RM to delete a file, you can usually still restore the file.
Common parameters:
-d: Directly deletes the hard connection data of the directory to be deleted to 0 and deletes the directory.-f: Forcibly deletes files or directories. -i: ask the user before deleting an existing file or directory. -r or -r: Recursive processing. All files in a specified directory are processed together with subdirectories. Preserve-root: does not recurse to the root directory -v: displays the detailed command execution process.Copy the code
Rmdir commands
**rmdir[option]… Directory…
** This command deletes one or more subdirectory entries from a directory. When deleting a directory, you must also have the write permission on the parent directory.
Common parameters:
-p or --parents: Deletes a specified directory and deletes the upper-layer directory of the directory if it is empty. --ignore-fail-on-non-empty: This option causes the rmdir command to ignore error messages caused by deleting a non-empty directory; -v or -verboes: displays the detailed execution process of the command. --help: displays the help information of the command. --version: displays the version information of the command.Copy the code
The mv command
** Command format: **mv[option] Source file or directory Directory file or directory
** The mv command renames a file or moves it to a new directory depending on the type of the second argument in the mv command (the target file or the target directory). When the second parameter type is a file, the mv command completes the file renaming. In this case, only one source file (or the name of the source directory) can be created. It renames the given source file or directory to the given destination file name. If the second parameter is an existing directory name, multiple source files or directories can be specified. The mv command moves the specified source files to the destination directory. When moving a file across a file system, mv copies and deletes the original file, and links to the file are lost.
Common parameters:
--backup=< backup mode > : If the file needs to be overwritten, backup the file before overwriting; -b: Creates a backup for a file that exists before overwriting it.-f: If the target file or directory is the same as the existing file or directory, the existing file or directory is overwritten directly. -i: an interactive operation. The user is asked whether to overwrite the target file if the source file has the same name as the target file or a file in the target directory. If you enter Y, the target file will be overwritten. Enter n to cancel moving the source file. This prevents the file from being overwritten by mistake. -- stripe-trailing slashes: delete slash '/' from source file; -s < suffix > : specifies the suffix for the backup file instead of the default suffix. --target-directory=< directory > : specifies the source file to be moved to the target directory; -u: Moves a file only when the source file is newer than the target file or the target file does not exist.Copy the code
The cp command
** Command format: **cp [option] Source destination
** Copies a source file to a destination file, or copies multiple source files to a destination directory.
Common parameters:
-a: Specifies both the effect and effect of this parameter"-dpR"Parameters are the same;-d: When copying a symbolic link, the target file or directory is also set up as a symbolic link and points to the original file or directory connected to the source file or directory;-f: Forcibly copy files or directories, regardless of whether the target file or directory already exists; -i: asks users before overwriting existing files.-l: Hardwire source files instead of copying files -p: preserves the attributes of the source file or directory. -r/R: indicates recursive processing. All files in a specified directory are processed together with subdirectories.-s: make symbolic links to source files instead of copying files -u: after this parameter is used, files are copied only when the change time of the source file is newer than that of the target file or the corresponding target file does not exist. -s: replace the default SUFFIX with the specified SUFFIX. -b: backs up existing file targets before overwriting them. -v: displays detailed command operations.Copy the code
Touch command
** Command format: **touch [options] file
**touch command parameters can change the date and time of a document or directory, including access time and change time.
Common parameters:
-a: or --time=atime or --time=access or --time=use only changes the access time; -c: or --no-create Creates no files.-d: < date and time > uses the specified date and time instead of the current time;-f: This parameter is ignored and is only responsible for solving the compatibility problem of the BSD version touch command. -m: or --time=mtime or --time=modify; -r: < reference file or directory > Sets the date and time of the specified file or directory to be the same as that of the reference file or directory. -t: < date time > uses the specified date time instead of the current time; --help: online help; --version: displays the version information.Copy the code
The cat command
**cat [option] [file]
Function:
- Display the entire file at once :cat filename
- Create a file from the keyboard :cat > filename Can only create new files, not edit existing files.
- To combine several files into one file :cat file1 file2 > file
Common parameters:
-n or -number: indicates the number of all output lines starting with 1. -b or --number-nonblank: similar to -n except that blank lines are not numbered;-sOr --squeeze-blank: when there are more than two consecutive blank lines, replace them with one blank line; -a: displays unprintable characters and $at the end of the line.-e: equivalent to the"-vE"Options; -t: Equivalent to"-vT"Options;Copy the code
The nl command
[option] [file]
The **nl command reads the File argument (standard input by default), calculates the line number in the input, and writes the calculated line number to standard output. In the output, the NL command calculates the left line based on the flags you specify on the command line. The input text must be written in the logical page. Each logical page has a header, body, and footer section (which can be empty). Unless the -p flag is used, the nl command resets the line number at the beginning of each logical page. Line evaluation flags can be set separately for header, body, and footer sections (for example, header and footer lines can be evaluated while text lines cannot).
Common parameters:
-b: specifies the line number. There are two ways to specify the line number: -b a: lists the line number regardless of whether the line is empty (similar to cat -n). -b t: If there are empty lines, do not list the line number of the empty line (default value). -n: lists the line numbers in the following three ways: -n ln: the line numbers are displayed on the left of the screen. -n rn: The row number is displayed to the right of its column without adding 0. -n rz: The line number is displayed on the right of the column and 0 is added. -w: indicates the number of digits occupied by the row number column. -p: does not restart the calculation at the logical delimiter.Copy the code
More orders
Format: * * * * more [- dlfpcsu] [- num] [+ / pattern] [+ linenum] [file]…
Function: The more command is used to view the contents of a file, similar to the cat command. However, the more command can view the contents of a file by page and supports line hopping.
Common parameters:
-< number > : specifies the number of lines to display on each screen.-d: "[press space to" is displayedcontinue.'q'To quit.] "and" [Press'h' forInstructions] "; -c: No scrolling operation is performed. Refresh the screen each time;-s: Condenses multiple blank lines into a single line for display. -u: disables the underscore. +< number > : displays from the line with the specified number.Copy the code
Common Operation Commands
- Enter goes down n rows and needs to be defined. The default is 1 line
- Ctrl+F scroll down one screen
- Space bar scroll down one screen
- Ctrl+B returns to previous screen
- = Prints the line number of the current line
- : f Outputs the file name and the line number of the current line
- V Invokes the vi editor
- ! Command invokes the Shell and executes the command
- Q out more
Use less
Command format: [Parameter] file
What it does: Less is similar to more, but you can browse through files at will. More can only move forward, not backward, and less does not load the entire file before viewing it.
Common parameters:
-e: Automatically exits after the file content is displayed.-f: Forcibly displays files. -g: displays only the currently displayed keywords without highlighting all the searched keywords to improve the display speed.-l: Ignore case difference during search. -n: Displays the first line number of each line.-s: Condenses consecutive blank lines into one line for display; -s: displays long content on a single line without newline. -x< number > : displays the TAB character as a specified number of space characters.Copy the code
Common operation commands:
- B Turn back a page
- D Turn back half a page
- H The help page is displayed
- Q Exits the less command
- U Scroll forward half a page
- Y scroll forward one row
- The space bar scrolls a line
- Enter to scroll a page
- [pageDown] : Scroll down a page
- [PageUp] : Scroll up a page
A head command
**head [parameter]… [file]…
**head is used to display the beginning of the file to standard output. By default, the head command prints the first 10 lines of the corresponding file.
Common parameters:
-n< number > : specifies the number of lines to display the header content. -c< character number > : specifies the number of characters to display the header content. -v: always displays the header information of the file name. -q: does not display the header information of the file name.Copy the code
Tail command
**tail[required parameters][Select parameters][file]
Function: Displays the content at the end of a specified file. If no file is specified, it is processed as input information. View log files frequently.
Common parameters:
-- Retry: Attempts to open a file when the tail command starts and the file becomes inaccessible later. Use this option with the option "-- follow=name"; -c<N> or -- bytes=<N> : Outputs N (N is an integer) bytes at the end of the file.-f< name/descriptor > or; --follow<nameldescript> : Display the latest content added to the file. Name: monitors file changes by file name. "-f"Equivalent to" -fdescriptor "; -f: With options "-follow=name" and "--retry""The function is the same when used together; -n< n > or -- line=< n > : The last n (n digit) lines of the output file. --pid=< process NUMBER > : This parameter is used with the -f option. When the process with the specified process number terminates, the tail command is automatically executed. -q or -- quiet or -- silent: If there are multiple file parameters, no file names are displayed. -s< seconds > or -- sleep-interal=< seconds > : used with the "-f" option to specify the number of seconds at which to monitor file changes; -v or -- verbose: When multiple file parameters are present, each file name is always displayed. --help: displays the help information of the command. --version: displays the version information of the command.Copy the code
2. Search for files
- Which looks at the location of the executable.
- Whereis views the location of a file.
- Locate works with the database to view the file location.
- Find Actual search disk query file name.
Which command
** Command format: **which name of the executable file
The **which directive searches for the location of a system command in the PATH variable and returns the first search result.
Common parameters:
-n< file name length > : specifies the file name length. The specified length must be longer than or equal to the longest file name in all files. -p< filename length > : the same as -n, except that the < filename length > contains the file path. -w: specifies the width of the output field. -v: displays the version information.Copy the code
Whereis command
Whereis [-bmsu] [BMS directory name -f] File name
The command whereis locates executables, source code files, and help files in a file system. The attributes of these files should belong to the source code, binary files, or help files.
The whereis program also has the ability to search source code, specify alternate search paths, and search for unusual items.
Common parameters:
-b: searches only binary files. -b < directory > : searches for binaries only in the specified directory.-f: Do not display the path name before the file name. -m: searches only description files. -m < directory > : searches for description files only in the specified directory.-s: Only find the original code file; -s < directory > only looks for original code files in the set directory; -u: searches for files that do not contain the specified type.Copy the code
The locate command
**Locate [select parameter] [style]
Function:
The Locate command can find files faster when searching databases, which are updated by the Updatedb program periodically created by Cron Daemons, than when searching through the entire hard drive database. The worse thing is that locate may not find files that were recently created or renamed. In the built-in values, updatedb runs once a day, which can be updated by modifying crontab. (etc/crontab)
Locate specifies that it is used to find a qualified file. It goes to the database that stores the file and directory names and looks for the file or directory that meets the template style criteria, using special characters (such as “” or”? If you specify a template as kcpaner, locate finds all files or directories that start with a kCPA string and end with NER. If the directory name is kcPartner, locate lists all files in that directory, including subdirectories.
Locate command and find find file search function is similar, but locate through the update program will be hard disk all files and directory information to establish an index database, in the implementation of loACte directly find the index, the query speed will be faster, index database is generally managed by the operating system, However, you can force the system to modify the index database immediately by issuing an UPDATE directly.
Common parameters:
-d< directory > or --database=< directory > : specifies the directory where the database resides; -u: updates the slocate database. --help: displays help. --version: displays the version information.Copy the code
The find command
**find pathname-options [-print-exec-ok…]
** function: ** used to find the file in the file tree, and make the corresponding processing
Common parameters:
-amin< min > : Finds files or directories that have been accessed at a specified time, in minutes; -anewer< reference file or directory > : finds a file or directory whose access time is closer to the current one than the specified file or directory. -atime<24 hours > : searches for files or directories that have been accessed at a specified time, expressed in 24 hours. -cmin< minute > : searches for files or directories that have been changed at the specified time. -cnewer< reference files or directories > finds newer files or directories whose change time is closer to that of the specified file or directory; -ctime<24 hours > : searches for files or directories that have been changed at a specified time, in 24 hours. -daystart: calculates the time from today. -depth: Searches for the deepest subdirectory in a specified directory. -expty: searches for files with 0 Byte file size or empty directories that do not have any subdirectories or files. -exec< execute instruction > : execute the find instruction if the return value is True; -false: sets the return value of the find command to false. -fls< list file > : This parameter has the same effect as the "-ls" parameter, but saves the result as the specified list file. -follow: exclude symbolic joins; -fprint< list file > : This parameter has the same effect as the "-print" parameter, but saves the result to the specified list file. -fprint0< list file > : This parameter has the same effect as "-print0" parameter, but saves the result to the specified list file. -fprintf< list file >< Output format > : This parameter has the same effect as the "-printf" parameter, but saves the result to the specified list file; -fstype< file system type > : only files or directories under this file system type are searched. -gid< group id > : searches for files or directories that match the specified group id. -group< group name > : searches for files or directories that match the specified group name. -help or -help: Online help; -ilname< Template style > : This parameter has the same effect as the "-lname" parameter, but ignores the difference in case. -iname< Template style > : The effect of this parameter is similar to that of the "-name" parameter, but the difference in case is ignored. -inum<inode number > : searches for the file or directory that meets the specified inode number. -ipath< Template style > : The effect of this parameter is similar to that of the "-path" parameter, but the difference in case is ignored. -iregex< Template Style > : The effect of this parameter is similar to that of the -regexe parameter, but the difference in case of characters is ignored. -links< number of connections > : finds files or directories that match the specified number of hard connections; -iname< template style > : specifies the string as the template style for finding symbolic links; -ls: Lists file or directory names to standard output, assuming that the return value of the find command is true. -maxdepth< directory depth > : sets the maximum directory depth. -mindepth< directory level > : sets the minimum directory level. -mmin< minute > : searches for files or directories that have been changed at a specified time, in minutes. -mount: The effect of this parameter is the same as that of -xdev. -mtime<24 hours > : searches for files or directories that have been changed within a specified period of time, in 24 hours. -name< template style > : specifies a string as the template style to find files or directories; -newer< reference files or directories > : finds files or directories whose change time is closer to the current one than the specified file or directory. -nogroup: finds files or directories that do not belong to the local host group identifier. - Noleaf: does not consider that directories need to have at least two hard connections; -nouser: finds files or directories that do not belong to the local host user id. -ok< execute command > : The effect of this parameter is similar to that of -exec, but the user is asked before executing the command. If y or y is answered, the command is abandoned. -path< template style > : specifies a string as the template style for finding directories. -perm< permission value > : searches for files or directories that match the specified permission value. -print: lists the file or directory name to standard output, assuming the return value of the find command is true. The format is one name for each column, and each name is preceded by a./ string. -print0: lists the file or directory name to standard output, assuming the return value of the find command is true. All names in the format are on the same line; -printf< output format > : Lists file or directory names to standard output, assuming the return value of the find directive is true. The format can be customized; -prune: does not find strings as a template style for finding files or directories; -regex< template style > : specifies a string as the template style for finding files or directories. -size< file size > : searches for files that match the specified file size. -true: Sets the return value of the find command to true. -typ< file type > : searches for files that match the specified file type. -uid< user id > : searches for files or directories that match the specified user id. -used< days > : searches for files or directories that were accessed at a specified time after the file or directory was changed, in days. -user< owner name > : finder and file or directory with the specified owner name. -version or -- version: displays the version information. -xdev: limits the range to the first file system. -xtype< file type > : This parameter has the same effect as the "-type" parameter except that it checks for symbolic links.Copy the code
3. Upload and download files
The tar command
**tar[required parameters][Select parameters][file]
** Function: ** to compress and decompress files. Tar itself does not have compression. It is implemented by calling the compression function
Common parameters:
-a or --catenate: adds files to existing backup files; -b: Sets the block size. -c or --create: creates a new backup file. -c < directory > : This option is used for decompression, and can be used to decompress in a specific directory.-d: Record file differences; -x or --extract or --get: restore files from backup files; -t or --list: lists the contents of backup files. -z or --gzip or --ungzip: Processes backup files using the gzip directive; -z or --compress or --uncompress: Processes backup files using the compress command.-f< backup file > or --file=< backup file > : specifies the backup file; -v or --verbose: displays the command execution process. -r: adds a file to a compressed file. -u: Adds changed and existing files to existing compressed files. -j: supports bzip2 decompression files. -v: displays the operation process.-l: file system boundary setting; -k: Retain the original file. -m: the file will not be overwritten. -w: verifies the correctness of the compressed file. -p or --same-permissions: restore a file with the original file permissions; -p or --absolute-names: Use the absolute name of the file name and do not remove the slash (/) before the file name. -n < date format > or --newer=< date time > : Save files newer than the specified date to the backup file. --exclude=< template style > : exclude files that match the template style.Copy the code
Gzip command
**gzip[parameter][file or directory]
** Features: ** Gzip is a widely used compression program that compresses files with a “.gz” extension at the end of their names.
Common parameters:
A or -- ASCII: use ASCII text mode;-dOr --decompress or ----uncompress: uncompress a compressed file;-fOr -- force: forcibly compress files. Regardless of whether a file name or hardlink exists and whether the file is symbolic; H - or -help: Online help;-l-- list: lists information about compressed files. -l or -- License: displays the version and copyright information. -n or --no-name: The original file name and time stamp are not saved when the file is compressed. -n or -- name: Saves the original file name and time stamp when the file is compressed. -q or -- quiet: No warning message is displayed. -r or -- recursive: processing all files and subdirectories in a specified directory together; -s or < compressed tailstring > or ----suffix< compressed tailstring > : changes the compressed tailstring; - t or -test: Test whether the compressed file is correct; -v or -- verbose: displays the command execution process. -v or -- version: displays the version information. -< compression efficiency > : The compression efficiency ranges from 1 to 9. The default value is 6. The larger the value is, the higher the compression efficiency will be. --best: This parameter has the same effect as the "-9" parameter; --fast: This parameter has the same effect as the -1 parameter.Copy the code
5. Set permissions for Linux files
The chmod command
** Command format: **chmod [-cfvr] [–help] [–version] mode file
** Function: ** Is used to change the access permission of a file or directory and control the access permission of a file or directory.
competence
- U: indicates the current user of a directory or file
- G: current group of directories or files
- O: a user or group other than the current user or group of a directory or file
- A: All users and groups
Access code
- R: indicates the read permission. The value is 4
- W: indicates the write permission. The value is 2
- X: execution permission, represented by the number 1
-
- : Delete permission. The value is 0
Common parameters:
-c or -- changes: the effect is similar to that of the -v parameter, but only the changes are returned.-fOr --quiet or -- silent: no error message is displayed; -r or -- recursive: processing all files and subdirectories in the command directory at once; -v or -- verbose: displays the command execution process. --reference=< reference file or directory > : Set the group of the specified file or directory to be the same as the group of the reference file or directory; < permission scope >+< Permission Settings > : Enable this option permission setting for files or directories within the permission scope; < permission scope >-< Permission Settings > : close the option permission Settings for files or directories within the permission scope; < Permission scope >=< Permission Settings > : specifies the permission Settings of this option for files or directories in the specified permission scope.Copy the code
- S: Special permission
The CHGRP command
** CHGRP [option] [group] [file]
** Run the ** CHGRP command to change the owning group of a file or directory by using the group name or group id. The permission is superuser.
Common parameters:
-c or -- changes: the effect is similar to that of the -v parameter, but only the changes are returned.-fOr --quiet or -- silent: no error message is displayed; -h or --no-dereference: modifies only the symbolic link file, not any other related file; -r or -- recursive: processing all files and subdirectories in the command directory at once; -v or -- verbose: displays the command execution process. --reference=< reference file or directory > : Set the group of the specified file or directory to be the same as the group of the reference file or directory;Copy the code
Chown command
**chown [option]… [Owner][:[group]] file…
** Change the file owner and group by chown. When changing the owner or group of a file, you can set the user name and user id. Ordinary users cannot change their files to other owners. The operation permission is generally an administrator.
Common parameters:
-c or -- changes: the effect is similar to that of the -v parameter, but only the changes are returned.-fOr --quite or -- silent: does not display error messages; -h or --no-dereference: Changes only to symbolic linked files without changing any other related files; -r or -- recursive: processing all files and subdirectories in a specified directory together; -v or -- version: displays the command execution process. --dereference: has the same effect as the "-h" parameter; --help: online help; --reference=< reference file or directory > : Set the owner and group of the specified file or directory to be the same as the owner and group of the reference file or directory. --version: displays the version information.Copy the code
6. Disk storage related
The df command
** command format: **df [option] [file]
** Function: ** Displays the available space of files on the specified disk. If no file name is specified, the available space of all currently mounted file systems is displayed. By default, disk space will be displayed in 1KB, unless the environment variable POSIXLY_CORRECT is specified, which will be displayed in 512 bytes
Common parameters:
-aOr --all: contains all file systems. --block-size=< block size > : displays the number of blocks with the specified block size; -h or --human-readable: Displays information in a readable manner; -h or --si: The same argument as -h, but calculated using 1000 Bytes instead of 1024 Bytes; -i or --inodes: displays information about the inode. -k or --kilobytes: specifies a block size of 1024 bytes.-lOr --local: displays only the file system on the local end. -m or --megabytes: specifies the block size of 1048576 bytes. --no-sync: do not run sync before obtaining disk usage information. This is the default value. -por --portability: using POSIX in the output format; --sync: Run the sync command before obtaining the disk usage information. -t< file system type > or --type=< File system type > : displays information about disks of a specified file system type. -t or --print-type: displays the type of the file system. -x< file system type > or --exclude-type=< file system type > : do not display the disk information of the specified file system type. --help: displays help. --version: displays the version information.Copy the code
Du command
Syntax: **du [options][file]
** Function: ** Displays the disk space used by each file and directory.
Common parameters:
-aOr -all displays the size of individual files in the directory. -b or -bytes Indicates the size of a directory or file, in bytes. -c or --total Displays the total of all directories or files in addition to the size of individual directories or files. -k or --kilobytes are output in KB(1024bytes). -m or --megabytes are output in MB.-sOr -- Summarize just shows the sum and lists only the last sum. -h or --human-readable will improve the readability of the information in units of K, M, or G. -x or --one-file-xystem is based on the file system at the beginning of processing. If a different file system directory is encountered, it is skipped. -l < symbolic link > or --dereference< symbolic link > displays the source file size of the symbolic link specified in the option. -s or --separate-dirs Displays the size of individual directories, excluding the size of their subdirectories. -x < file > or --exclude-from=< file > Specifies a directory or file in < file >. --exclude=< directory or file > Ignores the specified directory or file. -d or --dereference-args displays the size of the source file for the specified symbolic link. -h or --si has the same parameters as -h, but K, M, and G are converted to 1000 units.-lOr --count-links recomputes the hardware link file. The instanceCopy the code
7. Performance monitoring and optimization commands
The top command
** Format: **top [parameter]
** Function: ** Displays information about the processes that are running in the system, including process IDS, memory usage, and CPU usage
Common parameters:
-b: The operation is performed in batch mode. -c: displays complete governance commands.-d: Screen refresh interval; -I: ignores the failure process.-s: Confidential mode; -s: cumulative mode. -i< time > : Indicates the interval. -u< User name > : specifies the user name. -p< process number > : specifies the process. -n< times > : indicates the number of times to be displayed in a loop.Copy the code
The free command
** Syntax: **free [parameter]
Run the free command to display the used and free memory, including physical memory, swap memory, and kernel buffer memory. Shared memory will be ignored
Common parameters:
-b: displays the memory usage in bytes. -k: displays the memory usage in KB. -m: displays the memory usage in MB. -o: no buffer adjustment column is displayed.-s< interval seconds > : continuously observe memory usage; -t: displays the total memory column. -v: displays the version information.Copy the code
The vmstat command
Command format:
- vmstat [-a] [-n] [-S unit] [delay [ count]]
- vmstat [-s] [-n] [-S unit]
- vmstat [-m] [-n] [delay [ count]]
- vmstat [-d] [-n] [delay [ count]]
- vmstat [-p disk partition] [-n] [delay [ count]]
- vmstat [-f]
- vmstat [-V]
** Function: ** is used to display virtual memory information
Common parameters:
-a: Display active pages;-f: Displays the total number of processes created after startup. -m: displays slab information. -n: Displays the header information only once.-s: tabular display of event counters and memory status;-d: reports the disk status. -p: displays the status of a specified disk partition. -s: indicates the unit of output information.Copy the code
Iostat command
**iostat[parameter][time][times]
Iostat allows you to view CPU, network adapter, TTY device, disk, CD-ROM, and other device activity and load information.
Common parameters:
-c: displays only the CPU usage.-d: Displays only the device utilization. -k: displays the status in kilobytes per second instead of blocks per second. -m: Displays the status in megabytes per second. -p: displays the status of only the block device and all other partitions in use. -t: displays the time when each report is generated. -v: displays the version number and exits. -x: displays the extension status.Copy the code
The lsof command
**lsof [parameter][file]
** Function: ** Is used to view the files your process opened, the process to open the file, the process opened port (TCP, UDP). Retrieve/restore deleted files. Lsof is a very convenient system monitoring tool, because lsof needs to access the core memory and a variety of files, so you need to perform the root user.
Common parameters:
-a: lists the processes in which the open file exists. -c< process name > : lists the files opened by the specified process. -g: lists details about processes with GID numbers.-d< file number > : lists the processes that occupy the file number. +d< directory > : lists open files in the directory. +D< directory > : recursively lists open files in the directory; -n< directory > : Lists the files that use NFS. -i< Condition > : Lists the processes that meet the conditions. (4, 6, protocol, : port, @IP) -p< process number > : lists the files opened by the specified process number. -u: lists details about processes with the UID number. -h: Displays the help information. -v: displays the version information.Copy the code
8. Network commands
The ifconfig command
** Ifconfig [network device] [parameters]
The **ifconfig command is used to view and configure network devices. When the network environment changes, you can use this command to configure the network.
Common parameters:
Add < address > : set the IPv6 IP address of the network device. Del < address > : deletes the IPv6 IP address of the network device. Down: disables the specified network device. < hW < Network device type >< Hardware Address > : Sets the network device type and hardware address. Io_addr <I/O address > : indicates the I/O address of the network device. Irq <IRQ address > : Sets the IRQ of the network device. Media < Network media Type > : set the media type of the network device. Mem_start < memory address > : set the start address occupied by the network device in the main memory. Metric < number > : Specifies the number to be added when calculating the number of packets to be forwarded; Mtu < bytes > : Sets the MTU of the network device. Netmask < subnet mask > : set the subnet mask of the network device. Tunnel < address > : indicates the communication address of the IPv4 and IPv6 tunnel. Up: starts the specified network device. -broadcast< address > : The packets to be sent to the specified address are treated as broadcast packets. -pointopoint< address > : establishes a direct connection with the network device at the specified address. This mode is confidential. -promisc: Disables or enables the promiscuous mode of specified network devices. IP address: specifies the IP address of the network device. Network device: Specifies the name of the network device.Copy the code
The route command
** Command format: **route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric metric]] [if Interface]]
The **Route command is used to manipulate the routing table based on kernel IP. Its main purpose is to create a static Route to specify a host or network through a network interface, such as eth0. When “add” or “del” is used, the routing table is modified. If no parameter is specified, the current routing table content is displayed.
Common parameters:
-a: Sets the address type. -c: prints the route cache of the Linux core. -v: details mode. -n: does not perform DNS reverse lookup and displays the IP address in digital format.-e: Displays the routing table in netstat format. -net: routing table to a network. -host: indicates the routing table to a host.Copy the code
The ping command
** Ping [parameter] [host name or IP address]
Function:
The ping command is used to check the status of the network and external hosts. Tracking and isolating hardware and software problems; Test, evaluate, and manage the network. If the host is running and connected to the network, it responds to the echo signal. Each echo signal request contains an Internet Protocol (IP) and ICMP header, followed by a Tim structure, and enough bytes to fill in the packet. The default is to send back signal requests continuously until an interrupt signal is received (CtrL-c).
The ping command sends one datagram per second and prints one line of output for each received response. The ping command calculates signal round trip times and packet loss statistics, and displays a brief summary when done. The ping command ends when the program times out or when a SIGINT signal is received. The Host parameter is either a valid Host name or Internet address.
Common parameters:
-d: Uses the Socket SO_DEBUG function. -c< completion times > : Sets the number of times for completing the request response.-f: Limit detection; -i< interval seconds > : specifies the interval for sending and receiving messages. -i < network interface > : sends data packets using the specified network interface.-l< preload > : sets the packet to be sent before the requested message is sent; -n: outputs only values. -p< Template style > : Sets the template style for filled packets; -q: does not display the command execution process except the information about the beginning and end. -r: directly sends the data packets to the remote host, ignoring the common Routing Table. -r: records the routing process.-s< packet size > : Sets the packet size. -t< TTL value > : sets the TTL value. -v: displays the detailed command execution process.Copy the code
Traceroute command
** Traceroute [parameters][host]
The traceroute directive lets you track the route of network packets. The default packet size is 40Bytes, which can be set by the user.
Common parameters:
-d: Uses socket-level debugging.-f< TTL value > : sets the TTL value of the first detection packet. -f: Do not set off position. -g< gateway > : sets a maximum of eight source route gateways. -i< network interface > : sends data packets using the specified network interface. -i: uses ICMP response instead of UDP data. -m< TTL value > : sets the maximum TTL value of packets to be detected. -n: Use the IP address instead of the host name. -p< Communication port > : indicates the UDP communication port. -r: directly sends the data packets to the remote host, ignoring the common Routing Table.-s< Source address > : Set the IP address for sending packets from the local host. -t< service type > : sets the TOS value for detecting packets. -v: displays the detailed command execution process. -w< Timeout seconds > : specifies the time to wait for the return from the remote host. -x: enables or disables the correctness check of packets.Copy the code
The netstat command
** Netstat [-accefghilMnNoprSTUVVwx][-a < network type >][– IP]
** Function: ** Netstat displays statistics related to IP, TCP, UDP, and ICMP protocols. It is generally used to check the network connection status of each port on the host.
Common parameters:
-aOr --all: displays all connections of sockets; -a < network type > or --< network type > : lists the related addresses in the connection of the network type. -c or --continuous: Lists the network status continuously. -c or --cache: displays the cache information configured by the router.-eOr --extend: display other network related information; -f or --fib: displays the fib. -g or --groups: displays the member list of multiple broadcast groups. -h or --help: online help; -i or --interfaces: displays the network interface information form.-l--listening: Indicates the Socket of the monitored server. -m or --masquerade: shows disguised network connections; -n or --numeric: uses the IP address directly, not through the DNS; -n or --netlink or --symbolic: indicates the symbolic connection name of the network hardware peripheral device. -o or --timers: displays the timer. -p or --programs: Displays the identifiers and names of the programs using the Socket. -r or --route: Displays the Routing Table.-sStatistice: Statistics showing network work information; -t or -- TCP: displays the connection status of TCP. -u or --udp: displays the connection status of the UDP transport protocol. -v or --verbose: displays the command execution process. -v or --version: displays the version information. -w or -- RAW: displays the connection status of the RAW transmission protocol. -x or -- Unix: Effect and specification of this parameter"-A unix"Parameters are the same; -- IP or --inet: effect and specification of this parameter"-A inet"Same parameters.Copy the code
Ss command
Command format:
Ss [parameter]
Ss [parameter] [filter]
The **ss(short for Socket Statistics) command can be used to obtain Socket Statistics. The output of this command is similar to that of netstat, but it displays more detailed TCP connection status information, and is faster and more efficient than netstat. It uses tcp_DIag in the TCP protocol stack (which is a module for analyzing statistics), and can get first-hand kernel information directly, which makes ss command fast and efficient. Ss can work without tcp_DIag.
Common parameters:
-h: Displays the help information. -v: displays the command version. -n: indicates that the service name is displayed numerically but not parsed.-a: Displays all sockets;-l: Displays the listening socket; -o: displays timer information. -m: displays the memory usage of the socket. -p: displays information about the process that uses the socket. -i: displays internal TCP information. -4: Displays only ipv4 sockets. -6: Displays only ipv6 sockets. -t: displays only TCP sockets. -u: displays only UDP sockets.-d: Displays only DCCP sockets. -w: Displays only RAW sockets. -x: displays only UNIX domain sockets.Copy the code
Telnet command
** Telnet [parameters][host]
** Function: ** Execute Telnet command to start terminal operation and log in to remote host.
Common parameters:
-8: allows the use of 8-bit character data, including input and output.-a: Attempted automatic login to the remote system; -b< host alias > : Specifies the name of the remote host using the alias. -c: does not read. Telnetrc files in the user's exclusive directory.-d: Start troubleshooting mode;-e< Disengagement character > : Sets the disengagement character; -e: filters out separated characters.-f: Specifies the effect of this parameter"-F"Parameters are the same; -f: when Kerberos V5 authentication is used, the authentication data of the local host can be uploaded to the remote host if this parameter is added. -k< domain name > : when Kerberos authentication is used, this parameter is added to make the remote host adopt the specified domain name instead of the host domain name. -k: does not automatically log in to the remote host.-l< user name > : specifies the user name to log in to the remote host. -l: allows the output of 8-bit character data. -n< Record file > : Specifies the information about the file to record. -r: uses a user interface similar to the rlogin command. -s < service type > : sets the TOS information required for Telnet connections. -x: Indicates that the host supports data encryption. -x < Authentication mode > : disables the specified authentication mode.Copy the code
RCP command
** RCP [parameter] [source file] [target file]
** Function: the ** RCP command is used to remotely copy files or directories. If more than two files or directories are specified at the same time and the final destination is an existing directory, the RCP command copies all the previously specified files or directories to this directory.
Common parameters:
-p: saves the properties of the source file or directory, including the owner, owning group, permission, and time. -r: indicates recursive processing. Files in a specified directory and subdirectories are processed together. -x: encrypts all information transmitted between two Linux hosts. -d: specifies the port number of the remote server.Copy the code
The SCP command
** SCP [parameter] [original path] [destination path]
Run: SCP is short for Secure Copy. SCP is a secure remote file copy command based on SSH login in Linux. The Linux SCP command copies files and directories between Linux servers.
Common parameters:
-1: uses SSH version 1. -2: Uses SSH version 2. -4: Uses ipv4. -6: uses ipv6. -b: Runs in batch mode. -c: uses compression. -f: specifies the SSH configuration file.-l: Specifies the bandwidth limit; -o: indicates the SSH option to be used. -p: specifies the port number of the remote host. -p: indicates the last modification time, last access time, and permission mode of a reserved file. -q: the replication progress is not displayed. -r: replicates recursively.Copy the code
Other commands
Ln command
Ln [parameter][source file or directory][destination file or directory]
Function:
In Linux file systems, there are so-called links, which we can think of as aliases for files, and links fall into two categories: The hard link and the soft link are symbolic links. The hard link means that a file can have multiple names, while the soft link is to create a special file whose content points to the location of another file. Hard links exist in the same file system, while soft links can span different file systems.
Soft links:
- Soft links exist in the form of paths. Similar to shortcuts in the Windows operating system
- Soft links can cross file systems, but hard links cannot
- Soft links can link to a file name that does not exist
- Soft links can link directories
Hard links:
- Hard links exist as copies of files. But it doesn’t take up real space.
- Hard links to directories are not allowed
- Hard links can be created only in the same file system
Common parameters:
-b or --backup: delete, overwrite the backup before the target file;-d-f or -- directory: establishes a hard connection for a directory.-fOr -- force: forcibly establish a connection to a file or directory, regardless of whether the file or directory exists; -i or -- interactive: ask the user before overwriting an existing file. -n or --no-dereference: treats the destination directory of the symbolic link as a normal file;-sOr -- symbolic: a symbolic link to the source file, not a hard link; -s < suffix backup string > or --suffix=< suffix backup string > : use"-b"The default backup string is the symbol "~", which can be changed by using the "-s" parameter. -v or -- verbose: displays the command execution process. -v < backup mode > or --version-control=< backup mode > : After the backup file is backed up with the -b parameter, a backup string is added to the end of the backup file. This string can be changed with the -s parameter. When the -v < backup mode > parameter is used to specify different backup modes, backup strings with different tails are generated. --help: online help; --version: displays the version information.Copy the code
The diff command
Diff [parameter][file 1 or directory 1][file 2 or directory 2]
Run the diff command to compare the contents of individual files or directories. If you specify a file to compare, it is valid only if the input is a text file. Compare the similarities and differences of text files in a line-by-line manner. The diff command compares text files with the same name in both directories. Lists different binaries, common subdirectories, and files that only appear in one directory.
Common parameters:
-< line number > : Specifies how many lines of text to display. This parameter must be used with the -c or -u parameter.-aOr -- text: diff by default only compares text files line by line; -b or --ignore-space-change: does not check the difference of space characters; -b or --ignore-blank-lines: blank lines are not checked; -c: Displays all contents and marks the differences. -c < number of lines > or --context< number of lines > : same as executing the -c-< number of lines > instruction;-dOr -- minimal: uses a different algorithm, compared in small units; -d < macro name > or ifdef< macro name > : The output format of this parameter can be used for preprocessor macros;-eOr -- Ed: The output format of this parameter can be used in Ed's script file;-f-forward-ed: The output format is similar to that of Ed's script file, but different parts are displayed in the order of the original file. -h or --speed-large-files: Speeds up large files.-l< character or string > or --ignore-matching-lines< character or string > : If two files differ on certain lines, and both files contain characters or strings specified in the options, the difference between the two files is not displayed; -i or --ignore-case: does not check for case differences;-lOr -- paginate: turn the results over to a PR program for pagination; -n or -- RCS: Displays the comparison results in RCS format; -n or --new-file: When comparing directories, if file A Only exists in A certain directory, Only is displayed by defaultinDirectory, file A If -n is used, diff will compare file A with an empty file. -p: displays the function name of the difference if the comparison file is a C language program code file. -p or --unidirectional-new-file: similar to -n, but only compared to a blank file if the second directory contains a file that is not in the first directory; -q or --brief: displays only the difference without detailed information. -r or -- recursive: compares files in subdirectories;-sOr --report-identical-files: still displays information if no difference is found; -s < file > or --starting-file< file > : when comparing directories, start the comparison from the specified file; -t or --expand-tabs: Expands TAB characters on output; -t or --initial-tab: prefix each line with a TAB character for alignment; -u, -u < number of columns > or --unified=< number of columns > : displays file contents in a unified manner; -v or -- version: displays the version information. -w or --ignore-all-space: ignores all space characters. -w < width > or --width< width > : Specifies the column width when using the -y argument; -x< file name or directory > or --exclude< file name or directory > : does not compare the files or directories specified in the option; -x < file > or --exclude-from< file >; You can save the file or directory type as a text file and specify this text file in =< file >; -y or --side-by-side: shows the similarities and differences of files in a side-by-side manner; --help: displays help. --left-column: When the -y parameter is used, if the contents of a row in two files are the same, only the contents of that row are displayed in the left column. --suppress-common-lines: Displays only the differences when using the -y argument.Copy the code
CAL command
** CAL [parameter][month][year]
** Date can be used to display or set the system date and time.
Common parameters:
-l: Displays monthly output; -3: displays the calendar of the last three months.-s: Make Sunday the first day of the month; -m: Set Monday as the first day of the month; -j: Displays the Julian date. -y: Displays the calendar of the current year.Copy the code
The grep command
** Command format: **grep [option] pattern file
** Function: ** A specific character used for filtering/searching. Regular expression can be used with a variety of commands, the use is very flexible.
Common parameters:
-aDon't ignore binary data. -a < Show column number > Displays everything after the line except the one that matches the template style. -b Displays the contents of the line before the line that matches the template style. -c Calculates the number of columns that match the template style. -c < Show column number > or -< Show column number > displays the contents before and after the column except the column that matches the template style.-d< Do the action > This parameter must be used when you specify that you are looking for a directory rather than a file, otherwise the grep command will return the information and stop the action.-e< Template Style > specifies a string as the template style for finding file contents. -e uses the template style as extended plain notation, meaning that extended regular expressions can be used.-f< Template file > specifies a template file whose content has one or more template styles and tells grep to find the file content that meets the template criteria in the template style for each column. -f treats the template style as a list of fixed strings. -g uses the template style as a normal representation. -h Does not indicate the file name of the column before displaying the column that matches the template style. -h Indicates the file name of the column before displaying the column that matches the template style. -i Ignores the difference of case and case.-lLists the names of files whose contents match the specified template style. -l Lists the names of files whose content does not match the specified template style. -n Indicates the column number before displaying the column that matches the template style. -q Displays no information. -r /-r Specifies the effect of this parameter and"-dRecurse "has the same parameter.-sNo error message is displayed. -v Reverse lookup. -w Displays only the columns that match the full word. -x Displays only the columns that match all columns. -y Has the same effect as -i. -o Displays only the matched parts of the file.Copy the code
Wc command
**wc [options] file…
** Function: ** count the number of bytes, words, lines in the specified file, and display the statistical results. This command counts the number of bytes, words, and lines in a specified file. If no filename is given, it reads from standard input. The WC also gives the presidential count of the specified file.
Common parameters:
-c Indicates the number of bytes.-lCount rows. -m Indicates the number of characters. This flag cannot be used with the -c flag. -w Indicates the number of words counted. A word is defined as a string separated by whitespace, tabs, or newline characters. -l Prints the length of the longest line. -help Displays help information. --version Displays version informationCopy the code
The ps command
Command format: **ps[parameter]
** Function: ** is used to display the current process status
Common parameters:
-a: Displays programs executed at all terminals except the stage job leader. A: Display all programs under the current terminal, including those of other users. -a: Displays all programs. -c: displays THE CLS and PRI fields. C: When listing programs, display the real directive name of each program, without paths, options, or the identifier of the resident service. -c < instruction name > : Specifies the name of the instruction to execute and lists the status of the program that executes the instruction.-d: Displays all programs except those of the stage job leader.-e: The effect and specification of this option"A"The choices are the same. E: When listing programs, display the environment variables used by each program.-f: Displays UID,PPIP,C and STIME columns. F: Use ASCII characters to display the tree structure, expressing the relationship between programs. -g< group name > : Effect and specification of this option"-G"The same option can also be specified using the name of the stage job leader. G: Displays all programs under the current terminal, including those of the group leader. -g < group identifier > : Lists the status of programs that belong to this group, or can be specified using the group name. H: The header column is not displayed. -h: displays the tree structure, indicating the relationship between programs. -j or j: displays the program status in the work control format.-lOr L: use a detailed format to display the status of the program. L: List the relevant information of the field. -m or m: displays all threads. N: The USER and WCHAN fields are represented by numbers. -n: displays all programs except those in the PS command terminal. -p< program identifier > : specifies the program identifier and lists the status of the program. P < program identifier > : Effect and specification of this option"-p"The options are the same, with only minor differences in the format of the list. R: Lists only the programs that are executing on the current terminal.-s< stage job > : Specifies the program identifier for the stage job and lists the status of the programs that belong to the stage job. S: program status is displayed in the format of program signal. S: When listing programs, include interrupted subroutine data. -t< terminal number > : specifies the terminal number and lists the status of programs belonging to that terminal. T < terminal number > : effect and specification of this option"-t"The options are the same, with only minor differences in the format of the list. -t: displays all programs on the current terminal. -u< user id > : effect and specification of this option"-U"The choices are the same. U: Display the status of the application in a user-oriented format. -u < user id > : Lists the status of programs belonging to this user, which can also be specified by user name. U< user name > : Lists the status of programs belonging to this user. V: use virtual memory format to display program status. -v or V: displays the version information. -w or W: Displays program status in a broad format.   X: Display all programs, not by terminal. X: Use the old Linux I386 login format to display program health. -y: indicates the coordination option"-l"When used, the F(flag) field is not displayed and the ADDR field is replaced by RSS field   . -< program identifier > : Specifies the effect of this option"p"The choices are the same. --cols< characters per column > : Sets the maximum number of characters per column. --columns< number of characters per column > : Effect and specification of this option"--cols"The choices are the same. --cumulative: specifies the effect of this option"S"The choices are the same. -- desELECT: Effect and specification of this option"-N"The choices are the same. --forest: Effect and specification of this option"f"The choices are the same. --headers: Displays the header column repeatedly. --help: Online help. --info: Displays error information. --lines< display column number > : Sets the number of columns in the display screen. --no-headers: specifies the effect of this option"h"The options are the same, with only minor differences in the format of the list. --group< group name > : Effect and specification of this option"-G"The choices are the same. --Group< Group identifier > : Effect and specification of this option"-G"The choices are the same. -- PID < program identifier > : Effect and specification of this option"-p"The choices are the same. --rows< display column number > : Effect and specification of this option"--lines"The choices are the same. -- SID < stage job > : Effect and specification of this option"-s"The choices are the same. --tty< terminal number > : effect and specification of this option"-t"The choices are the same. --user< user name > : Effect and specification of this option"-U"The choices are the same. --User< User id > : Effect and specification of this option"-U"The choices are the same. --version: Effect and specification of this option"-V"The choices are the same. --widty< number of characters per column > : effect and specification of this option"-cols"The choices are the same.Copy the code
Watch command
**watch[parameter][command]
** Function: ** can output the command output to the standard output device, which is used to execute the command periodically or regularly
Common parameters:
-n: Indicates the interval of command execution (seconds).-d: Highlight the difference between command output information; -t: does not display the title.Copy the code
The at command
**at[parameter][time]
Features: * * * * in a specified time to perform a specified task, can only be performed once, and the need to open the atd process (ps – ef | grep atd view, open/etc/init. D/atd start or restart; Chkconfig –level 2345 ATd on)
Common parameters:
-f: Specifies the task file that contains specific instructions; -q: specifies the queue name of the new task.-l: Displays the list of tasks to be performed.-d: Deletes the specified task. -m: Sends an E-mail to the user after the task is complete.Copy the code
Crontab command
Command format:
crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
** With the crontab command, we can execute specified system commands or shell scripts at fixed intervals. The unit of time interval can be any combination of minutes, hours, days, months, weeks or more. This command is not used for periodic log analysis or data backup.
Common parameters:
-e: Edit the timer Settings for the user;-l: lists the timer Settings for the user; -r: deletes the timer Settings of the user. -u< user name > : Specifies the user name for which the timer is to be set.Copy the code
References:
A Linux command directory per day
Linux Commands
Linux Home Dish