FAQs about Linux

Source: Internet
Author: User

FAQs about Linux

(1) Press ~ Start the service process in z sequence.

# ExportLC_ALL = C # English environment variable settings, mainly used to solve the garbled Problem

# Chkconfig-list | grep [z-a]: | grepon $ sort

(2) display all services with a running level of 5.

# Chkconfig-list | grep 5: on | sort

(3) how to stop a (such as cups) service.

# Chkconfig cups off;/etc/init. d/cups stop

(4) how to change the configuration of the/etc/profile file to take effect immediately.

# Source/etc/profile and "/etc/profile" are followed by spaces.

(5) How to Use the find tool to find your cgweb files within 30 days and back up and archive them.

# Find/-user cgweb-ctime-30-exec tar azvf/home/backup/cgweb-new-files.tgz {}\;

(6) how to convert partition table information into files.

# Fdisk-l/dev/sda>/etc/config-data/sda-fdisk.txt # Note: Create the config-data DIRECTORY first

How to back up a hard disk partition table and MBR to a file:

# Dd if =/dev/sda of =/etc/config-data/sda-boot.img bs = 512 count = 1

(7) How to improve TCP/IP stack security.

There is usually a way to prevent SYNFlood attacks through "# echo1>/proc/sys/net/ipv4/tcp_syncookied", which is not safe, the reliable method is to send to/etc/sysctl. in the conf file, add the following code to/etc/sysctl. conf:

Net. ipv4.tcp _ syncookies = 1

Net. ipv4.ip _ default_ttl = 61

Net. ipv4.conf. all. accept_redirects = 0

Net. ipv4.conf. all. send_redirects = 0

If there are many machines, you can store the configuration file on the FTP server (for example, sysctl-add, Server IP Address: 10.10.10.1) and extract it from FTP, append to the existing/etc/sysctl. end of the conf file:

Wge tftp: // 10.10.10.1/pub/sysctl-add

Catsystl-add>/etc/sysctl. conf

(8) how to find and delete all RPM files under the/var directory.

# Find/var-name "*. rpm"-exec rm {}\;

(9) how to use SSH to create a directory (upload) on a remote host (10.10.10.1) and upload files.

# Ssh root@10.10.10.1 mkdir/var/www/html/upload

# Scp *. cfg root@10.10.10.1:/var/www/html/upload/

(10) How to Use the find command to find all files in a folder containing all specified keywords.

For example, you need to find all the files that contain the JAVA_OPTS keyword in the/etc/tomcat5 directory:

# Find/etc/tomcat5-name "*" | xargs grep "JAVA_OPTS"

(11) copy/etc/passwd and/etc/shadows on the old system to the new system. Can I continue to use them.

Do not copy the original/etc/apsswd on the new machine. Many services may conflict between the new and old systems. If the system is installed on the same disk, verify that the system's crypt/hash functions are the same (that is, the passwords are encrypted using the same algorithm ), do not copy the entire/etc/configuration file in the configuration file of the new system.

(12) how to view the log file information in real time (for example, DNS and DHCP debugging problems ).

# Tail-f/var/log/messages # If the-f option is not used, the tail in the default state can only list the last 10 lines of files.

(13) How to find all the files in the/etc/directory, including the "ip_forward" string, and print it to the screen.

# Find/etc/-exec grep "ip_forward" '{}' \;-print

(14) how to search for files larger than 1 GB in the current system (often used to eliminate disk space faults ).

# Find/-size + 1024000 k-exec du-H' {} '\;-print

(15) how to back up a tape drive on a remote server remotely.

