Linux system Maintenance Common commands

Source: Internet
Author: User
Tags rsync

Network command:
# ifconfig# Display network information, including IP address, packet receive/send status
# ifconfig eth0 up# start eth0
# vi/etc/sysconfig/network-scripts/ifcfg-eth0 # change eth0 configuration file
# iwconfig # show wireless network information
# sudo/etc/init.d/network Restart | Start | stop# Restart Network | start Network | STOP network

# Service Network start| Service Networking restart# Ibid.
#/etc/network/interfaces# manually configure network files
# IFUP interface# Enable network interface
# Ifdown interface# Disable Network interface
# wget http://xxx.com/xx.tar.gz # download
# route-n# Lists the kernel IP routing table to address related issues
# sudo dhclient# get the IP address from the DHCP server
# sudo dhclient-r# get the IP address from the specified network interface
# cat/etc/resolv.conf# View DNS Server
# iwlist scan# shows wireless network conditions in the area
# lshw-c network# Display network card and network device driver information (need to run with Administrator privileges)

Other common commands:
# cat# Connect the file string to the basic output (screen)
# more# similar to Cat, will be a page-by-page display,<space> next page,<b> previous,
# grep# find the strings that match the criteria in the file, and if they are included, display that column
# TAR-ZXPF xx.tar.gz# Decompression
# hostname | cat/etc/sysconfig/network# Viewing host names

# lspci-nn# Displays the PCI vendor and device code connected to the PCI bus in digital and hardware name mode
# lsusb# Display USB device
# lshw-c usb# display additional information on USB-related hardware (for USB dongle)

# yum install xx# Yum installation command
# Yum List Installed | Wc-l | rpm-qa# View all installed packages

# chkconfig--list # list all system services
# grep on# Lists all system services that are started
# service XX (services) Restart | Stop | start# Restart | stop | start XX service

# echo $LANG $LANGUAGE | cat/etc/sysconfig/i18n# viewing the system default language

Hard Drive Mount:
# mount-t hard Drive type hard drive mount point
(Hard disk Type: Fat is msdos,fat32, then VFAT,NTFS is NTFS)
# fdisk-l# View hard drives and all use cases
# mkdir/mnt/win_disk# set up a mount point in the/mnt directory
# mount-t ntfs/dev/sda6/mnt/win_disk# Mount Sda6 to/mnt/win_disk
# unmount/mnt/win_disk# unmount the hard drive
# mount-t iso9660/dev/cdrom/mnt/cdrom# Mount Disc
# mount/dev/fd0/mnt/floppy# Mount floppy disk

Common Command categories:

system

# Uname-a | Uname-r # View kernel/Os/cpu information
# lsb_release-a # View System version information
# head-n 1/etc/issue # view OS version
# Cat/proc/cpuinfo | More/proc/cpuinfo | grep "model name" # View CPU Information
# hostname # View computer name
# LSPCI-TV # list all PCI devices
# LSUSB-TV # list all USB devices
# lsmod # List of loaded kernel modules
# env # View Environment variables
# getconf Long_bit # View CPU bits (+ or 64)
# More/etc/redhat-release | cat/etc/redhat-release# viewing the current Linux version information
# passwd # Modify User password
# Reboot | Ctrl+alt+del | Init 6# Restart
# shutdown-h Now | Halt | Init 0# shutdown

Resources

# free-m # View memory usage and swap area usage
# df-h # View the usage of each partition
# du-sh < directory name > # View the size of the specified directory
# grep Memtotal/proc/meminfo # View Total Memory
# grep Memfree/proc/meminfo # View the amount of free memory
# uptime # View System uptime, number of users, load
# cat/proc/loadavg # View System load
# pwd # View your directory
# ls-l # show directory file list (-A: Show hidden)

disks and partitions

# Mount | COLUMN-T # Viewing the status of a mounted partition
# Fdisk-l | Df-h # View all partitions
# swapon-s # View all swap partitions
# hdparm-i/dev/hda # View disk parameters (for IDE devices only)
# DMESG | grep IDE # View IDE device detection status at startup

Network

# ifconfig # View the properties of all network interfaces
# iptables-l # View firewall settings
# route-n # View the routing table
# netstat-lntp # View all listening ports
# NETSTAT-ANTP # View all established connections
# netstat-s # View Network statistics
# cat/etc/sysconfig/network# View Gateway
# cat/etc/resolv.conf # View DNS

process

