Because Linux is getting longer and longer, and more things are required, efficiency has become the bottleneck that I must break through. I would like to summarize some of the good Linux skills used during this period. In the future, it will be very convenient to use it as needed.
[Management and network]
1. lsof usage is incomplete
Lsof abc.txt displays the process of enabling the file abc.txt
Lsof-I: 22. Know what programs are running on port 22.
Lsof-c nsd displays the files currently opened by the nsd Process
Lsof-g gid: displays the processes that belong to the gid.
Lsof + d/usr/local/display files opened by processes in the directory
Lsof + D/usr/local /.
Lsof-d 4 displays processes with fd 4
Lsof-I [I] is used to display qualified Processes
Syntax: lsof-I [46] [protocol] [@ hostname | hostaddr] [: service | port]
46 --> IPv4 or IPv6
Protocol --> TCP or UDP
Hostname --> Internet host name
Hostaddr --> IPv4 location
Service --> service name in/etc/service (more than one can be entered)
Port --> port number (more than one)
Example: TCP: 25-TCP and port 25
@ 1.2.3.4-Internet IPv4 host address 1.2.3.4
The tcp@ohaha.ks.edu.tw: ftp-TCP protocol host: ohaha.ks.edu.tw service name: ftp
Lsof-n does not convert the IP address to the hostname. By default, the-n parameter is not added.
Example: lsof-I tcp@ohaha.ks.edu.tw: ftp-n
Lsof-p 12: check which files are opened by the process with process number 12.
2. grep does not display its own processes
# Ps-aux | grep httpd | grep-v grep
Grep-v grep can cancel displaying the grep process you are executing. The-v parameter does not display the name of the listed process.
3. view the local IP Address
Ifconfig | grep "inet" | cut-c 0-36 | sed-e's/[a-zA-Z:] // G'
Hostname-I
4. Check the number of active Httpd processes.
#! /Bin/sh
While (true)
Do
Pstree | grep "* \ [httpd \] $" | sed's /. *-\ ([0-9] [0-9] * \) \ * \ [httpd \] $/\ 1 /'
Sleep 3
Done
Other processes can also be referenced.
5. Set the com1 port to allow the Super Terminal to log on through the com1 port.
Step 1: Confirm/sbin/agetty, edit/etc/inittab, and add
7: 2345: respawn:/sbin/agetty/dev/ttyS0 9600
9600bps is because this rate is generally used by default when a router is connected.
19200, 38400, 57600, 115200
Step 2: Modify/etc/securetty and add a line: ttyS0 to ensure that the root user can log on.
Step 3: restart the machine. You can unplug the mouse, keyboard, and display. You 'd better check the output information .)
6. Search for or delete a process that is using a file
Fuser filename
Fuser-k filename
7. Know the hardware address of a machine in the network, and how to know the IP address of the machine
In Linux, if you want to check the IP address corresponding to a hardware address such as "00: 0A: EB: 27: 17: B9 ",
Run the following command:
# Cat/proc/net/arp | grep 00: 0A: EB: 27: 17: B9
192.168.2.54 0x1 0x6 00: 0A: EB: 27: 17: B9 * eth2
In addition, you can use the "arp-a" command to query:
# Arp-a | grep 00: 0A: EB: 27: 17: B9
192.168.2.54) at 00: 0A: EB: 27: 17: B9 [ether] on eth2
8. How to bind IP addresses and hardware addresses in Linux
You can edit an address file, which records the relationship between the IP address and the hardware address, and then execute "arp-
F address corresponds to the file ". If no corresponding file address is specified, the default file/etc/ethers is usually used.
The format of the file corresponding to the address is as follows:
192.168.0.1 00: 0D: 61: 27: 58: 93
192.168.0.2 00: 40: F4: 2A: 2E: 5C
192.168.0.3 00: 0A: EB: 5E: BA: 8E
9. Change the Mixed Mode of eth0Mixed Mode can listen to information of other hosts)
Change the network adapter eth0 to the hybrid mode:
Ifconfig eth0 promisc
Disable the hybrid mode:
Ifconfig eth0-promisc
10. linux commands for clearing arp tables
# Arp-d-a (applicable to bsd)
For HOST in 'Arp | sed '/Address/d' | awk' {print $1} ''; do arp-d $ HOST; done
11. How to obtain the MAC address of the NIC
Arp-a | awk '{print $4 }'
Ifconfig eth0 | head-1 | awk '{print $5 }'
12. bind multiple ip addresses to a network card
Method 1. Create an eth0: 1 file with a colon and a number added to the NIC.
Cp/etc/sysconfig/network-scripts/eth0/etc/sysconfig/network-scripts/eth0: 1
Modify eth0: 1.
Method 2,
Create a file under/etc/sysconfig/network-scripts/: ifcfg-ethX-rangeX "X" indicates the NIC number)
File Content:
IPADDR_START =
IPADDR_END =
CLONENUM = 0
There can be 256 ip addresses
13. How to bind an ip address to two NICs
Suppose 192.168.0.88 is an ip address and 192.168.0.1 is a gateway:
/Sbin/modprobe bonding miimon = 100 mode = 1
/Sbin/ifdown eth0
/Sbin/ifdown eth1
/Sbin/ifconfig bond0 192.168.0.88
/Sbin/ifenslave bond0 eth0 eth1
/Sbin/route add default gw 192.168.0.1
14. Set ssh to disable automatic disconnection
Modify the. bash_profile file in the HOME directory, and add
Export TMOUT = 1000000 (in seconds)
Then run source. bash_profile
15. mount directories shared by other windows machines on the LAN
Mount-t smbfs-o username = guest, password = guest // machine/path/mnt/cdrom
16. Send a message to all users logging on to the same server.
1) enter wall and press Enter.
2) enter the message to be sent
3) Press "Control-d" at the end. The message is displayed in the user Control window.
17. send messages to all users on the remote machine
Use the rwall (Remote writing to everyone) command to send messages to all users in the network at the same time.
Rwall hostname file
When using window systems such as CDE or OpenWindows, each window is considered as a single login;
If the number of user logins exceeds one, the message is sent directly to the control window.
18. send messages to all users in the Network
All users who send messages to the network
1) Enter rwall-n netgroup and press Enter.
2) enter the message to be sent
3) Press "Control-d" at the end. The message is displayed in the Control window of each user in the system. below is the system administrator.
Example of sending a message to each user in the Network Group Eng:
% Rwall-n EngSystem will be rebooted at 11: 00. (Control-d)
%
Message in the user control window: Broadcast message from root on console... System will be rebooted
11: 00. EOF
Note: You can also run the rwall hostname command to access all users in the system.
19. output the top result to the file.
Top-d 2-n 3-B> test.txt
You can print the top result three times every 2 seconds, so that the process on the back page can also see
20. The solution to installing a dual system cannot be seen in another System
First, start the CD, enter rescue mode, run GRUB, enter grub prompt grub>, and then tap
Statement, Just restart.
Root (hd0, 2), setup (hd0)
21. compress the transmission file or directory
Transfer to remote: tar czf-www | ssh server "tar zxf -"
Compressed to remote: tar czf-www | ssh server "cat> www.tar.gz"
Decompress the package to the remote: ssh server "tar zxf-" <www.tar.gz
Decompress the package to the local machine: ssh server "cat www.tar.gz" | tar zxf-
22. Send emails with attachments under the command line
Method 1. uuencode | mail-s "title" mail @ address
The local file name must be used as the attachment file name.
The file name of the attachment in the email, which can be the same as the actual content.
Method 2. cat | mutt-s "title"-a mail @ address
Body of the email.
The local file name must be used as the attachment file name.
23. One command kills multiple processes
Sometimes, if a service is stopped and the process cannot be stopped, Kill it. However, many programs run many processes at the same time. It is too troublesome to delete ps-aux | grep names one by one. You can use the killall command. For example, apache processes can use the killall httpd command to delete some processes. If a zombie process exists, 6th entries can be used for processing.
24. Tips on Kill commands
Kill-hup pid reload Process
Kill-term pid ends the process
Kill-KILL PID
-HUP can be replaced by a number (-1 ).
-TERM can be replaced by numbers-15
-KILL can be replaced by a number (-9 ).
25. Several tips on cd commands
The cd command is one of the two commands with the highest usage in Linux)
Cd-# Go Back To The Last directory. I didn't know this technique. It seems to be useful and I have omitted a lot of input.
Cd! $ # Input the parameters of the previous command. This is also common in other commands and must be used to simplify a lot of work)
Cd # return to the home directory
Cd ~ # Return to the home directory
Cd .. # Go back to the upper-level directory
Cd.../../# return to the parent directory
[Mysql maintenance]
1. Where is the mysql DATA inventory?
1) if the rpm package is used for installation, the directory name of the database should be in the/var/lib/mysql directory.
2) If the source code is installed in/usr/local/mysql, use the database name as the directory name in/usr/local/mysql/var.
2. export and import data from mysql
Export Database
Mysqldump Database Name> file name
Import Database
Mysqladmin create database name
Mysql database name <file name
3. What should I do if I forget the root password of mysql?
# Service mysql stop
# Mysqld_safe -- skip-grant-tables &
# Mysqladmin-u user password 'newpassword''
# Mysqladmin flush-privileges
4. If mysqld is up, but cannot log on, the error "/var/lib/mysql. sock" does not exist.
In most cases, because your mysql is installed in rpm mode, it will automatically find
/Var/lib/mysql. sock file,
Log on to mysql through a unix socket.
Common solutions:
1) Create/modify the file/etc/my. cnf and add/modify at least one line
[Mysql]
[Client]
Socket =/tmp/mysql. sock
# Write the correct location of your mysql. sock Here, usually either under/tmp/or under/var/lib/mysql/
2) specify an IP address and connect to mysql using tcp instead of local sock.
# Mysql-h127.0.0.1-uuser-ppassword
3) Add a connection for mysql. sock. For example, if the actual mysql. sock is under/tmp /,
# Ln-s/tmp/mysql. sock/var/lib/mysql. sock
5. Several common data export Methods
1) Use mysqldump
# Mysqldump-uuser-ppassword-B database -- tables table1 -- tables table2>
Dump_data_20051206. SQL
Detailed Parameters
2) backup to Syntax
Mysql> backup table tbl_name [, tbl_name...] TO '/path/to/backup/directory ';
For more information, see the mysql manual.
3) mysqlhotcopy
# Mysqlhotcopy db_name [/path/to/new_directory]
Or
# Mysqlhotcopy db_name_1... db_name_n/path/to/new_directory
Or
# Mysqlhotcopy db_name./regex/
For more information, see the mysql manual.
4) select into outfile
For more information, see the mysql manual.
5) Client Command Line
# Mysql-uuser-ppassword-e "SQL statements" database> result.txt
Among the above methods, mysqldump is the most commonly used
6. How to execute SQL statements on the command line
# Mysql-uuser-ppassword-e "SQL statements" database
7. Common Methods for importing backup files
1) files dumped by mysqldump
# Mysql-uuser-ppassword [database] <dump. SQL
2) the file type is the same as above. Use the source syntax.
Mysql> source/path_to_file/dump. SQL;
3) text files or csv files stored in a certain format
# Mysqlimport [options] database file1 [file2....]
For more information, see the mysql manual.
4) the file type is the same as the preceding one. You can also use the load data syntax to import the file.
For more information, see the mysql manual.
Related Articles]
- Newbie School: A Collection of practical Linux operating system skills (Part 1)
- New school: a wonderful collection of practical skills for Linux operating systems (II)