# Tar cvf-/home/etc | ssh root@10.101.10.1 "cat>/mnt/backup/remoteserver 1 _ $
(Date00000000y-0000m-0000d0000.tar"

SSH is no longer familiar to administrators. How can I use it to transmit standard output (stdout) from a Linux server to a backup server over the network? The preceding command is used. Note that there is a space after date.

(16) after logging on to the system as a general cgweb user, how can I create a directory in a location that the root user can access.

# Su -- c "mkdir/root/cgwebtmp"

(17) How to show only the top processes.

If only several processes are displayed, enter the PID of the process to be viewed in the top:

# Top-p 4300-p4500

(18) how to view the system calls that occurred during the execution of a command.

# Strace/bin/ping 10.10.10.12>/tmp/ping_out

In this line of command, by running the ping command in the strace command and directing the standard error to the/tmp/ping_out file, many messages will be sent to the ping_out file. If you want to check where ping obtains its information, you will find all the open locations to check which files it opened:

# Grep ^ open/tmp/ping. out

In addition, you can also let it track sub-processes, for example, to track open system calls in the preceding example:

# Strace-e trace = open/bin/ping 10.10.10.1

In addition to opening the database, the ping command also opens the configuration file resolv. conf to find the IP address and find out where it resolves the domain name to the IP address.

(19) how to determine the performance of X server.

After the video card driver is installed, run the following command to check the performance of the Xserver server Server:

# X11perf-repeat 3-reps 10-subs 10 100-circulate

In the preceding example, the X11perf command runs a set of Windows from bottom to bottom. The circulate action repeats three times. The first group has 10 windows and runs 10 times respectively (100 in total). The second group has 100 windows, it still runs for 10 cycles (1000 cycles in total ). At the end of each group, the total number of repetitions and the time taken to complete the entire set of actions are displayed.

You can also use the following command to test the performance:

# X11perf-repeat 2-reps 1000-ftext

Send 1000 texts containing 80 characters to the display (-ftext ):

# X11perf-repeat2-reps 500-copywinwin 500

Copy a 500x500 square pixel block from one window to another (-copywinwin500 ):

# X11perf-repeat2-reps 800-scroll 500

Vertically scroll 500x500 square pixel frames 800 times.

(20) view the installed GPG key.

# Rpm-qa gpg-pubkey *

Gpg-pubkey-0dfb3188-41ed929b

The gpg-pubkey-0dfb3188-41ed929b represents the common key used by RedHat to sign the software package. If you want to obtain information about such a public key, you can continue to use the RPM command:

# Rpm-qi gpg-pubkey-0dfb3188-41ed929b | less

In the output Summary code line, the key is displayed as applicable to openjavasiseserver, and q is entered to exit.

(21) How to check the signature information of the package.

Run the following command to check if the RPM is damaged and modified:

# Rpm-check sig-vv fedora-logos-1.2.-1. noarch. rpm

(22) install the virtual machine under Xen.

# Virt-install-nvm-mysql-r512-f/vm/vm-mysql.img-s10 -- nographics-p-lftp: // ip/pub/iso

With the simple code above, you can install the virtual machine under Xen.

(23) view the current number of TCP connections.

In addition to common netstat-na | more commands, you can use the following command to accurately count the number of connections:

# Netstat-n | awk '/^ tcp/{++ S [$ NF]} END {for (ainS) printa, S [a]}'

TIME_WAIT29

FIN_WAIT1152

FIN_WAIT22

ESTABLISHED26

SYN_RECV16

(24) access the remote shared directory.

Put the following code in/etc/fstab:

// Ip/share1/mnt/dsmbfsdefaults, auto, username = name, password = pass00

The IP address is the IP address of the remote machine and the shared name of the shared directory. "/mnt/d" is to mount the partition to the local Linux directory, name and pass are the user names and passwords that can access the shared directory.

(25) how to increase the number of Tomcat connections.

In the Tomcat configuration file server. xml, you must increase the values of maxProcessors and acceptCount.

(26) how to modify the number of Tomcat ports.

Edit/etc/tomcat5/server. xml and find connectorport = "8080" maxHttpHeaderSize = "8192". Change the value of 8080 to unused ports above 1024.

(27) How to Increase Tomcat memory.

The default Tomcat memory is 128, which is obviously insufficient for some large applications. Therefore, we need to increase the memory manually:

# Vi/etc/tomcat5/tomcat5.conf

Find the "JAVA_OPTS =-Xmin0.1-Xmaxf0.3" code. Xmin0.1 indicates the initial memory size, changes it to Xmin256m, and Xmaxf0.3 indicates the maximum memory size. Change it to 512 m. Exit and restart to apply the Code.

(28) How to compress or merge large tar package volumes.

Take each volume of MB as an example, tar volume compression:

# Tar cvz pf-somedir | split-d-B 500 m

-D is not a split option, but a Shell option, indicating that the tar command output is used as the split input.

Tar multi-volume merge:

Catx *> mytarfile.tar.gz.

(29) how to remove unnecessary carriage returns from text (especially when copying from Windows to Linux ).

Sed's/^ M // 'test. sh> back. sh

Note that "^ M" is obtained by pressing "ctrl + V + M.

Or:

Dos2unixtest. sh

(30) how to change the RedHat System Language/character set.

Change the vi/etc/sysconfig/i18n file to: LANG = "en_US", X-window will display the English interface, and change it to: LANG = "zh_CN.GB18030 ", x-window displays the Chinese interface.

(31) Search for files with the S permission.

# Find.-typef \ (-perm-04000-o-perm-02000 \)-execls-lg {}\;

(32) find or delete a process that is using a file.

Fuserfilename

Fuser-kfilename

(33) how to make the user's password have a certain length and complexity.

Vi/etc/login. defs

Modify PASS_MIN_LEN.

(34) how to delete all contents (including directories and files in directories) three days ago ).