# ps-ef # View All Processes
# top # Real-time display of process status
# PS-AUXW # list the current process ID
# kill XX Process ID # terminates a single process
# Killall Program Name # All processes terminating a program
# xkill # Terminate X-window program

User

# w # View active Users
# ID < user name > # view specified user information
# last # View user log in log
# cut-d:-f1/etc/passwd # View All users of the system
# cut-d:-f1/etc/group # View all system groups
# crontab-l # View Current user's scheduled tasks
# startx # start X Desktop
# Switchdesk gnome| kde|. # switch Desktop

Service

# chkconfig--list # list all system services
# chkconfig--list | grep on # Lists all startup system services

Program

# Rpm-qa | Wc-l # View all installed Packages
# Yum List installed # ditto
# cat-n/root/install.log# to view packages installed during system installation
# More/root/install.log # ditto
#/.configure # Configuration
# make # Compile
# Make install # Install

1 、--df–hp No matter how long the file system name is, it will not wrap the output, which is useful when writing monitoring disk utilization
Df–hp-p,--portability Use the POSIX output format
2 、--Filter yesterday and today's error log in/var/log/messages
Cat/var/log/messages | Grep-ie ' Warning | Panic | Error | Exception | Fail ' | grep "$ (date | awk ' {print $ "" $ $} ') ">> $FILENAME
Cat/var/log/messages | Grep-ie ' Warning | Panic | Error | Exception | Fail ' | grep "$ (date-d yesterday | awk ' {print $ "" $ $} ') ">> $FILENAME
3 、--sort sorted by field,-T followed by delimiter,-K N (n represents number) sorted according to column,-n sorts string numbers
Sort-t ': '-K 3-n/etc/passwd//The UID of the/etc/passwd file is sorted from small to large, as follows:
station90.example.com# sort-n-T ":"-K 3/etc/passwd | Head-n 3
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/bin/bash
Daemon:x:2:2:daemon:/sbin:/bin/bash
4 、--BC Math operations
station90.example.com# echo "SCALE=3;1/5" | BC//Precision to several decimal points, need to add Scale,scale default value is 0
.200
station90.example.com# echo "1.2*8" | Bc
9.6
[[email protected] ~]# bc-q//-q--quiet don ' t print initial banner
3*4
12
3/4
0
Scale=5
3/4
.75000
[Email protected] ~]# var1=2
[Email protected] ~]# echo "scale=5; $var 1/3" | BC//BC Support Variables
.66666

[Email protected] ~]# var1=3
[Email protected] ~]# var2=$ (echo "scale=3; $var 1/3" | BC)
[Email protected] ~]# echo $var 2
1.000
5 、--Take out the data in column 2nd of the second row NR remove data from the first row
[Email protected]/1211> cat 1.txt
1 4
2 5
3 6
[Email protected]/1211> awk ' nr==2 {print $} ' 1.txt
5

