Linux Common simple Commands (iii) TAR, SCP, DF/DU, PS, free, top, netstat, tcpdump, kill, Reboot/halt/poweroff, shutdown __linux

Source: Internet
Author: User
Tags bz2 memory usage readable unpack domain name server disk usage ssh port

1.1 Package Unpack Command (TAR)
Common packing commands: tar, usually with the following parameters:

-C: Set parameters command for compressed files (create)

-x: Extracting parameter commands for files

-Z: Do you have the gzip attribute at the same time? Do you need to use gzip compression?

-j: Whether to have bzip2 familiar at the same time. Whether you need to use BZIP2 compression.

-V: Displays files during compression.

-F: Use filename, note that the file name is immediately followed by F. Do not add new parameters.

1.1.1 Packing Command
For example:

Pack all the files that start with SMS_MT into Sms_mt.tar packages.

root@[/mas/log/sms/bak]$ TAR-CVF Sms_mt.tar sms_mt*

Package all the files that start with SMS_MT into the sms_mt.tar.gz package.

root@[/mas/log/sms/bak]$ TAR-ZCVF sms_mt.tar.gz sms_mt*

Package all the files that start with SMS_MT into the sms_mt.tar.bz2 package.

root@[/mas/log/sms/bak]$ TAR-JCVF sms_mt.tar.bz2 sms_mt*

1.1.2 Unpack the Package command
Unpack the Sms_mt.tar package.

root@[/mas/log/sms/bak]$ TAR-XVF Sms_mt.tar

Unpack the sms_mt.tar.gz package.

root@[/mas/log/sms/bak]$ TAR-ZXVF sms_mt.tar.gz

Unpack the SMS_MT.TAR.BZ2 package.

root@[/mas/log/sms/bak]$ TAR-JXVF sms_mt.tar.bz2

1.2 telnet command (SSH)
telnet command: SSH login user @ip-p port

For example: Log on to the 172.16.9.28 server from a server, SSH port is 8015

root@[/root]$ SSH mas@172.16.9.28-p8015

mas@172.16.9.28 ' s password: (the MAS user password for 172.16.9.28 server is filled in here)

Last login:wed Aug 5 09:04:11 2009 from 172.18.25.203

mas@[/mas]$

1.3 Remote Transfer Command (SCP)
Telnet command: Scp-p port transfer file user @ip: Destination path

For example, transferring dbbackupfiledelete.pid files from a server to 172.16.9.48

mas@[/mas]$ scp-p8015 dbbackupfiledelete.pid Mas@172.16.9.48:/mas

mas@172.16.9.28 ' s password: (MAS user password for 172.16.9.28 server)

1.4 View Disk File space (DF/DU)
1.4.1 View System Individual disk usage
View the disk space file system and Usage: DF, the common parameters are as follows:

-A or--all contains all file systems;

-H or--human-readable to display information in a more readable manner;

The-H or--si is the same as the-h parameter, but is calculated using 1000 Bytes as the conversion unit instead of 1024 Bytes;

-I or--inodes display the information of the inode;

-K or--kilobytes specifies a block size of 1024 bytes;

-L or--local only displays the file system on the local side;

-M or--megabytes specifies a block size of 1048576 bytes;

For example, use Df–h to view details of the current system's capacity and used space, free space, and so on.

mas@[/mas/libsrc]$ df-h

File system capacity used available% mount point

/dev/mapper/rootvg-lvroot 16G 386M 15G 3%/

/dev/mapper/rootvg-lvhome 992M 34M 908M 4%/home

/dev/mapper/rootvg-lvvar 20G 293M 19G 2%/var

/dev/mapper/appvg-lvmysql 21G 249M 20G 2%/var/lib/mysql

/DEV/MAPPER/ROOTVG-LVUSR 18G 3.5G 13G 21%/usr

/dev/mapper/appvg-lvapp 9.7G 435M 8.8G 5%/app

/dev/mapper/appvg-lvbak 9.7G 905M 8.4G 10%/bak

/dev/mapper/appvg-lvmas 48G 3.6G 42G 8%/mas

/DEV/SDA1 99M 12M 83M 13%/boot

Tmpfs 506M 0 506M 0%/dev/shm

1.4.2 View directory or File usage
View each file or directory size use command: Du, the common parameters are as follows:

-A or-all displays the size of individual files in the directory;

-B or-bytes displays the directory or file size in bytes;

-C or--total displays the sum of all directories or files in addition to the size of individual directories or files;

-D or--dereference-args displays the source file size for the specified symbolic connection;

-H or--human-readable to k,m,g to improve the readability of the information;

-H or--si is the same as the-h parameter, but K,m,g is a conversion unit of 1000;

-K or--kilobytes to 1024 bytes as the unit;

-L or--count-links a file that repeats the hardware connection;