1find.-ctime + 3-execrm-rf {}\;

2find./-mtime + 3-print | xargsrm-f-r

(35) How to clear a file without changing inode.

> Filename

(36) Why is the Oracle Installation Program garbled.

Currently, Oracle Installation programs support Chinese characters. We recommend that you use the English interface to install it. Before Running runinstaller, run:

Export; exportLC_ALL = C

(37) What are the meanings of the colors of files and directories in Linux.

Blue indicates a directory; Green indicates an executable file; red indicates a compressed file; light blue indicates a link file; gray indicates other files; red indicates a link file is faulty; and yellow indicates a device file, including block, char, and fifo. You can use dircolors-p to view the default color settings, including various colors and definitions such as bold, underline, and blinking.

(38) How to check the number of httpd scripts and refresh them every 3 seconds.

Edit the following script:

#! /Bin/sh

While (true)

Do

Pstree | grep "* \ [httpd \] $" | sed's /. *-\ ([0-9] [0-9] * \) \ * \ [httpd \] $/\ 1 /'

Sleep3

Done

(39) how to enable the cp command to display the progress in running.

Cp-r-vdir1dir2

Cp-a-d-vdir1dir2

(40) after editing/etc/inittab, the configuration takes effect directly without restarting the computer.

Initq

(41) Let Linux Execute several commands consecutively and stop execution due to an error.

Command1 & command2 & command3

(42) What should I do when the screen changes to flowers.

When you accidentally cat a file that is not a text file, the screen will become blurred. you can press the "Enter" key and "Reset" key twice to restore the screen to normal.

(43) list the local IP address in the command line, instead of getting the NIC information.

# Ifconfig | grep "inet" | cut-c0-36 | sed-e's/[a-zA-Z:] // G'

Hostname-I

(44) How to not display the grep process itself.

# Ps-aux | grep httpd | grep-v grep

Grep-vgrep can cancel displaying the executed grep process. The-v parameter does not display the listed process name.

(45) delete files in the directory that contain keywords.

# Find/mnt/ebook/-typef-exec grep "input keyword" {}\;-print-execrm {}\;

(46) Let the task in cron not give back the information. Assume that the email is checked once every 5 minutes.

0-59/5 */usr/local/bin/fetchmail>/dev/null2> & 1

(47) How to enable multiple X-Windows.

Startx enables the first X-window with display: 0.0 by default. You can open multiple X-Windows by passing parameters to Xserver:

# Startx --: 1.0

# Startx --: 2.0

...

Then, use Ctrl + Alt + F7/F8 to switch.

(48) how to generate an empty file with a fixed length (for example, the file length is 1 MB), that is, the value of each byte is all 0x00.

# Dd if =/dev/zero of =/tmp/zero_file bs = 1024 count = 1024

(49) Find the files in the current directory and change the extension.

For example, change all files with the. cf extension in the current directory to. conf.

# Find./-name "*. cf"-execrename. conf '{}'\;

(50) how to delete packages that RPM-e cannot delete.

If you delete the directory of the package before deleting the package, run the following code:

# Rpm-e -- noscripts

If a package in the system is installed twice (due to some exceptions), run the following code:

# Rpm-emulti-installed-pkgs-allmatches

(51) how to prevent a key file from being modified.

In Linux, some configuration files cannot be modified by anyone (including root. To prevent accidental deletion or modification, you can set "Immutable" for the file )". The command is as follows:

# Chattr + I/etc/fstab

To modify the file, run the following command:

# Chattr-I/etc/fstab

(52) how to limit the number of processes that a user can start.

Check whether the following line of code in the/etc/pam. d/login file exists:

Sessionrequired/lib/security/pam_limits.so

Edit/etc/security/limits. conf and set the number of processes, CPU usage, and memory usage to limit the user. For example, hardnproc30 indicates a limit of 30 processes.

(53) how to limit the size of Shell Command records.

By default, bash stores up to 500 Command records in the $ HOME/. bash_history file. Sometimes the default number of records varies according to the specific system. In the system, each user's home directory has such a file. To ensure system security, we strongly recommend that you limit the size of the file. If you are a root user, you should reduce the number of entries. You can edit the/etc/profile file and modify the options as follows: HISTFILESIZE = 5 or HISTSIZE = 5 to reduce the number of recorded commands to 5.

(54) What should I do if I have no response when using the RPM command.

# Rm-rf/var/lib/rpm/_ db .*

(55) How to Prevent Users From modifying a file.

Some key files and important personal data in the system can be protected by file permissions, such as setting the file attribute to 600. In addition, if Linux uses the ext2 or ext3 file system, you can also use the chattr command to add the I attribute to the file. Even if the root user cannot directly modify or delete such files, to effectively prevent accidental modifications. The command is as follows:

# Chattr + I passwd

You can use the following command to remove the I attribute:

# Chattr-I passwd

(56) fixed the problem of slow WebLogic shutdown in Linux.

It takes a long time to start or close WebLogic because a Bug exists in JDK. The solution is to add the following content to setDomainEnv. sh In the WebLogic STARTUP script:

JAVA_OPTIONS = "$ {JAVA_OPTIONS}-Djava. security. egd = file:/dev/./urandom"

ExportJAVA_OPTIONS

We recommend that you back up setDomainEnv. sh before performing this operation.

(57) how to view the resource consumption of a process in real time.

First, check the PID of the process. Assume that the PID is 500. With the top-p500 command, you can view the resource consumption of this process in real time.

(58) how to delete a type of process.

# Ps-efww | grepLOCAL = NO | grep-vgrep | cut-c9-15 | xargskill-9

(59) How to manually modify the IP address.

Edit the/etc/sysconfig/network-scripts/ifcfg-eth0 file and run the following command:

Ifdowneth0; ifupeth0

(60) How to check what programs are running on port 22.

# Lsof-I: 22

(61) How to enable IP forwarding.

Edit/etc/sysctl. conf, for example:

Net. ipv4.ip _ forward = 0

Modify it:

Net. ipv4.ip _ forward = 1

It takes effect after restart. Use "sysctl-a" to check that IP Forwarding is enabled.

(62) How to allow/prohibit root users from logging on to the system through SSH.

Modify "sshd_config: PermitRootLoginno | yes.

(63) How to automatically synchronize time in Linux.

# Vi/etc/crontab

Add the following code:

0001 ** rootrdate-stime.nist.gov

