Linux: Frequently used command

1. List disk space usage:

df -hl
// "l" means "local", limit listing to local file systems
// "h" means "human-readable", print sizes in human readable format
 du -cks *|sort -rn|head
// recurisive sort file size under current folder

2. Sort file by size:

ls -hlS
// "h": "human-readable", print sizes in human readable format
// "l" : use a long listing format
// "S": sort by file size
// "t" : sort by modification date
// "r" : reverse order while sorting
// "s" : size, with "-l" print size of each file, in blocks

// For file, the output is the size of the file.
// For directory, the output is fixed 4.0K.

3. Delete file by size:

find . -size +10240k -exec rm -rf {} \;

4. Delete file by date:

find . -mtime +5 -exec rm -rf {} \;

5. Overview of CPU, I/O, Memory:

> vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 778576 337756 3527900    0    0     1    21    0    0  1  0 98  1  0

// Processes:
//  r: The number of processes waiting for runtime.
// b: The number of processes in uninterruptible sleep.
// Memory:
// swpd: The amount of virtual memory used.
// free  : The amount of idle memory
// buff  : The amount of memory used as buffers.
// cache: the amout of memory used as cache.
// Disk/Memory Swap:
// si: Amount of memory swapped from disk.
// so: Amount of memory swapped to disk.
// I/O:
// bi: Blocks received from a block device
// bo: Blocks sent to a block device
// System:
// in: The number of interrupts per second, including the clock
// cs: The number of context switches per second
// CPU:
// us: Time spent runnning non-kernel code. (user time)
// sy: Time spent running kernel code. (system time)
// id: Time spent idel.
// wa: Time spent waiting for IO
// st: Time stolen from a virtual machine.

6. Brief overview of system load average

>uptime
03:33:32 up 271 days,  9:44,  1 user,  load average: 0.93, 1.06, 0.99
// 0.93 is the load average for last 1 minute
// 1.06 is the load average for last 5 minutes
// 0.99 is the load average for last 15 minutes
// Command above should usually used combine with command below:

> grep 'model name' /proc/cpuinfo
model name      : Intel(R) Xeon(R) CPU           X5650  @ 2.67GHz
model name      : Intel(R) Xeon(R) CPU           X5650  @ 2.67GHz
// Means our system are 2-core machine.

7. Real time CPU/Memory/Load Average usage monitor:

> top
top - 03:58:40 up 151 days, 18:50,  4 users,  load average: 0.78, 0.67, 0.28
Tasks: 157 total,   1 running, 156 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.0%id,  0.8%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:   8174448k total,  4369796k used,  3804652k free,   138580k buffers
Swap:        0k total,        0k used,        0k free,  1491884k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                         
16267 rcastdev  15   0 10888 1104  800 R  0.3  0.0   0:00.01 top                                                             
16769 root      15   0     0    0    0 S  0.3  0.0   0:06.31 pdflush

8. Network statistical info:

> netstat -s
> netstat -pt
// -p: show PID which possess the port number
// t: show TCP protocol only
Proto Recv-Q Send-Q Local Address               Foreign Address             State PID  
tcp    0          0          ***.***:23010            ***.***:43333 ESTABLISHED  123

9. Memory statistical  info:

> free
             total       used       free     shared    buffers     cached
Mem:       8174448    4369228    3805220          0     138664    1492784
-/+ buffers/cache:    2737780    5436668
Swap:            0          0          0

10. SCP:

// SCP local file to remote:
scp {local-file} {username}@{remote-machine}:{remote-dir}
// SCP remote file to local:
scp {username}@{remote-machine}:{remote-file} {local-dir}

 

 

 

 

Reference Links:

1> Load average: http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

2> SCP: http://www.hypexr.org/linux_scp_help.php

 

猜你喜欢

转载自davyjones2010.iteye.com/blog/2149990