Linux daily records (Notes For Frequently Asked Questions)

Source: Internet
Author: User
Tags disk usage
0) Preface

I have learned that, since, I have been familiar with open-source platforms and have been involved in Linux. During this period, I have recorded all the problems. Although it is very embarrassing, I am afraid to keep it up to myself, the entries are not strictly organized. I hope it will be helpful for later users.

 

1) commonly used to view the path of a command

Which: view the path of a command. The command searches for the command in the path configured by the PATH variable and returns the first query result.

 

Methods for viewing user information

Finger

ID

Groups

 

Delete directory

ResultDirectoryIt is null. You can use rmdirDeleteIfDirectoryIt is not null. You can use Rm-RF.Delete

 

Create a symbolic link (shortcut)

Ln-s {target-filename} {symbolic-filename}

For example create softlink for/webroot/home/httpd/test.com/index.php as/home/Vivek/index. php, enter the following command:
Ln-S/webroot/home/httpd/test.com/index.php/home/Vivek/index. php
Ls-l

 

View system startup logs

Dmesg | more

 

Grep

Case Insensitive

Grep-I

 

Randomly generated NIC address

#! /Bin/sh
Exec 2>/dev/null
Dd If =/dev/urandom BS = 1 COUNT = 6 | OD-T X1 | sed '2d; S/^ 0 \ + //; S //:/G'

 

Three methods for adding the PATH variable

1) modify the/etc/profile file, which is valid for global users.

2) modify the. bashrc file to be accurate to the user (only valid for the current user)

3) directly add a variable to the shell. If the shell exits, the variable becomes invalid.

 

List objects in chronological order

Ls-T

 

List objects in reverse chronological order (after the new file)

Ls-RT (r indicates the meaning of reverse, which can reverse all sorts)

Ls searches for a file in the current directory, but does not list contents in subfolders.

Ls-d "pattern"

 

Copy all files in a directory

CP-R

 

After modifying fstab, how can I load all file systems without restarting?

Mount-

 

Move folders

Mv src dest

 

View the Linux version

1. Run the following command to view the kernel version:
1) [root @ q1test01 ~] # Cat/proc/version
Linux version 2.6.9-22. elsmp (bhcompile@crowe.devel.redhat.com) (GCC version 3.4.4 20050721 (Red Hat 3.4.4-2) #1 SMP mon Sep 19 18:00:54 EDT 2005
2) [root @ q1test01 ~] # Uname-
Linux q1test01 2.6.9-22. elsmp #1 SMP mon Sep 19 18:00:54 EDT 2005 x86_64 x86_64 x86_64 GNU/Linux
3) [root @ q1test01 ~] # Uname-R
2.6.9-22. elsmp
2. view the Linux version:
1) log on to the server and execute lsb_release-a to list all version information, for example:
[Root@3.5.5Biz-46 ~] # [Root @ q1test01 ~] # Lsb_release-
LSB version: core-3.0-amd64: core-3.0-ia32: core-3.0-noarch: Graphics-3.0-
Ia32: graphics-3.0-noarch
Distributor ID: redhatenterpriseas
Description: Red Hat Enterprise Linux as Release 4 (nahant Update 2)
Release: 4
Codename: nahantupdate2
Note: This command applies to all Linux releases, including RedHat, Suse, and Debian.
2) log on to Linux and run CAT/etc/issue, for example:
[Root @ q1test01 ~] # Cat/etc/issue
Red Hat Enterprise Linux as Release 4 (nahant Update 2)
Kernel \ r on an \ m
3) log on to Linux and run CAT/etc/RedHat-release, for example:
[Root @ q1test01 ~] # Cat/etc/RedHat-release
Red Hat Enterprise Linux as Release 4 (nahant Update 2)
Note: In this mode, you can see the specific version number, such as as4 update 1.
4) log on to Linux and execute rpm-Q RedHat-release, for example:
[Root @ q1test01 ~] # Rpm-Q RedHat-release
Redhat-release-4AS-3
Note: in this way, you can see a so-called release number. For example, the above example is 3.
There is a certain correspondence between the release number and the actual version, as shown below:
Redhat-release-3AS-1-> Redhat Enterprise Linux as 3
Redhat-release-3AS-7.4-> Redhat Enterprise Linux as 3 Update 4
Redhat-release-4AS-2-> Redhat Enterprise Linux as 4
Redhat-release-4AS-2.4-> Redhat Enterprise Linux as 4 Update 1
Redhat-release-4AS-3-> Redhat Enterprise Linux as 4 Update 2
Redhat-release-4AS-4.1-> Redhat Enterprise Linux as 4 Update 3
Redhat-release-4AS-5.5-> Redhat Enterprise Linux as 4 Update 4
Other methods: 3rd) and 4) are only valid for Redhat Linux.

 