-l< symbol connection > or--dereference< symbol connection > Display options The source file size of the symbol connection specified;

-M or--megabytes in 1MB units;

-S or--summarize display totals only;

-S or--separate-dirs displays the size of the individual directory and does not contain the size of its subdirectories;

-X or--one-file-xystem the file system at the start of the process, and if you encounter a different file system directory, skip.

For example, use Du–h to view the file size in the current directory.

mas@[/mas/libsrc]$ du-h

88K./svr_common

2.1M./isdn_head

60K./sms_moden

2.5M./mas2

13M.

1.5 View System process (PS)
To view the status of the process of the system commands: PS, the common parameters are as follows:

-A shows the procedures executed under all terminals, except for the stage-working leader;

A shows all the procedures under the existing terminals, including the procedures of other users;

-a displays all programs;

-C Displays CLS and PRI fields;

C listing the program, display the actual instruction name of each program, and does not include the path, parameters or the indication of resident service;

-e This parameter has the same effect as the specified "A" parameter;

e Displays the environment variables used by each program when the program is listed;

-F Displays Uid,ppip,c and Stime fields;

-H shows the tree structure, representing the relationship between programs;

-j or J uses the work control format to display the program status;

-L or L use a detailed format to display the program status;

L list the relevant information of the place of the slaughter;

N numbers to represent the user and Wchan fields;

-u< User ID > The effect of this parameter is the same as the specified "-u" parameter;

U display program status in user-oriented format;

X shows all programs and does not differentiate by terminals;

X uses legacy Linux i386 login format to display program status.

For example, use PS Aux|grep gwinit_db to view information related to gwiinit_db processes.

mas@[/mas/libsrc]$ PS Aux|grep gwiinit_db

Mas 7944 0.0 0.0 5180 692 PTS/7 s+ 20:24 0:00 grep gwiinit_db

1.6 Show Memory status (free)
Display the memory status of the command: free, the general display of memory usage, including physical memory, virtual swap file memory, shared memory section, and the system core use of buffers. Common parameters are as follows:

-B Displays memory usage in byte;

-K displays memory usage in kilobytes;

-m displays memory usage in MB;

-O does not display buffer throttling columns;

-s< interval seconds > Continuous observation of memory usage;

-T displays the memory sum column;

-V Displays version information.

For example: Use Free-m to view current system memory usage:

mas@[/mas/libsrc]$ free-m

Total used free shared buffers Cached

mem:1010 985 24 0 56 112

-/+ buffers/cache:816 194

swap:4095 673 3422

1.7 Display system resources (top)
Show system resources command: Top. It is a commonly used performance analysis tool under Linux, which can display the resource occupancy status of each process in the system in real time, similar to the Task Manager of Windows. The following is a detailed description of how it is used.

root@[/root]$ Top

top-01:06:48 up 1:22, 1 user, load average:0.06, 0.60, 0.48

tasks:29 Total, 1 running, sleeping, 0 stopped, 0 zombie

Cpu (s): 0.3% us, 1.0% sy, 0.0% ni, 98.7% ID, 0.0% wa, 0.0% Hi, 0.0% si

mem:191272k Total, 173656k used, 17616k free, 22052k buffers

swap:192772k Total, 0k used, 192772k free, 123988k cached

PID USER PR NI virt RES SHR S%cpu%mem time+ COMMAND

1379 Root 0 7976 2456 1980 S 0.7 1.3 0:11.03 sshd

1470 Root 0 2128 980 796 R 0.7 0.5 Top

1471 Root 0 1992 632 544 S 0.0 0.3 0:00.90 Init

1472 Root 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0

1473 Root 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0

The meanings of the columns are as follows:

Ordinal column name meaning

A PID process ID

b PPID Parent Process ID

C Ruser Real user name

D UID Process Owner's user ID

The user name of the e user process owner

Group name of the F group Process owner

G TTY starts the process's terminal name. Processes that are not started from the terminal are displayed as.

H-PR Priority

I NI nice value, negative indicates high priority, positive values mean low priority

The last CPU used by J P is meaningful only in a multi-CPU environment

K%cpu percentage of CPU time last updated to now

The total amount of CPU time used by the L/O process, in seconds

Total CPU time used by the M time+ process, in units 1/100 seconds

N%mem percent of physical memory used by the process

o The total amount of virtual memory used by the virt process, in kilobytes. Virt=swap+res

The amount of virtual memory that the P swap process uses, the size of which is swapped out, the unit KB.

The amount of physical memory used by the Q RES process that is not swapped out, in kilobytes.

The physical memory size, in kilobytes, that the code executable uses

The amount of physical memory that is consumed outside of the s DATA executable code, in kilobytes

T SHR shared memory size, per kb

U Nflt page Error times

