Linux basic commands

Source: Internet
Author: User
Tags system log uuid custom name disk usage rsync

CD command
The CD is used to change the user's directory after the same as nothing will go directly to the current
The user's root directory can only be followed by a directory name, not a file name
cd– indicates the last directory in which it was located
CD ~ Indicates the user's home directory
Cd.. Back to previous level

Use the PWD command to view your current location

ls command
Ls-l Listing Details
Ls-a list all files, including hidden files
Ls-t sorted by last changed time of file
Ls-ld for the directory, s lists only the directory itself

The which command is used to find the absolute path of a command.

mkdir command
MkDir used to create a directory where the MKDIR-P option works well. Often used to create a list of directories
Mkdir-m used to specify that permissions to create a directory are not commonly used

rmdir command
Rmdir-p command can delete a large list of empty directories if the directory contains a child (not empty) directory cannot be deleted

RM command
The RM command is the most commonly used delete command Rm-r command equivalent to the RmDir RM-RF command regardless of whether the file is deleted or the directory can be

CP command
Cp-r Command Copy directory if you do not add-r to copy directory
The cp-i command security option encounters an existing file that asks whether to overwrite

MV Command
MV option source File destination file
The mv-i command asks the user whether to overwrite the same cp-i when the target file exists
The destination file is a directory, exists or does not exist, the result of the move is not the same, if present, the source file will be moved to the target file directory. If it does not exist, the destination file is a file when it is finished moving.

Cat command
The cat command is used to view the contents of a file and display the cat command without any options directly with the file name
Cat-n display the number of rows on the screen
Cat-a Show all things including special characters

TAC command
The TAC command, like the Cat command, is just a reverse display.

More commands
The more command is to view the contents of the file after the more command can be directly followed by the file name advantage is can be a screen after reading press space and then look at the next screen want to quit just to press the Q key can

Less command
The less command can be directly followed by the file name, but better than the more good can page up and down press the Space/j Key page Press K page to use shortcut keys Ctrl+b and ctrl+f respectively
Now page and PAGE DOWN press the/key to find a string down? Key up find a string by G can quickly go to the end of the text press G to quickly return to the file header press Q to exit

Head command
The head command can be followed directly with the file name to display the first 10 lines of the files plus the-n option to display the first n rows of the file

Tail command
The tail command and head are followed directly with the file name to display the last ten lines of files plus the-n option to display the last n rows of the file
Tail-f dynamically display the last ten lines of the file, such as the file is increasing, use the-f option

chmod command
The chmod command is used to change the permissions of a file or directory. Syntax: chmod [options] numeric filenames (where numbers represent nine-bit permissions see book notes)
Chmod-r representing cascading change properties

Another way to change the permissions of a directory or file
User owner referred to as U group name g other users abbreviation o all users short A
chmod u=rwx,og=rx file or directory name
chmod u-x file or directory name//reduce execution rights to the user who owns the file or directory name

The CHGRP command is used to change the user group to which the file or directory belongs
CHGRP [group name] [file name] This command is used less
The CHGRP command can also change the group to which the directory belongs, but only change the directory itself to cascade changes subdirectories and sub-files, using the following command
Chgrp-r [group name] [filename]

Chown command
Chown command to change the owner and owners of a file
Chown [-r] Account name file name or Chown [-r] Account name: Group name File name
Chown [-R] handles all files and subdirectories under the specified directory

Chattr File Hidden Properties
chattr [+-=][asaci] [file or directory name]
+–=: Increase, decrease, set, respectively
A If you add this attribute, the atime of the file or directory will not be modified;
When the attribute is added, the data is written to disk synchronously;
A adds this attribute, can only append cannot delete, the non-root user cannot set this attribute;
C Automatically compress the file, the reading will be automatically extracted;
I added, so that the file can not be deleted, renamed, set link, write, add data;
Commonly used for a and I two options.

Lsattr commands are used to read files or directories with special permissions
lsattr [-ar] [File/directory name]
-A: Similar to the-a option for LS, which is listed together with hidden files;
-R: Listed together with subdirectories ' data

SUID Special Permissions
This permission is for the binary executable, which temporarily owns the owner of the executable file when the user executes the execution file. The passwd command enables the SUID feature, so the general user will temporarily have the passwd command owner root user permission to modify the password using the passwd command so that the average user can write their own password to the/etc/shadow file

