Summary of Common Linux commands

Source: Internet
Author: User
Tags ftp site parent directory zookeeper disk usage high cpu usage traceroute command

1. Enter a directory: such as Cd/home/app

2. list all subdirectories and files in the target directory : LS

the ls command is the most commonly used command under Linux. The LS command is the abbreviation for list. LS is used to print out a list of current directories

The LS command is the most commonly used command under Linux. The LS command is the abbreviation for list. LS is used to print out a list of current directories

1) LS [option] [directory name]

2) Common parameters

-a,–all lists all files under the directory, including the. The implied file at the beginning

-A with-a, but not listed "." (represents the current directory) and ".." (Represents the parent directory of the current directory).

-C mate-lt: Sort by CTime and display CTime (time of last change of file status) Mate-L: Show CTime

But sort by name otherwise: Sort by ctime

-c list items from top to bottom of each column

–color[=when] Controls whether to use color-resolved files. When can be ' never ', ' always ' or ' auto ' one of them

-d,–directory Displays the directory as a file, rather than displaying the file below it.

-d,–dired results in the use of dired patterns for Emacs

-F does not sort the output files, the-au option is active, the-LST option is invalid

-g similar to-l, but does not list owner

-g,–no-group does not list any information about the group

-h,–human-readable list file sizes in an easy-to-understand format (e.g. 1K 234M 2G)

–si is similar to-H, but the file size takes 1000 times instead of 1024

-h,–dereference-command-line the true destination indicated by using symbolic links in the command column

The –indicator-style= method specifies that after each project name is followed by the indicator < >:none (default), classify (-f), File-type (-P)

-i,–inode Prints the inode number of each file

-i,–ignore= style does not print any items that match the shell character < style >

-K is the –block-size=1k that represents the size of the file in K-byte form.

-l lists the permissions, owner, file size, and so on, in addition to the file name.

-l,–dereference when displaying the file information for a symbolic link, displays the object indicated by the symbolic link instead of the information of the symbolic link itself

-m all items are separated by commas and fill the entire row width

-O is similar to-L, showing details of the file in addition to the group information.

-r,–reverse in reverse order.

-r,–recursive listing all subdirectory tiers at the same time

-s,–size to list the size of all files in block size

-s sort by file size

–sort=word The following are optional WORD and the corresponding options they represent:

Extension-x status-c

None-u time-t

Size-s Atime-u

Time-t Access-u

Version-v Use-u

-T sorted by file modification time

-U mate-lt: Show access time and sort by access time

Mate-L: Show access time but sort by name

Otherwise: Sort by access time

-U does not sort, lists items according to the original order of the file system

-V Sort by version

-W,–WIDTH=COLS Specifies the screen width without using the current value

-X list items line by row instead of columns by column

-x Sort by extension

-1 list only one file per line

Help display this help message and leave

–version display version information and leave

3. Run the shell script file: such as./patch.sh

4. Name an alias: such as alias rs= '/home/app/resin/bin/restart.sh '

5. View file contents, common commands: less, cat

6. Reload the environment variable configuration, such as: Source/etc/profile

7. Kill a process, kill Sigkill PID, such as Kill-9 3629

8. View the running program, PS aux

-A: All process not related to terminal;

-U: Effective user (effective user) related process;

x: Commonly used with the A parameter to list more complete information

9. Query the process through the name of the program: PGREP parameter option program name, such as Pgrep-lo httpd

Common parameters

-l lists the program name and process ID;

The ID of the start of the-O process;

-N The ID of the process termination;

10. Download the entire HTTP or FTP site, the basic syntax is: wget [parameter list] URL

such as: wget http://place.your.url/here

This command can download the Http://place.your.url/here home page.

Using-X forces the creation of identical directories on the server.

If you use the-nd parameter, all content downloaded by the server will be added to the local current directory

12. Schedule the execution of repetitive tasks based on a combination of time, date, month, and week, crontab

View timed tasks: crontab-l

Edit timed Task: CRONTAB-E

13. Add environment variables, such as add "Name=liheng"

Export Name=liheng

14.ulimit resources used by the shell startup process, such as Ulimit-n 65536

Parameter description:

-H sets the hardware resource limit.

-S sets the software resource limit.

-a displays all current resource limits.

-C Size: Sets the maximum value of the core file. Unit: Blocks

-D Size: Sets the maximum value for the data segment. Unit: Kbytes

-F Size: Sets the maximum value of the created file. Unit: Blocks

-L Size: Sets the maximum value of the locked process in memory. Unit: Kbytes

-M Size: Sets the maximum number of resident memory that can be used. Unit: Kbytes