2) How to enable automatic Mount

Add a file system that is automatically mounted after startup. You can add an item to fstab, for example, add a Windows shared connection.

 

After modifying fstab, how can I load all file systems without restarting?

Mount-

 

Add a service that needs to run at startup:

Method 1: create a link in rc3.d

Method 2: Add a startup Item to RC. Local.

 

Init. d, RC [X]. d directory relationship

All files under this directory are linked files, all pointing to/etc/rc. d/init. d directory, and the/etc/rc. d/init. d directory is used to set the startup directory of some services when Linux rpm is installed. For example, if you want to restart Sendmail and your Sendmail is installed with rpm, release/etc/rc. d/init. d/sendmail restart can start Sendmail directly! So you can know the main functions of files in/etc/rc. d/init. d! So, when you run-level scripts to start which write Service, huh, huh! Link the file to the file under the init. d directory and start it! That is to say, when you start Linux in the run-level mode (run-level = 3), your system goes through bios, MBR, kernel, init,/etc/rc. d/RC. after sysinit, it will enter/etc/rc. d/rc3.d to start some services! However, you must note that, in rc3.d (or another directory, rc0.d ~ Rc6.d) the file starting with "S" in the directory is to execute the service, and the file starting with "K" is to kill the service. So what are the meanings of those numbers? That's the order of startup! For example, s12syslog will be executed earlier than s90crond! So why are there such orders? There is a reason! For example, if your host needs to start WWW, your network settings should be started first! So, if WWW is first started to drive the network, then WWW will naturally not get up! Therefore, the startup sequence of various services is also very important! Currently, you can use chkconfig to set the service options to be started when the machine is started!

 

3) view memory information about performance

CAT/proc/meminfo view memory information

 

View system disk usage

The DF command can be used.

DF-H makes the display result easy to read, for example, write 15176390 to 15 GB.

 

4) directory permission

-Rwxr-XR-x 1 Root 512 November 5 08:08 net. Lo
Drwxr-XR-x 2 root Root 48 Aug 17 13:06 Vmware
The first 2nd ~ 10 characters are used to indicate permissions. The first character is generally used to distinguish between files and directories:
D: indicates a directory. In fact, in ext2fs, a directory is a special file.
-: Indicates that this is a common file.
L: This is a symbolic link file. In fact, it points to another file.
B and C: Block devices and other peripheral devices, respectively. They are special files.
S, P: these files are related to the system's
Data Structure
And pipelines, which are rarely seen.
The following describes the types and methods of permissions.
II. General Permissions
2nd ~ Each three of the 10 characters is a group. The three characters on the left indicate the owner permission, and the three characters in the middle indicate the permissions of users in the same group as the owner, the three characters on the right are the permissions of other users. These three groups contain nine characters, which indicate the following meanings:
R (read, read): For a file, it has the permission to read the file content; for a directory, it has
Browse
The permission of the object.
W (write): For a file, you have the permission to add or modify the file content. For a directory, you have the permission to delete or move files in the directory.
X (execute): For a file, you have the permission to execute the file. For a directory, you have the permission to enter the directory.
-: Indicates that this permission is not granted.

 

 

Install tar.gz using the 5th Software

Tar-xzf: Extract

./Configuration: generate the make file. The prefix parameter is generally used to configure the target path.

Make: Compile

Make install: Install

Find the *** installed with RPM *** Program Set path

Rpm-Qa | grep ***

Check whether a software package is installed.

Rpm-Q package name

Find the *** assembly path installed with RPM

Rpm-Qa | grep ***

Install with APT

Sudo apt install apache2 mysql5

Introduction

TheAdvanced Packaging Tool, OrApt, Is a free user interface that works with core libraries to handle the installation and removal of software on the Debian GNU/Linux distribution and its variants. [2] apt simplifies the process of managing software on Unix-like computer systems by automating the retrieval, configuration and installation of software packages, either from binary files or by compiling source code. [2]

 