Sgid Special Permissions
The function is similar to the set UID, provided that the file is an executable binary, and when set GID is provisioned, the user who executes the file is temporarily executed as the group to which the file belongs. If the target
When this permission is set, any user who creates a file or directory in this directory has the same group as the group to which the directory belongs.

Sticky_bit Special Permissions
Whether a file can be deleted by a user depends largely on whether the directory in which the file resides is
The user has write permissions. Without write permissions, all files in this directory cannot be deleted and new files cannot be added.

For the configuration of these special permissions, the method is the same as before. For example, if I want to add a set UID permission to a file, the command
chmod u+s filename, and removing this permission is chmod u-s filename. In the same vein, setting the set GID would be
chmod g+s dirname. Set the Stick_bit permission to chmod o+t dirname.

Which find an absolute path to an executable file which [command] such as which VI

Whereis finding files (rarely used)
Whereis [-BMSU] [file name] or Whereis LS (this method is similar to fuzzy Lookup as long as the file name contains this LS character is listed.) )
-B: Only binary files are found
-M: Only files found under the manual path of the description file
-S: Only source files are found
-U: file with no documentation

Find command
find[path [parameter]
Common parameters
-atime +n/-n: Access or execute files with a time greater than/less than n days
-ctime +n/-n: Writing, changing inode properties (such as changing owner, permission, or link) files with a time greater than/less than n days
-mtime +n/-n: File with write time greater than/less than n days
Find.-name file name directly look for the file name, this selection uses a lot of

Soft connections and Hard links

A hard link is a block area directly linked to the file placement using the same inode as the source file
(1) cannot cross file system because different file systems have different inode Tadle
(2) cannot connect to directory
ln [-S] [source file] [destination file]
The options that LN uses are a-s, and if you do not add a hard link, add a soft link.

Soft Link: is to create a separate file, and the role of this file is when reading this link file,
It forwards the read behavior to the file that the file is link to.

Adding and removing user groups
Add a group: Groupadd [-G GID] GroupName
The No-G option follows the system default GID creation group as the user GID is also starting from 500
The Plus-G option customizes gid such as Groupadd-g 511 Grptest2

Delete Group: Groupdel
There is no special option, but there is one situation where you cannot delete a group, such as a User1 group that contains an User1 account, and only delete the User1 account before you can delete the group.

Adding and removing users
Added user syntax: Useradd [-u UID] [-G GID] [-D HOME] [-m] [-s]
-U Custom UID
-G to a group that already exists, followed by the group ID, or the group name
-D: Customizing the user's home directory
-M: Do not set up home directory
-S: Custom shell
Useradd without any option to directly follow the user name, a group with the same name as the user name is created. The-G option is followed by a non-existent GID error indicating that the group does not exist. -M option plus post does not create user home directory

Delete User: Userdel syntax: userdel[-r] Username
The-r option has only one function, which is to delete the account with the home directory when it is deleted.

Usermod Modifying user Properties
Usermod is to change a user-related property that already exists. Common options are as follows
-U: Change the uid of the user
-G: Change the user group, followed by the group ID, can also be followed by the group name
-D: Change the user's home directory
-S: Change the user's shell

passwd Modifying user passwords
Syntax: Passwd[username]
passwd the user name is the password to modify the current account. If you are logged in to the root account, you can follow the name of the normal account, which means to modify the password for the specified account.

Command mkpasswd to generate a password
If this command is not yum-y install expect
Specify a password length of 120 special characters three digits mkpasswd-l 12-s 0-d 3
-l Specify Password length-s Specifies the number of special characters,-d specifies the number of digits

command SU syntax [-] username can be followed by "-" or not.
Normal user Su does not add the user name is the switch to the root user "-" The role of this character is, plus will initialize the current user's various environment variables

Command DF to view the total capacity, usage capacity, remaining capacity, etc. of mounted disks. It can be displayed by default in units of K without any parameters.
DF Common options are-I,-H,-K,-M
-I view inodes usage status
-h display in the appropriate unit, e.g. G M
-K,-m display in units

The du command is used to view the amount of space a directory or file occupies, and the default display unit is K if no units are specified.
Syntax: du [-abckmsh][file or directory name]
-A All files and directory sizes are listed. If you do not add any options and parameters, only the size of the table of contents (including subdirectories) is listed.
The values listed in-B are output in bytes.
-K is output in kilobytes, and the output value is the same as the default without any option.
-M is output in megabytes.
-H System Automatic adjustment unit, for example, the file is too small may be a few k, then the unit is displayed in K, if large to a few g, it is displayed in units of G.
The-c option is the last addition, and this option is not used.
-s only lists the sum, which is used the most.

FDISK is used to partition a disk with a size less than or equal to 2T, if greater than 2T requires the parted tool
FDISK command syntax: fdisk [-l] [device name] option has only one.
-L does not follow the device name directly lists all disk devices in the system and the partition table, plus the device name lists the partition table for the device.
Fdisk enters another mode if it does not add-l, in which case the input m will list commonly used commands
Commonly used are p, N, D.
P prints the partition of the current disk.
n Create a new partition
W Save operation
Q exit
D Delete a partition
Use the n command to create a new partition that will prompt for either E (extended partition) or P (primary partition).

MKE2FS, Mkfs.ext2, Mkfs.ext3 and MKFS.EXT4
The common options are:
-B partition to set the space size per data block, currently supports 1024, 2048 and 4096 bytes per block
-I set the inode size
-N Sets the number of inode, sometimes using the default inode number is not enough, so you have to set the number of Inode
-C before formatting the disk to detect whether there is a problem, plus this option will be very slow
-L PRESETS the label of the partition label
-J create EXT3 format partition, if you use MKFS.EXT3, you don't have to add this option.
-T is used to specify what type of file system it can be ext2, ext3, or EXT4
-M format, specifies the percentage of the disk that is reserved to the administrator, and is only for the MKE2FS command

E2label commands used to view or modify partitions are rarely used, just know

Disk Mount and unload
The mount point (directory) must be an empty directory before the partition is mounted. The fact that the directory is not empty does not affect the use of the mounted partition. But
Once mounted, the previous item in the directory cannot be seen. You can only see this partition if you uninstall it.

The Mount command can view all the partitions that are currently mounted on the system, as well as the type of partition file system, mount points, and some options such as letters
Interest. If you want to know the file system type of a partition, you can view it directly with this command.
The options commonly used with the Mount command are:-A,-t,-O.

Another way to mount a load
The UUID can be used to obtain the UUID of each partition by Blkid command directly enter the Blkid command.
Of course, after this command can also specify which partition, such as BLKID/DEV/SDB5 see the book on page 171th

Chapter III LIUNX System to improve the article
Vim General mode to move the cursor
h or LEFT ARROW key cursor moves left one character
L or RIGHT ARROW key cursor move one character to the right
K or UP ARROW key cursor move up one character
J or up ARROW key cursor moves down one character
Ctrl+f or PageUp key screen move forward one page
Ctrl+b or PageDown key screen to move backward one page
The number 0 or Shift + 6 moves to the beginning of the bank
SHIFT + 4 moves to the end of bank line
GG moves to the first line
G move to Tail line
NG (n is any number) moves to nth row
Vim General mode Delete, copy and paste
X,x x Deletes one character backwards, X deletes one character forward
NX removes n characters backwards
DD Delete/Cut the line where the cursor is located
NDD (n is a number) Delete/Cut cursor is in the row up to a total of n rows
YY the copy cursor is in the row
P paste the copied or pasted content from the line where the cursor is located
P paste the copied or pasted content from the line where the cursor is located
NYY copy n rows from the line where the cursor is located
U Restore previous action
Vim command line mode find and replace
/word after the cursor looks for a string to Word, press N to continue searching
Word to the cursor before looking for a string for Word, press N to continue searching
N1,n2s/word1/word2/g find word1 between N1, N2 rows and replace with Word2, no G replaces only the first word1 of each row
1, $s/word1/word2/g replace all word1 in the document with Word2, no G replaces only the first word1 of each line
: W Save Text
: Q Quit Vim
: w! Force save, under root user even if the text is read-only can be saved
: q! Force exit, all changes are not valid
: Wq Save and exit
128
: Set NU Displays line number
: Set Nonu does not display line numbers
Compression
GZIP Syntax: gzip [-d#] filename where # is a number 1-9
-D: Use when extracting
-#: Compression level, 1 compression worst, 9 compression best, 6 default

bZIP syntax: bzip2 [-DZ] filename
BZIP2 only two options you need to master.
-D: Unzip
-Z: Compression
Can be added ' Z ' also can not add, can be compressed files

XZ Compression and decompression
XZ and gzip, bzip2 usage is the same
XZ syntax: XZ [-DZ] filename
-D: Unzip
-Z: Compression
Compression, you can add-Z or can not add, you can compress the file,-D is the decompression option

Zip and Unzip
Zip syntax zip[compressed package name [file or directory to compress]
Zip can be compressed directory can also compress files, compressed directory, you need to specify directory files such as Zip 1.txt.zip 1.txt
When using the ZIP archive directory, you must add the-r option (sub-directory compression)
Unzip decompression Unzip 1.txt.zip

A detailed description of the TAR packaging tool
Syntax: tar [-ZJXCVFPP] filename
The TAR command has several options, one of which I do not normally use to annotate.
-Z: Simultaneously with gzip compression
-j: Simultaneous compression with bzip2
-X: Unpacking or decompressing
-T: View the files inside the tar package
-C: Build a tar package or zip file package
-V: Visualize
-F: followed by the file name, compressed with the-f filename means that the compressed file name is filename, unzip with the-F file name,
It means extracting filename. Note that if you have multiple parameter combinations with-F, write-F to the last face.
-P: Use the properties of the original file to compress what properties to compress before compressing what properties. (not commonly used)
-P: Absolute path can be used. (not commonly used)
–exclude filename: Do not include the filename file when packaging or compressing. (not commonly used)

Tar package and compress and use
One of the most useful features of the tar command is the ability to compress directly when packaged, which supports gzip compression and BZIP2 compression as well as XZ.
-ZXVF is used to decompress. tar.gz Compressed Package
BZIP2 compression Packages Use the-CJVF option to compress
-TF can view a list of files for a package or a compressed package
Unzip. TAR.BZ2 's compressed package is also very simple TAR-JXVF [file or directory to unzip]
Packaging using XZ form compression is like this: TAR-CJVF [compressed package name] [file or directory to compress]
Decompression is also very simple: tar-jxvf [files or directories to unzip]

RPM Installation and uninstallation
The name of each RPM package is divided into several parts by-and. Take abrt-cli-2.0.8-15.el6.centos.i686.rpm this bag to explain a
Under ABRT-CLI is the package name, 2.0.8 is the version information, 15.el6.centos is the release version number, i686 is the running platform. Common with i386, i586, i686, only x86_64 for 64 systems
Some RPM packages do not write specific platforms but Noarch, which means that the RPM package does not have a hardware platform limit. such as alacarte-0.10.0-1.fc6.noarch.rpm
-I: Installation meaning
-V: Visualize
-H: Show installation progress
Additional parameters that are commonly used when installing an RPM package are:
–force: Force the installation, even if overwriting files belonging to other packages.
–nodeps: When the RPM package to be installed depends on other packages, install this package even if the other packages are not installed.
Upgrade a RPM Package
Command RPM-UVH filename
-U: The Meaning of the upgrade
Uninstalling an RPM package
Command RPM-E filename
The filename here is the one that is queried by the RPM query function and only needs to be the package name. such as Rpm-e Libjpeg-turbo-devel

Query whether a package is installed
Command rpm-q RPM Package name (here the package name, is not with platform information and suffix name) such as Rpm-q Libjpeg-turbo-devel

We can use RPM-QA to query all installed RPM packages of the current system, such as Rpm-qa |head (only the top 10 listed)

Get information about an installed RPM package
Command RPM-QI Package name (also does not need to add platform information and suffix name)

List A RPM package installation file
Command RPM-QL Package Name

List which rpm package a file belongs to
Absolute path to the command RPM-QF file

Yum tools in a detailed

Search for a RPM package yum search [Related keywords]
Install a RPM package yum install [-y] [RPM package name]
Without the-y option, the user will be installed in a manner that interacts with the user to see if they need to install, enter Y to install, and N does not install.
Uninstall an RPM Package command yum remove [-y] [RPM package name]
Uninstalling a RPM package must be clear, and do not even uninstall other important RPM packages, so as not to affect the normal business.
Upgrade an RPM Package command yum Update [-y] [RPM package]

Build a local Yum warehouse

Yum how to download RPM packages to local
Download an RPM package without installing the command Yum Install package name-y–downloadonly
Download to the specified directory without installing the command Yum Install package name-Y–DOWNLOADONLY–DOWNLOADDIR=/USR/LOCAL/SRC (/USR/LOCAL/SRC for the specified directory)

Chapter fourth Introduction to Shell programming
We can alias a commonly used and very long instruction by aliases a simple and easy-to-remember instruction. If you don't want to use it, you can also use Unalias to remove the alias feature.
Directly hitting alias will see the current system preset alias.
alias [command alias]=[' specific Command ']
The ENV command lists all system variables that are preset by the system.

Cut command syntax: cut-d ' delimited character ' [-CF] n here n is a positive integer
-D specify delimiters followed by single quotation marks
-F Specify paragraph
-C is followed by only one digit to intercept the first few characters, followed by a number area, indicating the interception from a few to several
such as: cat/etc/passwd |cut-d ': '-f 1|head-n5 means that the-D followed by the delimiter character, where the colon as the split character,-f1 is to intercept the first paragraph, the space between-F and 1 is optional
Sort command
Syntax: sort [-t delimiter] [-KN1,N2] [-NRU] Here's N1 < N2
-T delimiter: function with the-D one meaning of cut
-N: Sorting with pure numbers
-R: Reverse Sort
-U: To repeat
-KN1,N2: Sorted by N1 interval to N2 interval, can only write-kn1, sort N1 field
If sort does not have any options, then the first character is backward, then the ASCII values are compared, and finally they are output in ascending order.
For example: head-n5/etc/passwd |sort-t:-k3-n-T followed by a delimiter,-K followed by a number, a string is sorted on the number of areas, and-n is used to sort by a pure number

Uniq and Tee commands
The premise of using Uniq is to sort the files first, otherwise it doesn't work. Uniq is used to repeat the line, the most common option is only one:-C: Count the number of duplicate rows, and write the number of lines in front

The tee command, followed by the file name, is similar to the redirect ―>‖, but the specific weighting is more of a function, in writing the file following the text
Also appears on the screen at the same time

TR and Split commands
TR is used to replace characters, which are commonly used to handle special symbols appearing in documents, with two commonly used options:
-D: Delete a character, followed by the character you want to delete
-S: Remove repeated characters
The most common is to capitalize the lowercase:
TR ' [A-z] "[A-z] '
If it's not working for a string, you just need to know the TR, and you'll learn more about the tools you can implement for string manipulation.

Split for cutting documents, common options:
-B: Divide the document by size in bytes
If split does not specify a target file name, it will be Xaa xab ... Such a filename to access the cut file. And of course we can.
Specify the destination file name for example: [[email protected] split_dir]# split-b500 passwd 123
-L: Split document by number of rows

Connectors in the shell (and, and, or)

When used, Command2 is executed regardless of whether the Command1 is executed successfully.
With &&, only Command1 execution succeeds, Command2 executes, otherwise Command2 does not execute.
When using ‖, Command1 execution succeeds Command2 not execute, otherwise go to execute Command2, in short Command1 and Command2 always have a command will execute

2.0/2.1/2.2 grep Filter
Syntax: grep [-CINVABC] ' word ' filename
-C: Print the number of lines that meet the requirements
-N: Output with the same number of lines as required
-V: Print rows that do not meet the requirements
-A: followed by a number (with or without spaces), for example, –A2 to print the line that meets the requirements and the following two lines
-B: followed by a number, such as –B2, to print the line that meets the requirements and the above two lines
-C: followed by a number, such as –C2, to print the line that meets the requirements and two rows above and below
-R: All files under the directory are traversed
–color: Identify the matching keywords in red

awk command
There are three ways of calling Awk
1. Command-line mode
awk [-F field-separator] ' commands ' input-file (s)
Where commands is the true awk command, [-F domain delimiter] is optional. Input-file (s) is the file to be processed.
In awk, each line in a file, separated by a domain delimiter, is called a domain. In general, the default field delimiter is a space without naming the-F domain delimiter.

Example: Awk-f ': ' {print '} ' 1.txt

2.shell Script Mode
Insert all the awk commands into a file and make the awk program executable, and then awk command interpreter as the first line of the script, again by typing the script name to invoke.
Equivalent to the first line of the shell script: #!/bin/sh
Can be replaced by: #!/bin/awk

3. Insert all the awk commands into a separate file and then invoke:
Awk-f awk-script-file Input-file (s)
Where the-f option loads the awk script in Awk-script-file, Input-file (s) is the same as above.

Daily operation and maintenance management of Linux system
View System load command w see book 206

Vmstat detailed
The results of the Vmstat command print are divided into 6 parts: procs, memory, swap, IO, system, CPU.
(1) procs display process-related information
R: Indicates the number of processes running and waiting for CPU time slices. If it is longer than the number of server CPUs, then the CPU is not enough.
B: Indicates the number of processes waiting for the resource. For example, waiting for I/O, memory, and so on, if the value of this column for a long time greater than 1, you need to pay attention.
(2) Memory-related information
SWPD: Indicates the amount of memory switched to the swap partition
Free: The amount of memory currently idle
Buff: Buffer size (about to be written to disk)
Cache: Buffer size (read from disk)
(3) Swap memory exchange situation
Si: The amount of data written to memory by the swap area
So: The amount of data written to the swap area by memory
(4) IO disk usage
BI: The amount of data read from a block device (read disk)
Bo: The amount of data written from a block device (write disk)
(5) System shows the number of interrupts occurring during the acquisition interval
In: Indicates the number of device interrupts per second observed at a certain time interval
CS: Indicates the number of context switches produced per second
(6) CPU Display CPU usage status
US: Shows the percentage of CPU time that is spent under the user
Sy: Displays the percentage of CPU time that the system spends
ID: Percentage of time that the CPU is idle
WA: Indicates the percentage of CPU time consumed by I/O waits
ST: Represents the percentage of stolen CPUs (typically 0, no concern)
In each of the parameters described above, I often focus on r columns, column B and WA columns
The IO part of BI and Bo is also an object to refer to frequently. If the disk IO pressure is large, the values of these two columns will be higher.
The values of the SI and so two columns are high, and when changing, the memory is not enough and the data in memory is frequently exchanged in the swap partition, which often has a great impact on the system performance.

Vmstat Viewing System Status
Vmstat 1 5 indicates output once every second, output 5 times
Vmstat 1 means that the state is output once every 1 seconds and output, unless we press Ctrl + C to end

Top command
The top command is characterized by putting the highest processes that occupy system resources (CPU, memory, disk IO, etc.) to the front
The top command prints a lot of information, including system load (Loadaverage), Number of processes (Tasks), CPU usage, memory usage, and swap partition usage.
Use the top command to focus on how the process uses system resource details. There are several items to focus on:%cpu,%MEM, command%cpu CPU usage%MEM to use memory rate COMMAND
Top state, press SHIFT + M to sort by memory usage size. Press the number 1 to list the usage status of each CPU.
The command TOP-BN1 represents non-dynamic print system resource usage, which can be used in shell scripts

Netstat viewing ports
NETSTAT-LNP (print which ports the current system launches) and Netstat-an (Print network connectivity)

Grab Bag tool tcpdump and Tshark

Iptables detailed
Iptables is just an implementation tool for firewalls (netfilter).

Command crontab
The operation of the Linux Task Scheduler function is done through the crontab command. The common options are:
-U: Specifies a user, without the-u option, for the current user
-e: Make a scheduled task
-L: List Scheduled Tasks
-R: Delete Scheduled Tasks
Crontab-l command to view scheduled tasks
Crontab-r command to delete a scheduled task
For example:
3 echo "OK" >/root/cron.log
From left to right, in order: minute, time, day, month, week, command line. Meaning: On June 5 (This day must be Week 3) 10:01 execute command echo "OK" >/root/cron.log

Crontab-e actually opens the file/var/spool/cron/username (if Root is/var/spool/cron/root). Using the Vim editor, it is possible to make an error, so be sure to use CRONTAB-E to edit it.

Linux logs
Log format:
Log generated by Auth–pam
Verification information for login information such as Authpriv–ssh,ftp
cron– Time Task related
kern– kernel
lpr– Printing
mail– Mail
Mark (syslog) –rsyslog service internal information, time identification
news– News Group
user– related information generated by the user program
Uucp–unix to UNIX copy, related communication between UNIX hosts
Local 1~7– custom log device
Log level:
debug– with modal information, most log information
info– General Information log, most commonly used
notice– information on the most important general conditions
warning– Warning Level
err– error level, information that prevents a feature or module from working correctly
crit– critical level that prevents the entire system or the entire software from working properly information
alert– information that needs to be modified immediately
emerg– critical information such as kernel crashes
None – don't record anything.
From top to bottom, the level is low to high, and the information recorded is getting less
Connection symbols
. : represents information greater than or equal to the xxx level
. =: Represents information equal to XXX level
.! : Indicates the level of information outside of XXX

The/var/log/messages core System log file is the core log file of the Linux system, and if a service does not have a log defined, the log generated by the service will be in this file. The log is archived once a week.

Xargs and exec detailed
Xargs applications
Its function is to use the output from the front of the pipe as input to the command following the Xargs. The advantage of this is that it can be done in a single step or two or more steps to complete the task. Xargs is often used with the Find command
If you find a file with the current directory creation time greater than 10 days, then delete it. Find. -mtime +10 |xargs RM
[[email protected] test]# ls *.txt |xargs-n1-i{} mv {} {}_bak
[[email protected] test]# ls
1.txt_bak 2.txt_bak 3.txt_bak 4.txt_bak 5.txt_bak
xargs-n1–i{} resembles a For loop,-n1 means an object to be disposed of,-i{} replaces the preceding object with {}, MV {}
{}_bak is equivalent to MV 1.txt 1.txt_bak.

EXEC app
[[email protected] test]# find. -mtime +10-exec rm-rf {} \;

The command also replaces {} as a file in the previous find, followed by the caret, or the shell will make a semicolon
Is the end of the line command. This-exec is sometimes very useful, it can also be implemented just above the need to change the file name in bulk

URL command
The URL is a tool for simple testing of Web Access under the Linux system command line, with a few common options you need to master
-X can specify IP and port, omit write hosts, convenient and practical
-I can drop the contents of the access, only show the status code,-V can show the detailed process
-u can specify user name and password
-O (uppercase) direct download page or object can also use the-O custom name

rsync format
The command format for rsync is as follows:
rsync [OPTION] ... SRC DEST
rsync [OPTION] ... SRC [[Email protected]]host:dest
rsync [OPTION] ... [[email protected]] HOST:SRC DEST
rsync [OPTION] ... [[email protected]] HOST::SRC DEST
rsync [OPTION] ... SRC [[Email protected]]host::D EST
Rsync-av 123.txt/tmp/
The above example shows that the current directory 123.txt synchronization to the/tmp/directory, you can change the name of the target file, Rsync-av123.txt/tmp/234.txt
If it is a remote copy, this is the form: ip:path (e.g., 10.0.2.34:/root/)

Rsync Common Options
-a archive mode, which means that files are transferred recursively, and all properties are maintained, equivalent to the-RLPTGOD,-A option followed by a
–no-option This means that one of the-rlptgod is closed, for example-a–no-l is equivalent to-rptgod

-R subdirectories are processed recursively, primarily for directories, if a single file is not required to add-r, but the transmitted
Yes directory must be plus-r option
-V Print some information, such as rate, number of files, etc.
-L reserved Soft link
-L treats the soft link as a regular file, and if there is a soft connection file in SRC, the soft connection will be referred to as
Copy the target file to DST
-P Maintain file permissions
-O Keep File owner information
-G hold File group information
-D Keep Device file information
-T hold file time information
–delete Delete those files that are not in the DST SRC

The usual options pages are just a few: (-a-v–delete
–exclude), memorize.


This article is from the "Sen Wang" blog, make sure to keep this source http://zhibeiwang.blog.51cto.com/7555525/1788788

Linux basic commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.