-N Size: Sets the maximum number of file descriptors that the kernel can open at the same time. Unit: N

-P Size: Sets the maximum value of the pipe buffer. Unit: Kbytes

-S size: Sets the maximum value of the stack. Unit: Kbytes

-T size: Sets the maximum CPU usage time limit. Unit: Seconds

-V Size: Sets the maximum value for virtual memory. Unit: Kbytes

There are two types of 15.Linux links, one called hard link, and the other is called symbolic symbolic link.

By default, the LN command produces a hard link.

1) A hard connection refers to a connection through an index node. In the Linux file system,

Files saved in a disk partition regardless of the type, assign a number to it, called the index node number (Inode index).

In Linux, multiple file names point to the same index node that exists. Generally this connection is a hard connection;

2) Another connection is called a symbolic connection (symbolic link), also known as a soft connection.

A soft-link file has a shortcut similar to Windows. It's actually a special file.

In a symbolic connection, a file is actually a text file that contains location information for another file.

To establish a soft connection: Ln-s source target

such as: Ln-s/home/download/resin2.6/home/app/resin

To create a hard link and a soft link:

such as: [[email protected]]$ Touch F1 #创建一个测试文件f1

[Email protected]]$ LN F1 F2 #创建f1的一个硬连接文件f2

[Email protected]]$ ln-s F1 F3 #创建f1的一个符号连接文件f3

[[Email protected]]$ ls-li #-I parameter displays inode node information for a file

As you can see from the above test, hard connection F2 is not affected when the original file F1 is deleted, but the symbolic connection F3 file is not valid

16.touch is typically used to create a new file. At the same time, touch can also be used to modify file timestamps.

17. View the Java,tomcat running situation JPS

18. View Memory: Cat/proc/meminfo | grep memtotal

19.DF-HL View Linux hard disk space

20.dmidecode | grep "Product" View server model

21.uname-a This command to see if the server is a virtual machine or a physical machine, the kernel of the virtual machine is mostly Xen

22.scp-p 16322 [Email protected]:/home/app/resin/log/invalidtoken.391/home/user/

Another way to copy files from the server

* Command format:

Scp-r Local_folder [Email protected]_ip:remote_folder

23. Find keywords from the specified file

Grep-n-a5-b5--color=auto ' querytxt ' filename

24. Some server modification hosts do not take effect immediately and need to manually update the hosts

Command:/ETC/INIT.D/NSCD restart

25. Keep the latest 66 files in the directory:

#!/bin/bash

#snapshot file dir

Datadir=/home/app/test/zk_data/version-2

#tran Log dir

Datalogdir=/home/app/test/zk_log/version-2

#zk Log dir

Logdir=/home/app/test/logs

#Leave files

count=66

count=$[$count +1]

Ls-t $dataLogDir/log.* | Tail-n + $count | Xargs rm-f

Ls-t $dataDir/snapshot.* | Tail-n + $count | Xargs rm-f

Ls-t $logDir/zookeeper.log.* | Tail-n + $count | Xargs rm-f

#注: 1) ls-t According to the actual reverse order; 2) Tail-n +20 means starting from 20th, 3) Xargs a very large group of

According to split into small parts, passed to the command behind, otherwise the data are many, will be error

26. Use Ssh-keygen-i–f Pubkey.file to convert non-openssh pubkey formats

27.du-sh View the total size of the current directory

28. Upgrade Bash

1) Debian version: sudo apt-get update && sudo apt-get install bash

2) CentOS version: Yum update && yum install bash

29. View information such as the Linux version: Cat/proc/version or uname-a

30. Empty files: echo/dev/null > FileName

31. See if the file is Dos,:set FF?

: Set Ff=unix through this change file to UNIX file

32.uname-a This can be distinguished, the virtual machine's kernel is mostly Xen

Dmidecode | grep "Product" View server model

Df-h

With Xvda and the like is the virtual machine

33. View Port Connection usage: Netstat-an |grep:3306

A (All) displays all options and does not show listen related by default
-T (TCP) displays only TCP-related options
-U (UDP) displays only UDP-related options
-N refuses to display aliases, showing all numbers converted to numbers.
-l list only service status in Listen (listening)

-P Displays the program name that establishes the associated link
-R display routing information, routing table
-e display extended information, such as UID, etc.
-S statistics according to each protocol
-C executes the netstat command every other fixed time.

34.IPTABLES-NL viewing the configured filtering rules

1) Add Filter rule: iptables-a input-s 127.0.0.1-p tcp--dport 3306-j ACCEPT

Iptables-a input-s 127.0.0.1-p TCP--dport 3306-j DROP