6) view the local service port on the network

Netstat-TLN

View the program corresponding to a port

Lsof-I: 80, or netstat-anp | grep Port

Disable Firewall

/Etc/rc. d/init. d/iptables stop

Open Firewall

/Etc/rc. d/init. d/iptables start

View the configuration before iptable

: Iptables-l

Packet Capture and packet analysis

: TCPDUMP-I eth1 host XXX. XXX and port 80

Other commands are as follows:

The command parameter for saving tcpdump packets to a file is-w xxx. Cap.
Capture the eth1 package
Tcpdump-I eth1-W/tmp/xxx. Cap
Capture the packet of 192.168.1.123
Tcpdump-I eth1 host 192.168.1.123-W/tmp/xxx. Cap
Capture port 80 of 192.168.1.123
Tcpdump-I eth1 host 192.168.1.123 and port 80-W/tmp/xxx. Cap
Capture the ICMP packet of 192.168.1.123
Tcpdump-I eth1 host 192.168.1.123 and ICMP-W/tmp/xxx. Cap
Capture packets of port 80 of 192.168.1.123 and ports other than 110 and 25
Tcpdump-I eth1 host 192.168.1.123 and! Port 80 and! Port 25 and! Port 110-W/tmp/xxx. Cap
Capture VLAN 1 packets
Tcpdump-I eth1 port 80 and VLAN 1-W/tmp/xxx. Cap
Capture pppoe Password
Tcpdump-I eth1 pppoes-W/tmp/xxx. Cap
Save the file in 100 MB, and open a file larger than MB-C MB
Capture 10000 packets and exit-C 10000
Packet capture in the background, and the exit of the console will not be affected:
Nohup tcpdump-I eth1 port 110-W/tmp/xxx. Cap &
You can use ethereal or Wireshark to open the captured file. Wireshark is the new Ethereal

How can I modify IP information in Linux?

In the past, ifconfig was always used for modification, and it had to be redone after restart. If you modify the configuration file, you don't have to worry about it ~

A. Modify the IP address

Effective immediately:

# Ifconfig eth0 192.168.0.20 netmask 255.255.255.0

Start effective:

VI/etc/sysconfig/network-scripts/ifcfg-eth0

B. Modify the Default Gateway

Effective immediately:

# Route add default GW 192.168.0.254

Start effective:

VI/etc/sysconfig/network-scripts/ifcfg-eth0

C. Modify DNS

Modify/etc/resolv. conf

The modification takes effect immediately and starts as well.

D. Modify the host name.

Effective immediately:

# Hostname FC2

Start effective:

Modify/etc/sysconfig/Network

New Startup Network Configuration

/Etc/init. d/network restart

Note: After modifying the machine name, you generally need to modify the hosts (/etc/hosts) file and add the corresponding IP address of the machine name.

Premise: RedHat System

IP address, mask:

Edit/etc/sysconfig/network-script/ifcfg-eth0
Ipaddr = 192.168.0.1
Netmask = 255.255.255.0

Gateway:

Edit/etc/sysconfig/Network
Networking = Yes
Hostname = xx
Gateway = 192.168.0.100
DNS:

Edit/etc/resolv. conf
Nameserver = 202.96.209.5
Note: The above IP addresses must be changed to the IP address corresponding to your network configuration.

7) vi

VIM: Undo and redo

: U (UNDO operations)

CTRL + R

VI search:

Command STATUS input/pattern2search, continue to search directly press n

VI paste: P

VI cut: [number] dd Or d [number] D, number indicates the number of lines to cut

VI copy: [number] YY, number is the number of rows

Move to the end of the paragraph {}

Shift + G move to the end of the document

D l Delete the current character (same as the X command)
D 0: Delete to the starting position of a row
D ^ Delete to the first character position of a line (excluding spaces or ta B characters)
D w: delete it to the end of a word
D 3 W Delete to the end of the third word
D B. Delete it to the start position of a word.
D w is deleted to the end of a word with a space as the separator.
D B: delete it to the start position of a word with a space as the separator.

 

8) common directory Functions

