Five Commands and tools not unknown to Linux Administrators

Source: Internet
Author: User

BKJIA has many useful tools for Linux administrators. Here, I will only list five of the tools used by Linux administrators for routine operations. In my opinion, the most powerful tools may not be suitable for your use, and I forgot to count them. If so, I urge you to write out the tools I did not include in your comments. In addition, the tools mentioned in this article are only for selection. Not everyone needs them. The tools that are not mentioned do not mean that Linux administrators do not need to use them, such as SSH, SCP is a tool that every Linux administrator must use and has no other options.

#5. head/tail command

In most cases, the only purpose of logging on to the server is to diagnose certain problems. The general method is to view logs. Logs of different application types, such as Apache logs, MySQL logs, and mail logs. So what Command do you use to view logs? Isn't it tail? This is actually similar. Sometimes we can use the "head" command to view the first few lines of a file.

Examples:

 
 
  1. * To continuously check the Apache Error Log File, run the following command:
  2.  
  3. $ Tail-f/var/log/httpd/error_log
  4.  
  5. * To view the first 15 lines of MySQL logs, run the following command:
  6.  
  7. $ Head-15/var/log/mysqld. log
  8.  

#4. vi/nano/emacs Tool

Generally, text editors are frequently used to create/update configuration files. I prefer vim and it is very comfortable to use. It is easy to remember some of its quick edit commands.

Below are several examples of using vi. Open a file with vi without entering the insert mode), you can enter the following useful characters:

 
 
  1. => Jump to the end of the row
  2. $
  3. => Jump to the beginning of the line
  4. 0
  5. => Delete the remaining rows
  6. D
  7. => Repeat the previous command
  8. . (Point)
  9. => Add "maal" to the end of each line ". 1 indicates the first line, $ indicates the last line
  10. : 1, $ s/$/maal/
  11. => Add "bingo" at the beginning of the row between 5 and 10"
  12. : 5, 10 s/^/bingo/
  13. => If foo appears in the file content after the cursor, replace it with bar
  14. : S/foo/bar/g
  15. => Delete the row and enter the insert mode.
  16. C
  17. => Remove ^ M from the windows System File
  18. : Se ff = unix
  19. => Enable/disable row display
  20. : Set nu
  21. : Set nonu
  22. => Display the actual number of rows in the file
  23. : %! Cat-n
  24. => Locate words under the cursor
  25. * (Asterisk)
  26.  

#3. screen command

In the nix world, the screen command is not fully utilized. For example, when you run a command on the remote server for the last time, if you find that the command takes several hours to complete, or when you need to log on to 10 servers, check for items, and copy files between them, your Internet connection suddenly restarts, And the ssh session also ends, you will use the screen command, and once you start using this command, you will be attracted to it. Screen is a terminal multiplexer) that allows you to manage multiple processes, such as ssh sessions, by using a physical terminal ). Each process has its own virtual window, and you can switch back and forth between the virtual Windows that interact with each process.

Let's explain it in depth. Suppose you have many servers. Ideally, you should put ssh port 22) on a specific IP address. In this way, you can log on to a server that allows remote IP Access. In this case, you can type "screen" and install the screen command in all major linux versions. You will see a status bar. You can press Ctrl + ac to create a new screen window. Use Ctrl + an (next) and Ctrl + ap) to switch between windows. Generally, it provides very useful functions, such as remote terminal session management isolation or sharing terminal sessions). The number of unlimited windows is different from the number of fixed Linux virtual consoles ), copy/paste between windows, show activity or static in the window, split the terminal into multiple zones horizontally and vertically), and share the terminal among others.

