Linux Command considerations

Source: Internet
Author: User
Tags dmesg egrep
Document directory
  • File Stat-Display Information About File

1. recursively create a directory and specify the permission Value

 

2. Create a file and specify the permission value.

 

3. When ls is used to list directories, the data information must be listed.

Basic display standard: displays in full-time format, with the file size-h (unit: MB, or GB, rather than byte, it is displayed (byte by default). It identifies the file type, file permissions, users of the file and user groups, and sorts the files in the following order:

 

Display in the order of modification time:

Ll-sh-t-full-time

-H is displayed in MB, KB, and GB format.

-T is sorted by the modified time.

 

Sort by file name

By default, sorting by file name

 

Sort by file size (excluding Directories]

Ll-sh-S -- full-time [add-r, for example, ll-something-Sr -- full-time indicates reverse sorting]

 

The default sorting method is file names (in alphabetical order), which are sorted by file name, file size, file type (directory, file), and modification time. [sort by type first, based on the time or file name]

 

Sort priority: sort by file type first, and then sort by size (only file, not directory form)

 

 

 

4. View information about a directory or file by express delivery: file type, path, and permission Value

 

5. display the row number to view small files

Display the row number to view the large text file [page view]. Page View specifies the page number, page number, and the number of records displayed on each page.

 

6. Select the file to view the [number of rows range]-> for example, view the data of a large file

There are several situations:

1. From the first 40 rows to the end

2. From 40 rows at the beginning of the row to the first 50 rows at the end of the row

3. obtain data from 30th to 100 rows in the file

The first method is head and tail: head-n 100 ~ /. Bashrc | tail-n 30

The second method is to directly use sed: nl ~ /. Bashrc | sed-n '100 P'

 

Explanation:

Sed-n, -- quiet, -- silent cancel default output, otherwise for nl ~ /. Bashrc | sed-n '000000p', which outputs all. bashrc. By default, in general SED usage, all data from STDIN will be displayed on the screen. If the-n parameter is added, only data that has been specially processed by sed will be displayed.

 

7. locate can be searched by wildcard matching, and solve the problem that locate cannot search for instant files.

Update the search database before searching

 

Run the updatedb command to update with root updates, and then use locate to search for updates.

 

--- How to quickly search for files and use the permission values of listed files

 

File Stat-Display Information About File
stat /home/ramesh


stat `locate detail.phtml`|cat -n 

ll --full-time -th  `locate detail.phtml`|cat -n

8. When the system administrator clears the/etc/issue file, how does one know the current system version, version number, and kernel number?

 

Ll-sh -- full-time/etc/| grep-I 'release'

If there is a vendor trademark-release file, that is, detailed information

 

Lsb_release-

 

To view the kernel

Uname-

Cat/proc/version

 

 

9. Enable grep to support wildcard Filtering

 

10. If you want to output the screen content to a text file, the pipeline command application [especially stdout and correct, error output]

 

11. When grep filters netstat and ps, it also removes the head header description. How can we make the console output head header information and filter information?

 

12. If you can quickly find the log information of a service

 

For example, how to quickly know the log file location of httpd, mysql, and corntab

View syslog. conf

 

13. When a file is displayed, different operating systems lead to line breaks, different carriage returns, how to view carriage returns, etc.

Sudo cat access_etam.com.cn-check.log | egrep-I '. + \. html. + HTTP. + [: space:]? \ B503 \ B [[: space:]?. +'

14. Find all users and user information that can be logged on to the current system.

 

 

15. Percentage of disks occupied by folders removed from the current directory

 

 

Software Installation

1. How do I know whether the software is installed through bin, rpm-src, or source code?

Log view

How do I know what is logrotate?

 

Operate linux ---------> use regular expressions to search for files.

 

--------- Use the original command before using alias ---

 

A large text file, such as the HTTPD log file, MYSQL Log File is too large, nearly 2 GB big, how to quickly read part of the data (number of rows), of course, use grep, vim, cat must be unrealistic.

 

How to kill all processes at one time. For example, if there are nearly 15 httpd processes in the current system, kill-9 PID cannot be used to kill all processes at one time.

Killall process name

 

 

20. How can I transmit big data files at the maximum speed on different servers? That is, network transmission of big data files?

 

 

HTTP Log Analysis and Solution

1. You want to obtain all the 404 pages in the file, except spilder and crawler.

2. You want to get all pages with 503,504,502 errors and IP addresses in the file.

 

 

Gawk 'in in {FS = ","; OFS = "--"} {print $1, $2, $3} 'data1

Cat access_etam.com.cn-check.log | egrep-iv '(Spider | crawler | bot)' | egrep-I 'HTTP: // [-a-z0-9R :@&? = + ,.! /~ + % $] + \. (Html | htm) '| gawk' BEGIN {FS = ""; OFS = "-"} {if ($9 = "502" | $9 = "504") print $4, $9, $7} '| head-n 20

 

Gawk 'in in {FS = ","} $2 ~ /Define data2/{print $0} 'data1

 

Cat access_etam.com.cn-check.log | egrep-iv '(Spider | crawler | bot)' | egrep-I 'HTTP: // [-a-z0-9R :@&? = + ,.! /~ + % $] + \. (Html | htm) '| gawk' BEGIN {FS = ""; OFS = "----"} $7 ~ /(Html | htm) $/{if ($9 = "502" | $9 = "504") print $4, $9, $7 }'

 

 

Cat access_etam.com.cn-check.log | egrep-iv '(Spider | crawler | bot)' | egrep-I 'HTTP: // [-a-z0-9R :@&? = + ,.! /~ + % $] + \. (Html | htm) '| gawk' BEGIN {FS = ""; OFS = "----"} $7 ~ /(Html | htm) $/{if ($9 = "502" | $9 = "504") print $4, $9, $7 }'

 

 

1. For the log configuration with rotation, it usually generates some compressed files. If you do not want to compress these files, you can also see the content in these files.

 

 

 

22. How do I know which emails have been sent and which emails have not been sent?

 

 

 

How do I know which users have sent emails to the MTA? Include various users?

 

How can I send an MTA email to whom?

 

 

23. When a terminal needs to execute commands for a long time, it can be solved by running them in the background. How can I know whether an error is reported in the background or whether the operation is successful?

 

 

24. How can I manage background execution, add a running program to a background for execution, and manage related calls?

When to run the script in the background: for example, if you are copying a large file with a size of 3 GB, it takes one hour to import the database script for decompression or compression. If you do not use the background for execution, it keeps occupying the terminal, and thus cannot continue to execute the command line.

 

Considerations for background execution:

1. There should be a record on how to ensure that there are no errors during execution.

2. sdtout and sdtin must be taken into account. If there is a standard input and output in the command line, it will still be automatically displayed on the screen .. For example, v in tar zxvf is the output visual information.

 

For example, tar-zpcvf/tmp/etc.tar.gz/etc>/tmp/log.txt 2> & 1 &

 

2> what is & 1:

This is to place the error output and the correct output in the same file. You need to use this special writing method 2> & 1, which indicates writing to the same file.

 

 

MPs queue instructions:

1 indicates that the correct output of find/home testing> list_right is actually 1.

 

2 indicates the error output find/home-name testing> list_right 2> list_error

 

When we only need the correct information and do not need the error information, we need to use the/dev/null garbage bin./Dev/nullIt is regarded as a "black hole". It is very equivalent to writing only files. All the content written to it will be lost forever, and the attempt to read content from it will not be able to read anything.

For example

An error message such as rm $ badname 2>/dev/null [standard error] will be displayed and will not be stored in the system.
 
 

If you need to place the error output and correct output in the same log file, you can use a special method like 2> & 1.

You can use

 

 

View current jobs

Jobs-l

 

Abort and delete a job: kill-9% job ID

 

 

 

One server is operated by multiple people. When the system is found to be a little unstable, how can I know what operations others have done?

Last [it generally only reads the lo Record of the current month, generally it has a large amount of information], lastlog

 

 

Hardware information and performance monitoring

 

 

View basic computer or system configuration information

Hardware

CPU model and size

[Root @ localhost ~] # Grep "model name"/proc/cpuinfo
Model name: Intel (R) Xeon (R) CPU E5410 @ 2.33 GHz
Model name: Intel (R) Xeon (R) CPU E5410 @ 2.33 GHz

 

4. view the CPU count
[Root @ localhost ~] # Getconf LONG_BIT

 

View memory (only in KB)
[Root @ localhost ~] # More/proc/meminfo
MemTotal: 3755008 kB
MemFree: 155276 kB

 

View memory (displayed in MB)

[Root @ localhost ~] # Free-m

 

View Nic Information

[Root @ localhost ~] # Dmesg | grep 'eth'

 

System Software

1. view the kernel

[Root @ localhost ~] # Uname-
Linux localhost. localdomain 2.6.18-164. el5xen #1 SMP Tue Aug 18 16:06:30 EDT 2009 i686 i686 i386 GNU/Linux

 

2. view the version

[Root @ localhost ~] # More/etc/issue
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
Kernel \ r on an \ m

 

3. View System languages

 

 

Basic disk Information

1. obtain information about the current storage device (including the most basic information such as the brand, trademark, and model)

Cat/proc/scsi

 

Or hard disk capacity.

If you only want to obtain the disk size: fdisk-l

It is best to use the lshw software to view the information, it will be more comprehensive, of course, the premise is to install the software first

Lshw-class disk-class storage

 

Speed and basic disk read/write speed

Sudo hdparm-tT/dev/sda

 

View the hard disk or disk organization: LVM, RAID, etc. What is the capacity of this Organization?

 

Hard Disk Type: RAID, basic Hard Disk

SCSI or HDA

Hard disk read/write speed test

Hard Disk

Several hard disks

 

Hard Disk Type: RAID, basic Hard Disk

Hard Disk Type:
PV VP PE LV LVM

--------- View PV
Pvscan
Pvdisplay

Vpdisplay

RAID level

Partition

Dmesg-l | egrep-I 'disk'

References

Http://www.cyberciti.biz/faq/find-hard-disk-hardware-specs-on-linux/

Http://www.cyberciti.biz/tips/how-fast-is-linux-sata-hard-disk.html

------------

Motherboard:
Number of hard disks that can be inserted

USB data
Supported USB types

 

 

 

The log is too large.

Too many httpd processes need to be solved.

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.