Linux basic commands
Linux system version query command
1. # uname-a (view the current operating system kernel information of Linux version)
2. # cat /proc/version (Linux view current operating system version information)
3. # cat /etc/issue or cat / etc / RedHat release
4. # cat /proc/cpuinfo (Linux views cpu related information, including model, dominant frequency, kernel information, etc.)
5,# getconf LONG_BIT (number of bits of Linux version)
6,# lsb_release -a (LSB needs to be installed for CentOS version 6.9, and it can be used directly above CentOS version 7.0. It is said that Linux supports it on the Internet, and I have only verified the CentOS system)
Centos shutdown and restart commands
Linux centos restart command
reboot shutdown -r now #Restart now (for root) shutdown -r 10 #Automatic restart after 10 minutes (used by root user) shutdown -r 20:35 #Restart at 20:35 (used by root)
If the restart is set through the shutdown command, you can cancel the restart with the shutdown -c command
Linux centos shutdown command
halt #Turn it off immediately poweroff #Turn it off immediately shutdown -h now #Shut down now (for root) shutdown -h 10 #Automatic shutdown after 10 minutes
halt - the simplest shutdown command
In fact, halt calls shutdown -h. When halt is executed, the application process is killed and the sync system is executed. After the file system write operation is completed, the kernel will be stopped.
Parameter Description:
- [- n] prevent sync system calls. It is used after repairing the root partition with fsck to prevent the kernel from overwriting the repaired superblock with the old version of superblock.
- [- w] is not a real restart or shutdown, but a wtmp [/ var/log/wtmp] record is written.
- [- d] do not write wtmp record [included in option [- n]].
- [- f] forced shutdown or restart without calling shutdown.
- [- i] turn off all network interfaces before shutting down [or restarting].
- [- p] this option is the default. Is to call poweroff when shutdown.
Centos7 network configuration
1. View network card information
#ifconfig checks the network card information, mainly to see the name of the network card, whether there is an IP address, MAC code, etc.
ifconfig #View network card information ip addr #View network card information
Enter one of the above two commands to view network information
2. Configure network card information
vi /etc/sysconfig/network-scripts/ifcfg-ens33
Minimum configuration for Internet access (required)
TYPE=Ethernet #Set the network card type, "Ethernet" indicates Ethernet DEVICE=ens33 #Set the name of the network card ONBOOT=yes #Set whether the network card is activated when the Linux operating system starts BOOTPROTO=static #Set the configuration mode of the network card. "Static" means to use the static IP address, "dhcp" means to obtain the address dynamically IPADDR=192.168.80.3 #Set the IP address of the network card NETMASK=255.255.255.0 #Set the subnet mask of the network card GATEWAY=192.168.80.2 #Set the default gateway address of the network card DNS1=192.168.80.2 #Set the IP address of the DNS server
If the machine does not need to access the external network, it only needs the internal network. Then remove DNS and GATEWAY
Analysis of network card configuration file
TYPE=Ethernet #Network card type: Ethernet BOOTPROTO=static #IP protocol, static or dynamic DEFROUTE=yes #Default route: Yes, if you don't understand, you can use Baidu keyword 'default route'` IPV4_FAILURE_FATAL=no #Yes, do not enable IPV4 fatal error detection: no IPV6INIT=yes #Whether IPV6 is automatically initialized: Yes [no impact, IPV6 is not used yet] IPV6_AUTOCONF=yes #Whether IPV6 is automatically configured: Yes [no impact, IPV6 is not used yet] IPV6_DEFROUTE=yes #Whether IPV6 can be the default route: Yes [no impact, IPV6 is not used yet] IPV6_FAILURE_FATAL=no #Yes do not enable IPV6 fatal error detection: no NAME=ens33 #Network card physical device name UUID=9e8d604f-d991-4aa2-88a3-4c679e6f139c # Universal unique identification code, cannot be repeated DEVICE=ens33 #The network card device NAME must be the same as the 'NAME' value ONBOOT=yes #Start or not PEERDNS=yes PEERROUTES=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes HWADDR=00:0c:29:ce:3f:3c #MAC address IPADDR=192.168.1.104 #Static IP GATEWAY=192.168.1.2 #Default gateway NETMASK=255.255.255.0 #Subnet mask DNS1=114.114.114.114 #DNS configuration
3. Restart the network card
systemctl restart network #centos7 service network restart #centos6
Operation of directory
1. Directory switching
cd / #Switch to the root directory cd ~ #Switch to user and directory cd ../ #Switch to the previous directory cd - #Switch to the last accessed directory cd etc #Switch to the etc directory under the current directory ./ #Represents the current directory
example:
cd The command is used to switch directories,The format is: cd /catalogue cd /home #Enter the home directory
2. Add directory mkdir command
Used to create a blank directory
Command format: mkdir [option] catalogue
In addition to creating a single blank directory, you can also use the - p parameter to recursively create file directories with nested and cascading relationships.
mkdir test #test names the directory for itself
-
- -m --mode = mode, set permission < mode > (similar to chmod), instead of rwxrwxrwx minus umask
- -p --parents create directory recursively
- -v. -- verbose displays information every time a new directory is created
- – help displays this help message and exits
- – version outputs version information and exits
example:
mkdir abc #Create abc empty directory directly mkdir -m 755 pc #Change the permissions of the pc directory mkdir -p test/test1 #Create test and test1 without error
3. View directory ls
-a view all directories under the current directory and hide directories
-l view the details of all directories in the current directory, abbreviated as ll
4. Search directory
find command
find /root -name *test*
5. Modify / move directory mv command
mv xxx.txt aaa.txt Explanation: xxx Old directory name, aaa New directory name mv You can also modify the names of files and compressed packages mv yyy.txt /root #yyy needs to move the directory/ Where root cuts to
6. Copy directory and file cp command
cp -r aaa / #Copy the aaa directory to the root directory cp tt.zip / #Put TT Zip to the root directory
7. Delete directory
rm #Delete file rm-r #Delete directory rm-rf #Forcibly delete the directory (you can use this sentence to delete anything, just use this sentence)
In Linux, mkdir is used to create a directory. There are commands to create a directory. Naturally, there are commands to delete a directory. The command to delete a directory is rmdir.
rmdir command
Command format: rmdir [option] catalogue
- -p can be deleted recursively, but non empty directories cannot be deleted
- -v displays the deletion process
rmdir cannot delete a non empty directory
For example:
[root@balich~]# rmdir 222 rmdir: failed to delete '222': directory is not empty
rm command
The rm command is used to delete a file or directory.
Command format: rm [option] name
- -i confirmation is required before deletion
- -f force deletion, ignore nonexistent files, and do not prompt for confirmation
- -r/-R recursively deletes directories and their contents
- -I require confirmation before deleting more than three files or recursive deletion
- -v if you want to rm display the details when the current operation is completed
File packaging and compression
- Packaging: turn a large number of files or directories into a total file [tar command]
- Compression: transform a large file into a small file through some compression algorithms [gzip, bzip2, etc.]
Many compression programs in Linux can only compress one file, so when you want to compress a large number of files, you have to pack the large number of files into a package (tar command), and then compress them with the compression program (gzip bzip2 command).
The most commonly used packaging program under Linux is tar. The package printed by tar program is often called tar package. The commands of tar package file are usually based on Tar terminated. After the tar package is generated, it can be compressed by other programs.
1. Packaging and unpacking of files
tar command
It is used to compress and decompress files. tar itself does not have compression function, which is realized by calling compression function.
Command format
tar [required parameters] [select parameters] [file / directory]
Necessary parameters
- -A add a compressed file to an existing compressed file
- -B set block size
- -c create a new compressed file
- -d) differences in documentation
- -r add files to compressed files
- -u add changed and existing files to existing compressed files
- -x extract files from compressed files
- -Tdisplays the contents of the compressed file
- -gzip unzip files are supported
- -j supports bzip2 decompression files
- -Z supports de compress files
- -v display operation process
- -l file system boundary settings
- -k keep the original file without overwriting
- -m reserved files are not overwritten
- -W confirm the correctness of the compressed file
Optional parameters
- -b set the number of blocks
- -C switch to the specified directory
- -f specifies the compressed file
- – help displays help information
- – version displays version information
Practical examples:
pack
tar -cvf FileName.tar DirName
Note: tar is packaged, not compressed
Unpack
tar -xvf FileName.tar
Description: x extracts the file from the compressed file, v displays the operation process, and f specifies the compressed file
Compression and decompression
#Package the / temp / directory directly and compress it into ". tar.gz" format, - z to identify the format, - c to package, - v to display the process progress, - f to specify the compressed file
tar -zcvf tmp.tar.gz /tmp/
#Decompress and unpack ". tar.gz" format, - z to identify the format, - x to unpack, - v to display the process progress, - f to specify the compressed file
tar -zxvf tmp.tar.gz
Package and compress to ". tar.bz2" format. Pay attention to the file name of the compressed package
tar -jcvf tmp.tar.bz2 /tmp/
Decompress and unpack ". tar.bz2" format
tar -jxvf tmp.tar.bz2
File operation
1. New file
touch test.txt
Under Linux, you can not add the suffix of the file. Adding the file name is for developers to distinguish the file
2. View file
cat,more,less,tail
cat use cat You can easily view smaller files. use cat View the last screen of the file directly displayed more use more Check the file, press enter, turn one line, turn one page in the space, Q End viewing, only viewing down less use less Can use more Can be viewed in the same way, but you can use pg up ,pg down Turn up and down tail use tail View the last few lines of the file tail -10 xxx.txt View the last 10 lines of the file tail -f xxx.txt Dynamic monitoring file crtl+ c sign out
3. Modify file
vim ./sys.txt #Edit sys. In the current directory txt
vim can also create new files
4. Delete file
rm -rf xxx.txt