Some of the commonly used commands on linux

top: command often used to monitor system status linux, such as cpu, memory usage.

free: observe the memory usage.

Find: Find the file specified.

   Whereis: Find the file specified source and binary files and manuals

   Which: a location query commands or aliases.

   Locate: quickly find the content specified in the system database.

   Grep: Find files that match the criteria string.

2. grep

search string in a file (case insensitive)

$ -i grep "The" demo_file

output successful match line, and three lines after the line

$ grep -A 3 -i "example" demo_text

in a file recursive query folder that contains the specified string file

$ grep -r "ramesh" *

more examples:! ON the Get a Grip at the grep - 15 Practical examples grep the Command
3. the Find

find the specified file names (case insensitive)

$ find -iname "MyProgram.c"

execute a command on the files found

$ find -iname "MyProgram.c" -exec md5sum {} \;

all the empty file find home directory under

$ -empty the find ~


23. the as Free

This command is used to display the current memory usage system, including the used memory, available memory and swap memory where the

default will be free in bytes the amount of memory output units of

    $ free
                 Total Used free Shared buffers cached
    Mem: 3566408 1,986,188 203 988 902 960 0 1.58022 million
    - / + buffers / Cache: 473 272 3,093,136
    Swap: 4000176 0 4000176

If you want to use a different amount of output per unit of memory, you need to add an option, -g as GB, -m for the MB, -k (KB) , -b bytes

    $ -g as Free
                 Total Used as Free Shared buffers cached
    Mem: 3 1 1 0 0 0
    - / + buffers / Cache: 0 2
    Swap: 3 0 3

if you want to see a summary of all memory, use - t option, use this option will add a summary line in the output

    @-Laptop Ramesh Ramesh: -t ~ $ Free
                 Total Free Used Shared buffers cached
    Mem: 3,566,408 1,592,148 0 1.97426 million 204.26 thousand 912 556
    - / + buffers / Cache: 475 332 3,091,076
    Swap: 4,000,176 4,000,176 0
    the Total: 1,592,148 5974436 7566584

24. A Top

Top command displays the current system takes some process most resources (the default sort order CPU usage) If you want to change the sort, you can click in the results list O (uppercase letter O) shows all the columns for sorting, this time you select the column you want to sort

    Current the Sort Field,: P for window. 1: Def
    the select Via Sort Field Field Letter, type the any OTHER Key to return
      a: the PID = Process Id V: NDRT = Dirty Pages COUNT
      D: the UID = the User Id Y : WCHAN = Sleeping in Function
      E: the User the USER the Name = z: Flags = Task Flags
      ........

if a particular user processes only want to display, you can use the -u option

$ top -u oracle

more examples: Can You Top This? Top the Linux the Command Practical Examples 15
25. a DF

display file system disk usage, df -k output bytes will be used in an amount of disk default

$ DF -k
the filesystem 1K-Blocks used the Available the use% Mounted ON
/ dev / sda1 29.5304 million 3233104 24,797,232 12% /
/ dev / sda2 120 367 992 44% 50,171,596 64.08206 million / Home

use -h option to display disk usage in a manner more in line with the reading habits of

$ df -h
Filesystem Size Used Avail Capacity Mounted Iused iFree% Iused ON
/ dev / disk0s2 232Gi 84Gi 148Gi 37 % 21998562 38864868 36% /
100% 187Ki 187Ki 0Bi devfs 648 0% 100 / dev
Map -hosts 0Bi 0Bi 0Bi 100 100 0% 0% / NET
Map the auto_home 0Bi 0Bi 0Bi 100 100 0% 0% / Home
/ dev / disk0s4 466Gi 45Gi 421Gi 10% 112 774 440 997 174 % 0 / Volumes / the BOOTCAMP
//[email protected]/public 2.7Ti 1.3Ti 1.4Ti 48% 0% 0 18446744073709551615 / Volumes / public

-T option to display the file system type

$ DF -T
the filesystem the type-1K the Available Blocks used Mounted% ON the Use
/ dev / sda1 24,797,216 12 is 3.23312 million 29.5304 million ext4% /
/ dev / sda2 ext4% 120 367 992 50,171,596 44 is 64.08206 million / Home