2) Delete filter rule: iptables-d input-s 127.0.0.1-p tcp--dport 3306-j Accept/drop

35.linux command-line post data:

The option for Post mode is-D

Like what

Curl-d "user=nickwolfe&password=12345" http://www.linuxidc.com/login.cgi

36. Recursion change the use of-L in Permissions Note:

-R parameter We all know, is in order to recursively modify the permissions of the sub-directory;

After adding-R, there are a few parameters to note, wherein the-l, that is, should not be recursive in the time, recursive to the real directory of soft links to go;

And just on the decompression machine,/home/monitor/test/This directory is a soft link, so when performing chown-r, phase

When it is only recursive to the test directory, and no longer recursively in its real directory

It's a coincidence.

Two improper use together, eventually there is this problem, of course, chown Plus-L, the problem can be solved;

Summarize

A little summary.

Peacetime with the Linux command, the Man manual is not seen, but at least--help listed those still look;

When working with directories, especially when it comes to recursive subdirectories, most of the Linux commands use-l to indicate whether

Follow symbolic links. (e.g. chown, find, etc.)

38. Add comments in bulk:

Add # comments To line 10-20

: 10,20s/^/#/g

Delete # comments on line 10-20

: 10,20s/^#//g

39. Leap second solution, set the time manually:

sudo date-s "20150701 09:58:00"

40. Delete the log files created 100 days ago:

Find. -ctime +100-name "log*" | Xargs rm-f

Delete log files that are less than 100 days

Find. -ctime-100-name "log*" | Xargs rm-f

Extra: #-atime

#-mtime

#-ctime

#-amin

#-mmin

#-cmin

So here atime,mtime,ctime is the corresponding "Last Access Time" "Last Content Modification Time" "Recent

A property modification Time ", where atime units refer to" Days ", Amin units are minutes

For example: Zookeeper only keep logs for the last 30 days:

Zookeeper only scripts that keep logs for the last 30 days:

#!/bin/sh

find/home/app/zookeeper/data/version-2/-ctime +30-name "log*" | Xargs rm-f

find/home/app/zookeeper/data/version-2/-ctime +30-name "snapshot*" | Xargs rm-f

41. View the domain name resolution process: Nslookup or dig domain name

The 42.traceroute command allows you to track the routing of network packets, the default packet size is 40Bytes, the user can set a separate

such as traceroute hostname

tracert hostname under Windows

43. Installation Instructions:

Debian dpkg-i Xxx.deb

Redhat rpm-i xxx.rpm

44. Locate threads with high CPU usage:

1) Top command to view approximate CPU usage and load loads

2) Use Pidstat to monitor all or specified processes that consume system resources, such as CPU, memory, device IO, task switching,

threads, etc.

such as: Pidstat-p 17056-u 1 3-t, view the PID 17056 program, 1 seconds is the sampling period, 3 times of statistical information

3) Jstack output all current threads, such as

Jstack-l 17056 >/home/bjwudi/jstack-201511091457.log

Locate the specific method by locating the TID with the most CPU using the Pidstat in step 2, then turning the TID into 16, and finding the corresponding hexadecimal tid in the jstack exported file.

Extended:

CPU Usage statistics (-u)

With the-u option, Pidstat displays CPU usage statistics for each active process, performing "pidstat-u" with separate

The same effect as the "Pidstat" line.

Memory usage statistics (-R)

Using the-r option, Pidstat will display memory usage statistics for each active process

IO Case Statistics (-D)

With the-D option, we can view the statistics of process IO

45.iostat

1) iostat-d-K 1 10

Parameter-D indicates that the device (disk) usage status is displayed; k Some columns using block are forced to use kilobytes as a single

bit; 1 10 indicates that the data is refreshed every 1 seconds and is displayed for a total of 10 times

2) using the-x parameter we can get more statistical information

RRQM/S: How much of this device-dependent read request has been merge per second (when the system call needs to read the data, the VFS will

The request is sent to each FS, and FS will merge the request if it finds that different read requests are reading the same block of data.

Merge); wrqm/s: How much of this device-related write request is being merge per second.

RSEC/S: Number of sectors read per second; wsec/: Number of sectors written per second. R/s:the number of Read requests

that were issued to the device per second;w/s:the number of write requests this were issued to the device per second;

Await: The average time (in milliseconds) of processing per IO request. This can be understood as the response time of Io, a

The system IO response time should be less than 5ms, if more than 10ms is larger.


%util: All processing io time, divided by total statistic time, in the statistical time. For example, if the statistic interval is 1 seconds, the device has

0.8 seconds while processing Io, while 0.2 seconds is idle, then the device's%util = 0.8/1 = 80%, so this parameter implies that the device