(64) how to keep the SSH logon system open permanently.

Modify the. bash_profile file in the HOME directory, add exportTMOUT = 1000000 (in seconds), and run source. bash_profile.

(65) prevent anyone from using the su command as root.

Add the following code to vi/etc/pam. d/su:

Authsufficient/lib/security/pam_rootok.sodebug

Authrequired/lib/security/pam_wheel.sogroup = wheel

Define the wheel group in the/etc/pam. d/su configuration file.

(66) How to bind multiple IP addresses to a network card.

In Linux, a network card supports a maximum of 256 IP addresses. Run the following code:

# Cd/etc/sysconfig/network-scripts

# Cp ifcfg-eth0 ifcfg-eth0: 1

# Vi ifcfg-eth0: 1

Modify the IP address and device name.

(67) commands for clearing ARP tables in Linux.

# Arp-d-a (applicable to BSD)

ForHOSTinarp | sed '/Address/d' | awk' {print $1} '; doarp-d $ HOST; done

(68) How to enable Linux to support NAT.

# Echo1>/proc/sys/net/ipv4/ip_forward

# Iptables-tnat-IPOSTROUTING-jMASQUERADE

(69) How to temporarily modify the MAC address of the NIC.

L disable NIC:/sbin/ifconfig eth0 down

L modify the address:/sbin/ifconfig eth0 hwether 00: AA: BB: CCD: EE

L enable NIC:/sbin/ifconfig eth0 up

(70) Change eth0 to hybrid mode.

Enable eth0 and change it to the hybrid mode:

# Ifconfig eth0 promisc

Disable the hybrid mode:

# Ifconfig eth0-promisc

(71) How to allow SSH to log on to a specified user only.

Add the following to the/etc/pam. d/sshd file:

Authrequiredpam_listfile.soitem = usersense = allowfile =/etc/sshusersonerr = fail

Create the sshusers file under/etc, edit the file, add the user name that allows the use of the SSH service, and restart the SSHD service.

(72) 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 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.12.100: 0D: 61: 27: 58: E3

192.168.12.200: 40: F4: 2A: 2E: DC

192.168.12.300: 0A: EB: 5E: BA: AE

(73) How do I know the IP address of a machine in the network.

In Linux, run the following command to check the IP address corresponding to a hardware address such as "00: 0A: EB: 27: 17: B9:

# Cat/proc/net/arp | grep00: 0A: EB: 27: 17: B9

192.168.2.540x10x600: 0A: EB: 27: 17: B9 * eth2

In addition, you can use the "arp-a" command to query:

# Arp-a | grep00: 0A: EB: 27: 17: B9

(192.168.2.54) at00: 0A: EB: 27: 17: B9 [ether] oneth2

(74) The Apache-based HTTPD or Sendmail service is suspended at startup. How can this problem be solved.

In this case, check whether the/etc/hosts file contains the following line:

127.0.0.1localhost.localdomainlocalhost

Note: 127.0.0.1 is the network loop address.

(75) how to make Linux do not respond to ping.

To make Linux do not respond to ping, that is, to make Linux ignore ICMP packets, use the following command:

# Echo1>/proc/sys/net/ipv4/icmp-echo-ignore-all

To restore the data, run the following command:

# Echo 0>/proc/sys/net/ipv4/icmp-echo-ignore-all

(76) rsync compresses and transfers files or directories synchronously.

Rsync-azessh -- deletesample_dir/remote_host: remote_dir/sample_dir/

(77) You do not need to enter a password to log on with the SSH key.

Ssh-keygen-b1024-trsa

Sshserver "mkdir. ssh; chmod0700.ssh"

Scp ~ /. Ssh/id_rsa.pubserver :~ /. Ssh/authorized_keys

In this way, you can directly log on to the Server without prompting you to enter the password, which is convenient for file copying, synchronization, and other operations.

(78) send an email with an attachment under the command line.

# Cat <mailcontent.txt> | mutt-s "title"-a <attachfile> mail @ address