/Bin stores the longest-used commands, such as CP, ls, and CAT.
/Boot some core files used when Linux is started.
/Dev is the abbreviation of device. This directory contains all Linux peripheral devices. D: \ document \ chat \ myim \ bin \ release
The/etc directory is used to store the configuration files and subdirectories required by the system management.
/Home user's home directory. For example, if a user is named Wang, the directory is/home/Wang ~ Wang.
The/lib directory stores the most basic dynamic connection libraries of the system. Almost all applications must use these shared libraries.
The/lost + found directory is usually empty. When the system is not shut down normally, this is a shelter for some homeless files.
/Mnt: the directory is empty. The system provides this directory for users to temporarily Mount other file systems.
The/proc directory is a virtual directory, which is the system memory ing. We can directly access this directory to obtain system information. That is to say, the contents of this directory are not on the hard disk but in the memory.
/Root the main directory of the system administrator (Root) as the privilege of the system owner.
/Sbin S is the meaning of super user, that is, the management program used by the system administrator is stored here.
The/tmp directory stores some temporary files.
/Usr almost all the application files we use are stored in this directory:/usr/x11r6 stores the x_window directory;/usr/bin stores many applications; /usr/sbin puts some management programs used by Super Users in this directory;/usr/include header files required for application development and compilation; /usr/lib stores some frequently used dynamic connection shared libraries and static archive libraries;/usr/local is the/usr directory provided to general users, which is the most suitable for installing software here. /Usr/man stores help documents. /Usr/src openSource codeThis directory exists.
The/var directory stores constantly expanding things. To keep the USR relatively stable, the directories that are frequently modified can be placed in this directory, such as/var/log files.

 

9) other meanings about input and output ">" <"

Cat x y 1> hold 2> & 1

The result is to output the standard + error to the hold;

Cat x y 2> & 1 1> hold redirects the error output to the standard output and redirects the standard output to the hold. Therefore, the error output will not enter hold because it is directed to the standard output.

Value assignment relationship

(1) 1 = hold, 2 + = 1;

(2) 2 + = 1, 1 = hold.

 

Shell script

Shift: Delete the first variable in the command line Variable list, and change the second variable to the first one. It can be understood that the variable list header pointer moves one

The daemon statement and the & symbol can change the program to the background output.

 

10) problems with Linux installation on virtual machines

Virtual Machine installation screen adjustment resolution

After Linux is installed in vitualpc, the graphic interface will generate a screen. In this case, you need to jump to the command line mode and adjust the xwin parameters as follows:

During startup, before loading various startup items, Linux prompts whether to enter interactive mode by typing 'I. At this time, type I to enter interactive mode, manually Allow System items one by one and prohibit the system from starting xwin

After entering the command line mode, go to the/etc/X11/directory, modify the resolution and color depth in the X11 configuration file, and restart after modification.

 

New Linux version ?? When the kernel is loaded into the virtualpc virtual machine, the mouse cannot be captured. You can modify the kernel parameters in grub. conf to correct this problem.

Go to Kernel

Add i8042.noloop at the end of the row

Kernel/vmiluz ******* Ro root = label =/***** i8042.noloop

 

Windows 2008 Remote Desktop, eliminating the restriction that only one user can log on

Http://vanderbiest.org/blog/2010/08/16/multiple-rdp-sessions-in-windows-2008-r2/

 

 

 

12) collnetsvn 1.1.0 x86 Linux Installation

Download the collnetsvn File

CP to the installation directory

Switch the user to a common user su somebody (it must not be root. If there are no users, you can use adduser to add one and use passwd username to change the password of this user)

Tar-zxf Decompression

Run csvn/bin/csvn start and csvn/bin/csvn-HTTPd start as the normal user just now (root cannot be used)

You can add csvn-HTTPd to the startup Item by using ln-S/csvn/bin/csvn-HTTPd s99csvn_httpd. After you restart the system, you can see that this service is loaded at startup.

 

11) httpdapache configuration forwarding

<Virtualhost *: 80>
Proxypreservehost on
Serveradmin a@a.com
Servername search.cd-host.net
Defaultlanguage ZH-CN
Adddefacharcharset UTF-8
Proxypass/http://www.missworld.cn: 8888/
Proxypassreverse/http://www.missworld.cn: 8888/
</Virtualhost>

 

Start FastCGI: spawn that comes with light httpd

/Usr/local/webserver/PHP/bin/spawn-fcgi-A 127.0.0.1-P 10080-C 64-u www-F/usr/local/webserver/PHP/bin/PHP -CGI

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.