Degree of busy. Generally, if the parameter is 100%, the device is already running close to full load (of course, if it is multiple disks,

Make%util 100% because of the concurrency of the disk, so disk usage may not be the bottleneck.

3) If the%util is close to 100%, indicating that there are too many I/O requests and that the I/O system is full, the disk may have bottlenecks.

Idle less than 70% io pressure is larger, the general reading speed has more wait.

You can also combine vmstat to see the b parameter (the number of processes waiting for a resource) and the WA parameter (the percent of CPU time that IO waits

higher than 30% when IO pressure is high)

In addition, the parameters of await are also more and SVCTM to reference. There must be an IO problem with too much difference.

Avgqu-sz is also an IO tuning need to pay attention to, this is the direct operation of the size of the data, if many times, but

If the data is small, the IO will be very small. If the data is large, the IO data will be high. You can also pass AVGQU-SZX (r/s or w/s) = RSEC/S or wsec/s. That is to say, the speed of reading is determined by this.

46. View the footprint size of the directory-level subdirectory: Du-h--max-depth=1

47. Check the current directory and sub-directory file name contains "Commons-codec" files

Find. -name ' *commons-codec* '

48.crontab execution, lock the target folder, to avoid the last scheduled task does not finish, another one:

1) Local mode: */10 * * * * (flock-xn/var/run/rsync01.lock-c '/bin/sh/home/app/shellscript/rsynchtml.sh ')

-X indicates an exclusive lock

-N Specify Lock file

2) Client mode:

*/2 * * * * lockfile-s 5-r 1/tmp/rsync1.lock &&/usr/bin/rsync-ua/home/htmlfile/nc/192.168.52.72::newsclien t/; Rm-rf/tmp/rsync1.lock

Lockfile-sleeptime | -R Retries | -L Locktimeout | -S Suspend | -! | -ml |  -mu | FileName ...

49. Count the number of file handles opened by the Velocity.log file: lsof velocity.log | grep velocity.log|wc-l

50. Bulk Delete:

Delete all content: First go to the end of the file with G, then use the following command:

: 1,. D

Delete the contents of line 10th to 20th: first go to line 20th with 20G, then use the following command:

: 9,. D

51. Find the first occurrence of the keyword and identify the green:

grep ' Too many open files ' jvm-default.log | awk ' nr==1 {print ' \033[32m "$" \033[39m "} '

52. Query the interface timeout for more than 10 seconds:

grep--color=auto ' Costtime [1-9]\{5,\} MS ' Catalina_2016-08-08.log

such as: grep ' process article cost:[1-9]\{5,\}ms ' Catalina_2016-09-13.log

53./home/jdk-oracle-1.6.0_64/bin/jmap-dump:format=b,file=/home/logs/heap.hprof 31252

54. Count word occurrences and sort the output:

1) grep ' Get articles list cost: ' Jvm-default.log |  Awk-f ", topicid=" ' {print $} ' | Sort | uniq-c | Sort-k1,1nr

Sort Description:

1) the plus-n parameter is sorted by number. If there are non-numeric characters in a row, sort by the number size preceding the non-numeric character

2) sort the default sorting method is ascending, if you want to change to descending order, add an-R to do it.

3) The default sorting is in the order of the behavior units, if you want to sort by a field, you can specify the field separation with the-t option

Character,-k specifies the field to sort.

The-k parameter is in the format of-K Start[,end], and it is important to note that if you omit end, you need to compare to the end of the line.

Example: ~$ cat text

1|101|2

1|10|2

~$ Echo $LC _all

C

~$ sort-t "|"-K 2 text

1|101|2

1|10|2

~$ sort-t "|"-K 2,2 text

1|10|2

1|101|2

Although the 10 row is in front of 101, but does not specify the end of the field, the default will continue to compare, that is, compare ' | ' and ' 1 ', so there's on

The result of the polygon.

In general, we only want to sort by one or more fields, rather than starting from one field to the end of the line, so use the

This parameter is preferable to specifying both start and end.

54.java View Heap Overall situation: Jmap-heap 25008

Note: Jmap is a tool that can output all in-memory objects, and even the heap in the VM can be output as text in binary.

Command: Jmap-dump:format=b,file=heap.bin <pid>

File: Save path and file name

PID: Process number

Jmap-histo:live pid| Less: The object and size of the activity in the heap

Jmap-heap pid: View heap usage information

55. Close the extranet Ifdown eth0

Open the external network ifup eth0


This article from "Quiet Zhiyuan" blog, declined reprint!

Summary of Common Linux commands

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.