Here: <mailcontent.txt> indicates the body of the email. <Attachfile> indicates the file name of the local attachment.

(79) how to add the httpd dynamic module without re-compiling Apache (take the deflate module as an example ).

Go to the httpd source code directory:

# Cd/usr/local/src/httpd-2.2.6

Run the bin/apxs file in the directory after httpd installation:

/Usr/local/apache2/bin/apxs-ciamodules/metadata/mod_deflate.c

Restart httpd:

# Service httpd restart

(80) how to change the default storage location of sendmail mail.

If sendmail uses Procmail as the MDA (mail delivery agent), Procmail can be used to specify the default storage location for receiving mails. The method is as follows:

Create the/etc/procmailrc file.

Edit the/etc/procmailrc file and specify the path of the MAIL environment variable, such as "$ HOME/mbox.

(81) The standard connection library used by the newly compiled GCC is located in/usr/local/lib, but the default connection path used is/usr/lib. How to add the library.

ExportLD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/lib

Write it to "~ /. Bash_profile.

(82) Why can't Shell scripts be run.

The script permission must be "# chmod + xtest. sh ". And the directory where the script is located is in the path environment variable, or directly execute "#./test. sh ".

(83) Where is the MySQL DATA inventory.

If the RPM package is used for installation, it should be located in the/var/lib/mysql directory, with the database name as the directory name.

If the source code is installed in/usr/local/mysql, it should be located in/usr/local/mysql/var and named as the Directory Name of the database.

(84) 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''

# Mysqladminflush-privileges

(85) Enable MySQL to start in large memory mode.

Copy a mysql-*. cnf file under/usr/share/mysql (such as a mysql-huge.cnf in 1 GB memory) to the/etc/mysql. cnf file and restart MySQL.

(86) Mount folders on the remote host through SSH.

Sshfsname @ server:/path/to/folder/path/to/mount/point

(87) display the top 10 processes that consume the most memory, sorted by memory usage.

# Ps aux | sort-nk + 4 | tail

(88) use Shell email notification.

# Echo "Testmail" | mail-s theme test root@sampl.com

Note: The SMTP Service of the host must be enabled.

(89) how to find the core files generated by system program crash in the javaslerac environment.

When the system program crashes, the kernel maps the current memory to the core file. We use the X86 environment as an example to find the core location using the following command, we can also see which file caused the problem.

# Find/u01-name core. *-exec ls-l thr {}\; | awk '{print $9}' | xargs file

/U01/oracle/product/crs/log/rac1/crsd/core.20.7: ELF32-bitLSBcorefileIntel80386, version1 (SYSV), SVR4-style, from 'crsd. bin'

From the above command, we can see that the generation of core.20.7 is caused by the "crsd. bin" file.

(90) How to quickly scan out a network segment (for example, 192.168.150.0/24) to start the server.

The first simple method:

# Nmap-sP 192.168.150 .*

The second method is to use a Shell script:

For (I = 1; I <= 254; I ++); do ping 192.168.150. $ I; done

(91) how to disable the network connection of a process.

We can first find the port number based on the process, and then directly discard the sent package, or use the owner function.

# Iptables-m owner-pid-owner <processid>-j REJECT

(92) How to quickly disable SELinux.

#/Usr/sbin/setenforce0 disable SELinux immediately

#/Usr/sbin/setenforce1 enable SELinux immediately

You can also edit the configuration file for the same purpose:

# Vi/etc/selinux/conf

SetSELINUX = disabled

(93) how to listen for packets sent from port 80 to client-A or from client-

# Tcpdump-I eth0 host client-A and port80

If your computer has multiple NICs, specify the NICS after-I.

(94) How does one display the user name after a user logs on to the system?
Change/sbin/bash in the shell environment variable of the System user to/sbin/nologin. Note that you cannot change the root user to/sbin/nologin. Otherwise, you cannot log on to the system. The role of nologin can also restrict some users to log on to the shell through ssh.

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.