V NDRT last written to now, the number of pages that have been modified.

W S process status. (of which: d= the state of sleep; r= operation;

s= sleep; t= tracking/stopping; z= zombie process)

x command name/command line

Y Wchan If the process is sleeping, show the name of the system function in sleep

Z Flags Task Flag

By default, only the more important PID, USER, PR, NI, Virt, RES, SHR, S,%cpu,%mem, time+, command columns are displayed.

1.8 Display System network condition (netstat)
Display system network Status common commands: Netstat, which allows you to view the entire Linux system's network situation (typically only the root user has permission to execute the command). Common parameters are as follows:

-A or--all to display sockets in all lines;

-a< network type > or--< network type > lists the relevant addresses in the network type line;

-C or--continuous continuously list network status;

-C or--cache display the router configuration cache information;

-E or--extend display other relevant information about the network;

-F or--fib display fib;

A-G or--groups displays a list of multiple broadcast function group members;

-H or--help online help;

-I or--interfaces display network interface information form;

-L or--listening display the socket of the server in the monitor;

-M or--masquerade display a disguised network connection;

-N or--numeric directly using the IP address, but not through the domain name server;

-N or--netlink or--symbolic displays the symbolic connection name of the network hardware peripherals;

-O or--timers display timer;

-P or--programs displays the program identifier and program name for which the socket is being used;

-R or--route display routing Table;

-S or--statistice display network work information tables;

-T or--tcp shows the connection status of the TCP transport protocol;

-U or--UDP displays the connection status of the UDP transport protocol;

-V or--verbose display instruction execution process;

-V or--version display version information;

-W or--raw shows the connection status of the raw transport protocol;

-X or--unix the effect of this parameter is the same as the specified "-A unix" parameter;

--ip or--inet The effect of this parameter is the same as the specified "-A inet" argument.

For example, see if Port 7890 is already occupied by a process.

root@[/root]$ NETSTAT-ANP |grep 7890

TCP 0 0 0.0.0.0:7890 0.0.0.0:* LISTEN 24536/mscp

TCP 0 0 172.16.9.48:45221 221.130.33.92:7890 established 24464/MSCP

1.9 Network Packet Grab command (tcpdump)
Network packet Crawl Use command: tcpdump, this command usually has only root to execute permissions. Common parameters are as follows:

-i < NIC port > use the specified network card port to send out packets;

-s < packet size > set the size of each packet;

-W < packet file > write packet data to specified file

For example: Crawl sent to destination address 221.130.33.91, port is TCP 8080

root@[/root]$ tcpdump-i eth0 TCP port 8080 and host 221.130.33.91-s 0-w

Tcpdump:listening on eth0, Link-type EN10MB (Ethernet), capture size 65535 bytes

(Use the "Ctrl" + "C" key combination to terminate the grab command, just get the packets to be written to the Mas_mms.cap file)

Packets Captured

Packets Received by filter

0 packets dropped by kernel

The network packets obtained can usually be analyzed using the ethereal tool.

1.10 Process deletion (kill)
Process deletion using the command: Kill, General and-9 collocation use.

For example, you can first find Tomcat's PID through the PS command, and then force the process to end by using the KILL command.

root@[/mas/guoleia/mysrc/gb2uni]$ Ps-ef|grep gwiinit_db

Mas 1446 1 0 22:04? 00:00:00 MSCP gwiinit_db

Root 2094 20812 0 22:08 pts/26 00:00:00 grep gwiinit_db

root@[/mas/guoleia/mysrc/gb2uni]$ kill-9 1446

1.11 Restart command (reboot, Halt, Poweroff)
Reboot command: Reboot, Halt, Poweroff, almost the same as Shutdown-r now.

1.12 Shutdown Command (shutdown)
Shutdown command: Shutdown, you can turn off all programs, and according to the needs of users, to reboot or shutdown action. Common parameters are as follows:

-C when the "shutdown-h 11:50" instructions, just press the + key can interrupt the shutdown instructions;

No fsck is performed when-F restarts;

Execute fsck when-F restarts;

-H shuts down the system;

-K simply sends out information to all users, but does not actually shut down;

-N does not invoke the INIT program for shutdown, and is performed by shutdown itself;

-R shutdown after reboot;

Number of seconds to delay between-t< seconds > sending warning messages and deleting information.

For example:

Shutdown Now:

root@[/root]$ Shutdown-h Now

On the same day 20:25 shut down the machine:

root@[/root]$ shutdown-h 20:25

The system shuts down again in 10 minutes:

root@[/root]$ shutdown-h +10

The system reboots immediately:

root@[/root]$ Shutdown–r Now

This article from Csdn Blog, reprinted please indicate the source: http://blog.csdn.net/grredowen/archive/2009/10/30/4749101.aspx

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.