You can save your parameters in. in the screenrc file, the following is my. like the screenrc file, I have redefined the appearance and feeling of the status bar and set the key f5 to a window) and f6 to the next window:

 
 
  1. $ Cat ~ /. Screenrc
  2. # Please do not have annoying ringtones
  3. Vbell on
  4.  
  5. # Separation during suspension
  6. Autodetach on
  7.  
  8. # Do not display the copyright page
  9. Startup_message off
  10.  
  11. # Imitating. logout messages
  12. Pow_detach_msg "Screen session of \ $ LOGNAME \ $: cr :\$: nl: ended ."
  13.  
  14. # Tertertermcap hard status window list and clock) supported
  15. Termcapinfo xterm * ti @: te @
  16.  
  17. # Set the shell in each window to the logon shell
  18. Shell-$ SHELL
  19.  
  20. Defscrollback 10000
  21.  
  22. # Extend the vt100 description according to a sequence
  23.  
  24. Termcap vt * AF = \ E [3% dm: AB = \ E [4% dm
  25. Caption always
  26. Caption string '% {= wk} [% {k} % H % {k}] [% = % {= wk} %? %-Lw %? % {R} (% {r} % n * % f % t %? (% U) %? % {R}) % {k} %? % + Lw %? %? % = % {K}] [% {B} % d/% m % {k} % c % {k}]'
  27.  
  28. # Redefinition of Key Binding
  29.  
  30. Bind-k F5 prev
  31. Bind-k F6 next
  32.  

#2. netstat/nmap command

These two commands are very useful for diagnosing network problems. Of course, ping/traceroute may be the most commonly used command, but if it is more effective, the nmap and netstat commands are more useful than the basic ping commands. Netstat can display the network status. Nmap is a security/port scanner, or a network exploration command.

An example of netstat is as follows:

 
 
  1. * Display all Internet ports 80) Number of connections:
  2. $ Netstat-an | grep: 80 | wc-l
  3. * Display all listening ports on the machine:
  4. $ Netstat-ant | grep LISTEN
  5. * Scan a machine using the nmap command on your LAN and learn which ports are open:
  6. $ Nmap ip
  7.  

#1. find and grep commands

Problems encountered in daily work include: How many files occupy most of the disk space? Hosts file. In the face of these jobs, the command find and grep will be your best friend.

The Find command is used to search for files. You can specify many options, such as the file creation date or the file size must be greater than the specified capacity. Generally, we also use find in combination with xargs or exec to execute the command on the file returned by the find command.

Example of the find command:

 
 
  1. * Search for the 10 largest files in the/var directory:
  2. $ Find/var-type f-ls | sort-k 7-r-n | head-10
  3.  
  4. * Search for files larger than 5 GB in/var/log:
  5. $ Find/var/log/-type f-size + 5120 M-exec ls-lh {}\;
  6.  
  7. * Search for all today's files and copy them to another directory:
  8. $ Find/home/me/files-ctime 0-print-exec cp {}/ mnt/backup /{}\;
  9.  
  10. * Find and delete all temporary folders that have exceeded one week:
  11. $ Find/temp/-mtime + 7-type f | xargs/bin/rm-f
  12.  
  13. * Find and rename all mp3 files and convert the uppercase letters in the file name to lowercase letters ):
  14. $ Find/home/me/music/-type f-name *. mp3-exec rename 'y/[A-Z]/[a-z]/''{} '\;
  15.  
  16. Some examples of the grep command:
  17. * Print the name of the Apache file root directory:
  18. $ Grep-I documentroot/etc/httpd/conf/httpd. conf
  19.  
  20. * View the content of files without comments and empty rows:
  21. $ Grep-Ev "^ $ | ^ #"/etc/my. cnf
  22.  
  23. * Print only the IP addresses assigned to this interface:
  24. $ Ifconfig eth0 | grep 'inet addr: '| cut-d':'-f2 | awk' {print $1 }'
  25.  
  26. * View the number of email messages sent on a specific date:
  27. $ Cat/var/log/maillog | grep "status = sent" | grep "May 25" | wc-l
  28.  
  29. * Find a running process/daemon in the process list. Thanks to staranneph ):
  30. Ps-ef | grep mysql
  31.  
  32. * You can also use the preceding command to comment out cpu/men usage, such as the following command output, as you can see, the statistical process of Plesk occupies more than 18% of the cpu performance:
  33. [Root @ myserver ~] # Ps aux | grep statistics
  34. Root 8183 18.4 0.0 58384 2848? D/usr/local/psa/admin/sbin/statistics
  35.  

Original article: Top 5 most useful commands or tools for Linux administrators Author: Linux Admin Zone

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.