Red Hat Linux Common Operations Command (derived from the network summary in a piece
1. How to use the command (three ways)
Shutdown--help
Shutdown--?
Man shutdown (man is Manual Handbook, guide)
2. Services Service
How do you know the name of the service? Use this command to Chkconfig:
Chkconfig--list will list all the service items
Start a service, such as a service that starts MySQL
Service MySQL start not all the commands have this d this letter
Service iptables Stop shutting down the firewall
Service VSFTPD start VSFTP server
Service VSFTPD Stop Service stopped
Service VSFTPD Restart Restart
3. Boot from boot
You don't have to start mysql,vsftp,apache manually, and so on.
With Chkconfig This command, check configure checks the configuration
Chkconfig--list | More
Chkconfig--list | grep MySQL
Chkconfig--list | grep vsftpd
Chkconfig MySQL on these several 3 4 5 levels all started
Chkconfig--level 3 MySQL on just starting at 3 this level
Chkconfig MySQL off
MySQL database service--------------MySQL
Vsftp Server service------------VSFTPD
Firewall service------------iptables
SSH service------------sshd
HTTP------------------httpd
4. Modify the system default boot level
When modifying that profile, first back up
Modify the configuration file/etc/inittab, change the number in Id:5:initdefault 5 to 3
3 Pure command line interface, with network sharing
5 graphical interface
The next time the system starts, it's not going to get into that graphical interface.
5. View hardware Information
UNAME-A # View kernel/Os/cpu information
Head-n 1/etc/issue # View OS version
Cat/proc/cpuinfo # Viewing 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 variable resources
Free-m # View memory usage and swap area usage
Df-h # Viewing the usage of each partition
Du-sh # Viewing the size of a specified directory
grep memtotal/proc/meminfo # View Total Memory
grep Memfree/proc/meminfo # Viewing the amount of free memory
Uptime # View System uptime, number of users, load
CAT/PROC/LOADAVG # Viewing system load disks and partitions
Mount | COLUMN-T # Viewing the status of a mounted partition
Fdisk-l # 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 network at startup
Ifconfig # View the properties of all network interfaces
Iptables-l # View firewall settings
Route-n # Viewing the routing table
NETSTAT-LNTP # View All listening ports
NETSTAT-ANTP # View all established connections
Netstat-s # Viewing the network statistics process
PS-EF # View All Processes
Top # Real-time display of process status users
W # View Active Users
ID # 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 the current user's scheduled tasks service
Chkconfig–list # List all system services
Chkconfig–list | grep on # Lists all started system services programs
RPM-QA # View all installed Packages
Cat/proc/cpuinfo: View CPU-related parameters
Cat/proc/partitions: Viewing hard disks and partitions
Cat/proc/meminfo: Viewing memory information
Cat/proc/version: View version, similar to Uname-r
Cat/proc/ioports: Viewing device I/O ports
Cat/proc/interrupts: Viewing interrupts
CAT/PROC/PCI: Viewing information for PCI devices
Cat/proc/swaps: View information for all swap partitions
6. View the System log
/var/log
/VAR/LOG/DMESG/Core Boot log
/var/log/messages/System error log
/var/log/maillog/mail System log
/VAR/LOG/XFERLOG/FTP Service Log
/var/log/secure/Security information System login and network connection
/VAR/LOG/WTWP/Login Record
Tail-f/var/log/messages/View recent information.
7. System Switch Machine
To switch the Virtual Workbench:
ALT key and a function key to implement, usually using F1-F6.
When the user logs in, click the "Alt+f2" button, the user can see the "Login:" prompt appears above, indicating that the user saw the second Virtual Console. You can go back to the first Virtual console simply by pressing the "ALT + F1" key.
A newly installed Linux system allows users to use "ALT+F1" to "Alt+f6" keys to access the first six virtual consoles.
The most useful thing about virtual consoles is that when a program fails to cause a system deadlock, you can switch to another virtual Console to work and close the program.
Turn off the computer
Shutdown-h-T 30 30 seconds to safely power off the machine
Shutdown-c Canceling shutdown command execution
Restart the computer reboot
Exit command Line Exit
8. Switch the operating level
The run level is the functional level that the operating system is currently running.
This level is from 1 to 6 and has different functions. These levels are specified in the/etc/inittab file. This file is the main file that the INIT program looks for, and the first service to run is those files that are placed in the/ETC/RC.D directory.
In most Linux distributions, the startup script is located in/etc/rc.d/init.d. These scripts are connected to the/ETC/RC.D/RCN.D directory by the LN command. (n here is the run level 0-6) For example/etc/rc.d/rc2.d the following s10network is connected to the network script under/ETC/RC.D/INIT.D.
The beginning of the file s for start is the start service meaning, the following number 10 is the order of the boot. For example, in the same directory, you can also see s80postfix this file, 80 is the order after 10, because there is no network startup, start Postfix is not any effect. In addition,/ETC/RC.D/RC2.D can also see those files that begin with K, such as/etc/rc.d/rc2.d/k45named,k for Kill, which means to stop the service.
The standard Linux run level is 3 or 5, and if it is 3, the system is in multi-user state. If it is 5, it is running X Window.
The different run-level definitions are as follows:
(You can refer to the/etc/inittab in Red Hat Linux)
0-Downtime
1-Single user mode
2-multi-user, but no NFS
3-Full multi-user mode
4-No Use
5-x11
6-Reboot (never set Initdefault to 6)
A detailed explanation of the individual run levels:
0 for downtime, the machine shuts down.
1 is single-user mode.
2 is multi-user mode, but there is no NFS support.
3 is the full multi-user mode and is the standard run level.
4 generally not, in some special cases you can use it to do something.
5 is X11, into the X Window system.
6 Restart, the init 6 machine will restart.
9. Package Management
Installing RPM Packages
RPM-IVH package.rpm
Upgrade RPM Package
RPM-UVH package.rpm
Uninstalling RPM Packages
Rpm-ev Package
Query the list of files included in the RPM package
RPM-QLP Package
Query the list of files included in the RPM package
RPM-QLP Package
Query the content information contained in the RPM package
RPM-QIP Package
Querying all installed RPM packages in the system
Rpm-qa
10. User Management
Who: Querying users who are currently online
Groups: Querying the group to which the user belongs
ID: Displays current user information
Finger: Querying user information
Add a new user Useradd username
change User Password passwd username
Change user home directory usermod-d/home/username username
Usermod-e "2009-01-01" username set the password expiration time for the user
Usermod-g root (group) Username (user) Add a user to a group
USERMOD-G root username change user's GID
Usermod-s/bin/csh username Changing the user's default shell
Usermod-u 504 Username Change the UID of the user to 504
Usermod-l username Lock the user, the user cannot log on to the Linux system after locking
Usermod-u username Unlocking user
Passwd-s username to see if the user is locked
Userdel User name only deletes user registration information
Userdel-r User name Delete home directories and messages belonging to the user
11. Storage Management
View the new hard drive # Fdisk-l
Create PV # Pvcreate/dev/sdb
Create VG # vgcreate DATAVG/DEV/SDB/DEV/SDC
Note: When you create a volume group using Vgcreate, you can also specify the size of the PE, which needs to be implemented with the-s parameter, the PE size range is 8 KB to 16GB, and must always be a multiple of 2. A maximum of 65,534 PE in a volume group is allowed to exist. The default PE size is 4 MB, which means that all logical volumes created on the volume group are scaled up or down in increments of 4 MB, so a 4 MB PE determines the maximum capacity of a single logical volume to be up to three GB, and a larger PE is required to create a larger logical volume when creating a volume group.
Create LV # lvcreate-l 180m-n lvdata01 Datavg
Note: When you use the remaining space to create a logical volume, you should first view the remaining space for the current volume group through the "Vgdisplay" command.
When creating a logical volume, you can also specify the mode of logical block and physical block mapping, with the following two types of logical volume mapping modes:
Linear mode-maps a range of physical blocks to logical blocks in order, which is the default mapping method. For example, map 1-25 of Le in a logical volume to PV1, and 26-50 of Le to PV2.
Stripe mode-the logical block is mapped to a different physical volume in the form of a stripe, which is somewhat similar to the previous RAID 0, which improves the performance of the logical volume reading and writing. For example, the Pe1,le 2 mapping for the logical volume of LE 1 to PV1 is mapped to PV3 PE1 for PV2 Pe1,le 3.
Lvcreate-i 3-i 4-l 180m-n lvtest1 vgtest
The parameters are described as follows:
-I: Creates a logical volume with a stripe-mode mapping that specifies that the logical volume being created will be mapped on several PV.
-I: Specifies the size of the block used in stripe mode, in kilobytes, whose value must be: 2N (n≥2).
-L: Specifies the size of the logical volume to be created, in units of K, M, G, T for KB, MB, GB, and TB.
-N: Used to specify the name of the logical volume that is created, which can be defined casually as needed.
-L: The amount of PE used to specify the logical volume, which is calculated as the default of 4MB total capacity.
When using the "-i" parameter to specify the number of PV, it is important to confirm that the specified PV is not fully allocated to any logical volume, otherwise the creation will fail, second, if the size of these PV is unequal, then the logical volume created can only take the minimum value.
Creating a file system
Mkfs.ext3/dev/datavg/lvdata01
Mount File System
Mkdir/data01
Mount/dev/datavg/lvdata01/data01
Manually activating volume group # vgchange-a y Datavg
Manually go to activate volume Group # vgchange-a N datavg
Note: If the volume group is not activated, volume groups and logical volumes cannot be accessed, and volume groups created in LVM 2 are activated by default.
Add a new physical volume to a volume group
When the volume group is running out of space, you can add a new physical volume to expand the volume group capacity, which is achieved by using the "vgextend" command.
Vgextend DATAVG/DEV/SDE
Remove a physical volume
To remove a physical volume from a volume group, first verify that the physical volume to be removed is not being used by any logical volume, and the "pvdisplay" command allows you to view the physical volume information as follows:
Pvdisplay/dev/sde
---physical volume---
PV NAME/DEV/SDE
VG Name Vgtest
PV Size 100.00 mb/not usable 0
Allocatable Yes
PE Size (KByte) 4096
Total PE 25
Free PE 25
Allocated PE 0
PV UUID Ee2ifc-uhuq-xg67-icwt-ahdj-7krz-jddjiq
If the "Total PE" is equal to "free PE", it indicates that the physical volume is not being used, and if a physical volume is being used by a logical volume, it is necessary to transfer the data of that physical volume elsewhere and then remove it. The command to remove the physical volume is "vgreduce".
Vgreduce DATAVG/DEV/SDE
Transferring data between physical volumes
When a disk under a logical volume is found to be faulty, or if there are other requirements to transfer data from the physical volume (for example, to replace a large or higher-speed physical device), the transfer of data between physical volumes can be achieved through "Pvmove".
Modprobe Dm-mirror
You need to use the "modprobe dm-mirror" command to load the Dm-mirror module before using "Pvmove", because "pvmove" needs to use the module when transferring data, and the default system does not load the module. # PVMOVE/DEV/SDD/DEV/SDE
Extending logical Volumes
Lvextend-l +300M/DEV/DATAVG/LVDATA01 on the original basis, increase the size of 300MB space
Lvextend-l 300M/DEV/DATAVG/LVDATA01 expansion to 300MB space size
Logical volume expansion does not take effect immediately, you need to use the "resize2fs" command to reload the size of the logical volume, the command only for EXT2/EXT3 file system (if the ReiserFS file system, then use the "resize_reiserfs" command), If the logical volume is in use, the logical volume should be unloaded before executing the "RESIZE2FS" command.
Umount LVDATA01
Resize2fs/dev/datavg/lvdata01
MOUNT/DEV/DATAVG/LVDATA01 LVDATA01
Note: These actions can be implemented directly through the "ext2online" command, so that you do not have to unload the logical volume and so on.
Ext2online/dev/datavg/lvdata01
Delete a logical Volume: you first need to uninstall the logical volume before you execute the following command:
Lvremove/dev/datavg/lvdata01
Remove a volume group: Before removing a volume group, you must first confirm that there are no logical volumes in the volume group, or you can manually stop the volume group by using "Vgchange", and remove the volume group as follows: # Vgremove Datavg
Delete Physical Volume: Before deleting a physical volume, verify that the physical volume has been removed from the volume group.
Pvremove/dev/sde
12. Network Configuration
Network configuration tools such as System-config-network-tui (text mode), System-config-network-gui (image mode), Netconfig (text mode) can be used. These tools will directly modify the Linux system on the network interface settings file, which is not comparable to the Ifconfig command, where Redhat-config-network and system-config-network tools is not only to set the network card tool, More set up ISDN and ordinary cat, ADSL tools, network hardware additions, host name settings, DNS client settings and so on. For example:
/usr/sbin/system-config-network-tui
/usr/sbin/system-config-network-gui
The Netconfig tool is a better tool in text mode.
netconfig-d eth0/Setup Eth0
netconfig-d eth1/Setup Eth1
Set the DHCP mode of the network card to obtain IP automatically
netconfig-d eth0--bootproto=dhcp
Manually set the IP of the NIC, etc.
Netconfig-d eth0-ip=192.168.1.33-netmask=255.255.255.0-gateway=192.168.1.1
(1) Configure the IP address of the eth0 and activate the device at the same time.
#ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
(2) Configure the IP address of the eth0 alias device eth0:1 and add the route.
#ifconfig eth0:1 192.168.1.3
#route add–host 192.168.1.3 Dev eth0:1
(3) Activate the device. #ifconfig eth0:1 up
(4) Disable the device. #ifconfig Eth0:down
(5) View the configuration of the specified network interface. #ifconfig eth0
(6) View all the network interface configuration. #ifconfig
(7) Check the connection status of the network interface: # Ethtool eth0
(1) The route added to the host.
#route add–host 192.168.1.2 Dev eth0:0
#route add–host 10.20.30.148 GW 10.20.30.40
(2) Routes added to the network.
#route add–net 10.20.30.40 netmask 255.255.255.248 eth0
#route add–net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41
#route add–net 192.168.1.0/24 eth1
(3) Add a default gateway. #route Add default GW 192.168.1.1
(4) View the configuration of the kernel routing table.
#route
(5) Delete the route.
#route del–host 192.168.1.2 Dev eth0:0
#route del–host 10.20.30.148 GW 10.20.30.40
#route del–net 10.20.30.40 netmask 255.255.255.248 eth0
#route del–net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41
#route del–net 192.168.1.0/24 eth1
#route del default GW 192.168.1.1
For 1 and 22 points can be implemented using the following statement:
Ifconfig eth0 172.16.19.71 netmask 255.255.255.0
Route 0.0.0.0 GW 172.16.19.254
Service Network Restart
(1) Display the network interface status information. #netstat –i
(2) Displays the socket of all monitored servers and the program information that is using the socket. #netstat –lpe
(3) Displays the kernel routing table information.
#netstat –r
#netstat –NR
(4) Displays the connection status of the TCP/UDP transport protocol.
#netstat –t
#netstat –u
Hostname Changing host names
#hostname Myhost
13. Clear the screen
Clear is the clear screen, Windows is CLS
14. List the contents of the file
Cat TAC Head Tail more
Cat 3.txt positive sequence starts from the first line
TAC 3.txt Reverse from the countdown to the first line
Head 3.txt
Head-3 3.txt List Top 3 rows
Head can take parameter-lines
Tail Tail-1 3.txt last line
More 3.txt------The default is to be paged, so a lot of plumbing used him
ls horizontal display, this line is full of the next line
Ls-l a row displays only one file or directory details
Ls-m Horizontal row, this line is full of the next line
Ls-r a little like a tree show.
15.cp+move
CP copy copy MV move mobile
CP 1 2 Copy 1 of this file, named 2.
Cp-r d1 D2 Copy directory must have parameter R
Delete a directory and delete the contents of the directory first. To use recursion, the copy is also
MV D2 D1 Move D2 directory to D1, if not, add recursion mv–r
16. Change the name MV
In addition to the MV can be moved outside, but also can change the name
Mv 3.txt 4.txt Change the name of 3.txt to 4.txt
17.whoami
Displays the current user, root or other user
18. Press 5 to ESC
Press 5 to ESC and there will be a lot of commands to use
Display all 2091 possiblities, or Redhat Linux, has more than 2000 commands.
19.mount Mount + Uninstall
Mount point mount Points
MOUNT/DEV/CDROM/MNT/CDR the CDROM device in the Dev directory with
The CDR directory under the MNT directory under the root directory is associated with this is the Mount
mount point------CDR device-----CDROM
Uninstall Umount/dev/cdrom or UMOUNT/MNT/CDR
20.VI is important
Vi: Command mode and edit mode, just start to enter the command mode, cannot enter content.
Hit a into the edit mode, the bottom will appear insert this word append append
Tap ESC to exit Edit mode and enter command mode
In command mode, knock the colon: and then kill the W is disk
Q is to exit q! is not to save the WQ is to save the exit (most commonly used)
Wq is to save out W is not write meaning
21.find
Find the name of a file (provided you remember the approximate name) and find its path path. You can find rc.local based on creation date.
Find/-name
local from the root directory to find, specify a location, from there to start checking
Find/etc-nameLocal
find/etc | grep Local System go back to find all the files or directories that contain the local letters
Find/-name MySQL system just go back to the file or directory named MySQL.
Find/-name MySQL
Find the first few letters are MySQL (any later) files or directories, the name does not have to write the full
22.whereis
Whereis ls find ls where is this command
/bin bin directory below are various commands VI cat LS pwd and so on
There are also various commands under the/usr/bin directory
23. View Environment variables
See Environment variables under DOS
Echo%path%
Echo%classpath%
Under Linux echo $PATH PATH must be capitalized
24. Link Ln
ln 3.txt 4 More 4
Link: Changed the content of 3.txt,4 will automatically follow, if you have not modified 4
ln 3.txt 4 A hard link, which is equivalent to copying a copy, and then creating a shortcut between the two files, and modifying the 3.txt,4 will also change
Ln-s 3.txt 5 Soft connection, equivalent to Windows shortcut, modify 3.txt,5 also change
The differences between the two types of links:
The 3.txt is deleted, 5 does not exist, the connection is broken, and 4 is still present.
25.WC (Word count)
Wc-l lines How many lines are there in this file?
26.grep
Global Regular Expressions Print Universal Regular expression version
Finds the specified string in a text file and displays the included line, grep student 4
In 4 This text file to find student this string, which line contains it, displayed
^ in regular expressions, represents the beginning of a line
Ls-l | grep ' ^d ' only lists the directories,/etc files and directories are many
^ This character is above the number 6
Rpm–qa to list all the bags,
Rpm-qa | grep MySQL finds all the packages that contain the words MySQL, as long as the package name contains MySQL letters, it will be found
27.grep and find
Find/-name MySQL
Find/| grep MySQL
Fdisk-l l Display the current disk information
28.dmesg
List boot information for power on the full name is------D message
DMESG | grep eth0 See the first NIC booting up normal?
29. Command Replacement Wall
Warning all notify everyone and warn everyone
Wall HelloWorld
Wall
date
The warning character is the current time, and the date is treated as a command, warning the result of the command execution (' this character is the number 1 left character)
Wall Date warning character is date
30. Redirection
Java's original program, to replace out.
SYSTEM.OUT.PRINTLN () output the command to the file
Ls
ls > Cmd.txt Input the results of the command just executed by LS into the Cmd.txt file.
Error output redirection---------
Lssss > Cmd.txt No, lsss, this command doesn't exist.
Lssss 2> Cmd.txt
REDIRECT Input wall < Cmd.txt to warn the contents of cmd.txt.
31. Piping
page display,/etc a lot of content below
Ls-r
Ls-r | More give the result of the last command to the next command
Ls-l/etc | More
More The default is to be paged, but the ls-l will not be paged, sometimes the content of the display is huge, with more will result. Wouldn't it be nice to split the pages?
Ls-l | grep ' ^d ' only lists the directories,/etc files and directories are many
32. File Permissions Files Privilege
A total of 10 people on the left
- (on behalf of the file) d (for directory) L (yes L for link)
The leftmost one is removed, leaving 9 of them, which can be divided into 3 groups.
The permissions for Linux files are divided into 4 types---------
Read Write Execute none (Nothing)
9 bits are divided into 3 groups:
The first group represents what permissions the owner of this file has
The second set of permissions that are owned by the same group as the owner of the file
The third group represents what the rest of the people have right
X--------------Execute
R-------------Read
W---------------Write
- It means nothing, none.
33.chmod-not Professional
Change mode
chmod +x 4 to 4 This file plus executable permissions, the other two groups also have
Chmod-x 4 Canceling permissions
chmod u+x 4 Add only the executable permission to the first group, plus the permissions
How to get this permission for other people in the same group:
chmod g+x 4 Add permission group to the second group only
chmod o+x 4 Add permissions to the third group
chmod 755 4
chmod 777 4
7 means that the permissions are all 5 means no write permission
Representation of permissions within Linux (Unix), represented by 3 octal numbers
000 =====0 111 ======7
34. How to modify the owner of a file
Chown TestUser1 4-------------Change owner
35. Management of simple users
When a user logs in, the default path is the user's home directory
36. Add users (two ways)
Useradd testuser
AddUser testuser
37. Set the password
passwd testuser to set a password for this user
The BACKSPACE key is not valid because the password does not appear
38. Two position changes
After adding a user, the system has two locations that change:/home,/etc
Cd/home ls #home目录会有一个自动生成的目录, called TestUser
CD/ETC more passwd open passwd this file
passwd This file does not have a password, it is saved by all users Testuser:x:501:502::/home/testuser:/bin/bash
This User ID number---501 in the group: 502
The user's home directory is----/home/testuser
The shell--------used by this user/bin/bash
User Group------------------------------------------------
The group's information is/etc/group in this file
Adding a user who does not specify a group will add a group that is the same as your user name
39. Add a group
Groupadd TESTG
Useradd testuser2-g Testg Specify a group when adding users
Modify user-owned group Usermod-g testuser testuser2 New Group user name
Usermod---------User Modify
40. Delete Users and Groups
Delete users in two steps---Delete the user deleted his directory
Userdel TestUser
Cd/home
RM-RF TestUser
Group deletion Groupdel Testg
41. User Switching
Switch User
Su TestUser2
42.Shell
There is a layer outside the kernel, called Shell,shell, that will explain the commands you hit under Linux and then deal with the kernel. The shell has different forms, there are different shell,c shell-------the C language form of the shell, different shell executes the command is not the same, the same command under different shell can not be common, common commands, can be common.
We use the shell called Bash, formerly known as BSH, the origin of the name, is a person called bone, wrote, so called BSH, then he wrote again, Bone again shell, so called bash.
BASH------Switch to bash
CSH---switch to C shell
Ksh-----switch to K shell
The most primitive and primitive shell of SH
BSH------Switch to BSH
Linux Common Operations Commands