Perform df–h every 2s
Watch–n 2 "Df–h"
LS–LTRH user-friendly display output
RM * Delete File error, can delete file by the following way
Find./-type F >/tmp/0110.txt
For a in $ (cat/tmp/0110.txt);d o rm $a;d one
In the tar command, the parameter-files-from is useful, such as:
Unzip the tar in a specific number of files, while using the-C to specify the decompression path,--files-from the file after 0110.txt storage to extract the file name, can be fuzzy matching
TAR-ZXVF xxxxx.tar.gz-c xxxx/--files-from 0110.txt
--files-from is also very useful when compressing files, such as:
Retention of files under the current path for 10 days and 10 days, other deletions
Find./-type f–name "emcm*" –mtime +10 >/tmp/0110.txt
TAR–ZCVPF Xxxxx.tar.gz–files-from/tmp/0110.txt
For a in $ (cat/tmp/0110.txt);d o rm $a;d one
5. Split split file and composite file
Split-b 70m xxx.tar.gz Xxx.tar.gz_
For network reasons, the export file is divided into 70M, after you have downloaded all the files, execute the following command to synthesize the file:
Cat Xxx.tar.gz_aa xxx.tar.gz_ab Xxx.tar.gz_ac xxx.tar.gz_ad > xxx.tar.gz
If you need to synthesize on windows, if you download the file to D, execute the following command:
C:\users\administrator>d:
D:\>copy/b "Xxx.tar.gz_aa" + "Xxx.tar.gz_ab" + "Xxx.tar.gz_ac" + "Xxx.tar.gz_ad" xxx.tar.gz
6. See how many file handles are opened by the process, and take the top 3
[Email protected] ~]# Lsof-n | awk ' {print $} ' | Sort| uniq-c | Sort-nr | Head-n 3
128 6618
58 9945
55 9883
7. Change the operating system user password in bulk
CHPASSWD < 1.txt
Cat 1.txt
Test1:$%uk83re
test2:$ #rK8e78
Test3:#&rh9e3r
8, when colleagues are doing some operations, may lead to storage problems, as long as you can create files on the storage, then the storage is OK, this time the job is to go to multiple servers occasionally to create files, simple repetition but very tired, write the following script instead:
Script function: If unable to create the file then make a sound alarm echo $ ' \a '
#!/bin/bash
For i in {1..10000}
Do
Sleep 3
echo "Xxxxxxxxxxxxxxxxxxxxx" > Lhf_$i.txt
If [$?-eq 0];then
echo "OK"
Else
echo "Failure"
echo $ ' \a '
Fi
Done
9, the TAC looked backward text, such as to see the latest message log is very convenient
Tac/var/log/message | Less
10. grep parameter-a,-b,-c
-A 1 take the following line of the current row and the filtered values
-B 1 Take the previous line of the current row and the filtered values
-C 1 Take the current row and the top and bottom rows of the filtered values
station90.example.com:~/1205 # Cat Grep.txt
1
2
3
4
5
6
station90.example.com:~/1205 # cat Grep.txt | Grep-b 1 4//Fetch the current row and the previous row of the filtered values
3
4
station90.example.com:~/1205 # cat Grep.txt | GREP-A 1 4//Fetch the current row and the following row of filtered values
4
5
station90.example.com:~/1205 # cat Grep.txt | GREP-C 1 4//Fetch the current row and the top and bottom rows of the filtered values
3
4
5
11. Grep–l–r Parameters
Search contains keyword keyword files,-l lists only the file names that contain the keywords,-r recursion
Grep-l-r keyword./
12. grep parameter –x–w
Cat 1.txt | Grep–x 192.168.1.1 matches the row, only the line is 192.168.1.1
Cat 1.txt | Grep–w 192.168.1.1 match the phrase, as long as this line has 192.168.1.1 is matching
13, Grep–f followed by the file name, such as:
Cat 1.txt | Grep–f 2.txt 2.txt each row in the content will be matched in 1.txt, if there is a match in the 1.txt file, then the 1.txt file will display the match, if the 2.txt and 1.txt files are large, it is very performance-consuming
14. Change the UID of the user and the GID of the group
Usermod–u UID User name
Groupmod–g GID Group Name
15. Sed usage
1, SED to replace the number before the 86 to empty
Sed-i ' s/^86//g ' 1.txt
2. Insert the 115th line above the text into the xxxxx
Sed-i "115i\xxxxx" 1.txt
3. Add "At the beginning and replace the space with \+ space
Sed-i-E "s/^/\"/g "-e" s/$/\ "/g"-e "s//\\\/g" mdsp_filepath.txt
4, step to write, then:
Sed-i "s/^/\"/g "1.txt
Sed-i "s//\\\/g" 1.txt
5. At the end of the file content, add "
Sed-i "s/$/\"/g "1.txt
16. Xargs Usage
1. Batch Rename file
ls | Xargs-i mv {} {}.bak
2, in the file, query the information of the keyword
Find. -name ' *. CDR ' |xargs grep ' keyword '
17. Awk Usage
AWK–F Specifies the delimiter, the default delimiter is a space, such as
With | As a delimiter, take the nineth column
Awk-f ' | ' ' {print $9} ' 1.txt
18, batch take the absolute path of the file dirname, the file name must have no space
station90.example.com~ # Cat 1.txt
/etc/ataev100r002c03spc200/sles10sp2_x64.properties
/etc/ataev100r002c03spc200/1206/task.properties
/etc/dir_colors
station90.example.com:~ # for I in $ (cat 1.txt);d o dirname $i;d One
/etc/ataev100r002c03spc200
/etc/ataev100r002c03spc200/1206
/etc
19, Batch take the file name basename
station90.example.com~# for I in $ (cat 1.txt);d o basename $i;d One
Sles10sp2_x64.properties
Task.properties
Dir_colors
Netcontrol_global_hooks
20. Rsync Transfer File
Rsync–avh–n–delete./[Email protected]:/home/oracle/
-N does not really transmit, just a test
-A shows recursive transfer of files and maintains all file attributes
--delete if the remote file and the transferred directory file are different, delete (use cautiously)

Linux system Maintenance Common commands

Related Article

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.