26. A the kill

kill to terminate a process. Generally, we will first look for a process with ps -ef get its process ID, then use the kill -9 process ID to terminate the process. You can also use killall, pkill, xkill to terminate the process

$ PS -ef | grep vim
Ramesh 7243 7222 9 22:43 PTS / 2 00:00:00 vim

$


WC: Count
  -l: number of lines
  -w: Words
  -c : The number of characters

  wc -l file1 file2 ...... can count multiple files

cat to read text
  -n: display the line number
  -b: display the line number and ignores blank lines

  cat -n 1.txt

more display text each time a screen, press the space bar to continue
  the Find / -name "* .sh" | More

 

tail from a specified starting position behind the display was content
  tail -f server.log for the top server running while viewing the log
  tail -10 dos2unix. sh look at the last 10 lines of

 

head
  and tail correspond

with the "route -n" and "netstat -nr" command, we can view the default gateway. In addition to the default gateway information, these two commands can also display the current routing table.


Ifconfig 36. The

ifconfig is used to view and configure Linux systems network interface

View all network interfaces and their status

$ ifconfig -a

use the up and down commands to start or stop an interface

    $ ifconfig eth0 up
     
    $ ifconfig eth0 down

43. The less

this name displays the file without loading the entire file, viewing when large log files that can be very useful command

$ less huge-log-file.log

when you open a file with the less command, the following two buttons will give you a lot of help, for their forward and backward scroll

CTRL + F - Forward One window
CTRL + B - Backward One window


to see if the linux in a port (port) is occupied by
a use lsof

format:
1
    
lsof -i: port

for example, I want to see the 80-port occupancy can be used lsof -i: 80

you can clearly see that the port is occupied

NOTE: when should be noted that, lsof need to have permission to the process, parties can view, occupancy. For example, I use another user, you can not see the.

Current users will not see the name dequan process occupancy. If you are using nginx or root user on it, as follows:

Second, use netstat

format:
1
    
netstat -anp | grep Port

such as viewing occupancy 80, as follows:
top: command often used to monitor system status linux, such as cpu, memory usage.

free: observe the memory usage.

Find: Find the file specified.

   Whereis: Find the file specified source and binary files and manuals

   Which: a location query commands or aliases.

   Locate: quickly find the content specified in the system database.

   Grep: Find files that match the criteria string.

2. grep

search string in a file (case insensitive)

$ -i grep "The" demo_file

output successful match line, and three lines after the line

$ grep -A 3 -i "example" demo_text

in a file recursive query folder that contains the specified string file

$ grep -r "ramesh" *

more examples:! ON the Get a Grip at the grep - 15 Practical examples grep the Command
3. the Find

find the specified file names (case insensitive)

$ find -iname "MyProgram.c"

execute a command on the files found

$ find -iname "MyProgram.c" -exec md5sum {} \;

all the empty file find home directory under

$ -empty the find ~


23. the as Free

This command is used to display the current memory usage system, including the used memory, available memory and swap memory where the

default will be free in bytes the amount of memory output units of

    $ free
                 Total Used free Shared buffers cached
    Mem: 3566408 1,986,188 203 988 902 960 0 1.58022 million
    - / + buffers / Cache: 473 272 3,093,136
    Swap: 4000176 0 4000176

If you want to use a different amount of output per unit of memory, you need to add an option, -g as GB, -m for the MB, -k (KB) , -b bytes

    $ -g as Free
                 Total Used as Free Shared buffers cached
    Mem: 3 1 1 0 0 0
    - / + buffers / Cache: 0 2
    Swap: 3 0 3

if you want to see a summary of all memory, use - t option, use this option will add a summary line in the output

    @-Laptop Ramesh Ramesh: -t ~ $ Free
                 Total Free Used Shared buffers cached
    Mem: 3,566,408 1,592,148 0 1.97426 million 204.26 thousand 912 556
    - / + buffers / Cache: 475 332 3,091,076
    Swap: 4,000,176 4,000,176 0
    the Total: 1,592,148 5974436 7566584

24. A Top

Top command displays the current system takes some process most resources (the default sort order CPU usage) If you want to change the sort, you can click in the results list O (uppercase letter O) shows all the columns for sorting, this time you select the column you want to sort

    Current the Sort Field,: P for window. 1: Def
    the select Via Sort Field Field Letter, type the any OTHER Key to return
      a: the PID = Process Id V: NDRT = Dirty Pages COUNT
      D: the UID = the User Id Y : WCHAN = Sleeping in Function
      E: the User the USER the Name = z: Flags = Task Flags
      ........

if a particular user processes only want to display, you can use the -u option

$ top -u oracle

more examples: Can You Top This? Top the Linux the Command Practical Examples 15
25. a DF

display file system disk usage, df -k output bytes will be used in an amount of disk default

$ DF -k
the filesystem 1K-Blocks used the Available the use% Mounted ON
/ dev / sda1 29.5304 million 3233104 24,797,232 12% /
/ dev / sda2 120 367 992 44% 50,171,596 64.08206 million / Home

use -h option to display disk usage in a manner more in line with the reading habits of

$ df -h
Filesystem Size Used Avail Capacity Mounted Iused iFree% Iused ON
/ dev / disk0s2 232Gi 84Gi 148Gi 37 % 21998562 38864868 36% /
100% 187Ki 187Ki 0Bi devfs 648 0% 100 / dev
Map -hosts 0Bi 0Bi 0Bi 100 100 0% 0% / NET
Map the auto_home 0Bi 0Bi 0Bi 100 100 0% 0% / Home
/ dev / disk0s4 466Gi 45Gi 421Gi 10% 112 774 440 997 174 % 0 / Volumes / the BOOTCAMP
//[email protected]/public 2.7Ti 1.3Ti 1.4Ti 48% 0% 0 18446744073709551615 / Volumes / public

-T option to display the file system type

$ DF -T
the filesystem the type-1K the Available Blocks used Mounted% ON the Use
/ dev / sda1 24,797,216 12 is 3.23312 million 29.5304 million ext4% /
/ dev / sda2 ext4% 120 367 992 50,171,596 44 is 64.08206 million / Home

26. A the kill

kill to terminate a process. Generally, we will first look for a process with ps -ef get its process ID, then use the kill -9 process ID to terminate the process. You can also use killall, pkill, xkill to terminate the process

$ PS -ef | grep vim
Ramesh 7243 7222 9 22:43 PTS / 2 00:00:00 vim

$


WC: Count
  -l: number of lines
  -w: Words
  -c : The number of characters

  wc -l file1 file2 ...... can count multiple files

cat to read text
  -n: display the line number
  -b: display the line number and ignores blank lines

  cat -n 1.txt

more display text each time a screen, press the space bar to continue
  the Find / -name "* .sh" | More

 

tail from a specified starting position behind the display was content
  tail -f server.log for the top server running while viewing the log
  tail -10 dos2unix. sh look at the last 10 lines of

 

head
  and tail correspond

with the "route -n" and "netstat -nr" command, we can view the default gateway. In addition to the default gateway information, these two commands can also display the current routing table.


Ifconfig 36. The

ifconfig is used to view and configure Linux systems network interface

View all network interfaces and their status

$ ifconfig -a

use the up and down commands to start or stop an interface

    $ ifconfig eth0 up
     
    $ ifconfig eth0 down

43. The less

this name displays the file without loading the entire file, viewing when large log files that can be very useful command

$ less huge-log-file.log

when you open a file with the less command, the following two buttons will give you a lot of help, for their forward and backward scroll

CTRL + F - Forward One window
CTRL + B - Backward One window


to see if the linux in a port (port) is occupied by
a use lsof

format:
1
    
lsof -i: port

for example, I want to see the 80-port occupancy can be used lsof -i: 80

you can clearly see that the port is occupied

NOTE: when should be noted that, lsof need to have permission to the process, parties can view, occupancy. For example, I use another user, you can not see the.

Current users will not see the name dequan process occupancy. If you are using nginx or root user on it, as follows:

Second, use netstat

format:
1
    
netstat -anp | grep Port

such as viewing occupancy 80, as follows:

Guess you like

Origin www.cnblogs.com/zhouwenfan-home/p/11323874.html