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:
- * To continuously check the Apache Error Log File, run the following command:
-
- $ Tail-f/var/log/httpd/error_log
-
- * To view the first 15 lines of MySQL logs, run the following command:
-
- $ Head-15/var/log/mysqld. log
-
#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:
- => Jump to the end of the row
- $
- => Jump to the beginning of the line
- 0
- => Delete the remaining rows
- D
- => Repeat the previous command
- . (Point)
- => Add "maal" to the end of each line ". 1 indicates the first line, $ indicates the last line
- : 1, $ s/$/maal/
- => Add "bingo" at the beginning of the row between 5 and 10"
- : 5, 10 s/^/bingo/
- => If foo appears in the file content after the cursor, replace it with bar
- : S/foo/bar/g
- => Delete the row and enter the insert mode.
- C
- => Remove ^ M from the windows System File
- : Se ff = unix
- => Enable/disable row display
- : Set nu
- : Set nonu
- => Display the actual number of rows in the file
- : %! Cat-n
- => Locate words under the cursor
- * (Asterisk)
-
#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:
- $ Cat ~ /. Screenrc
- # Please do not have annoying ringtones
- Vbell on
-
- # Separation during suspension
- Autodetach on
-
- # Do not display the copyright page
- Startup_message off
-
- # Imitating. logout messages
- Pow_detach_msg "Screen session of \ $ LOGNAME \ $: cr :\$: nl: ended ."
-
- # Tertertermcap hard status window list and clock) supported
- Termcapinfo xterm * ti @: te @
-
- # Set the shell in each window to the logon shell
- Shell-$ SHELL
-
- Defscrollback 10000
-
- # Extend the vt100 description according to a sequence
-
- Termcap vt * AF = \ E [3% dm: AB = \ E [4% dm
- Caption always
- Caption string '% {= wk} [% {k} % H % {k}] [% = % {= wk} %? %-Lw %? % {R} (% {r} % n * % f % t %? (% U) %? % {R}) % {k} %? % + Lw %? %? % = % {K}] [% {B} % d/% m % {k} % c % {k}]'
-
- # Redefinition of Key Binding
-
- Bind-k F5 prev
- Bind-k F6 next
-
#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:
- * Display all Internet ports 80) Number of connections:
- $ Netstat-an | grep: 80 | wc-l
- * Display all listening ports on the machine:
- $ Netstat-ant | grep LISTEN
- * Scan a machine using the nmap command on your LAN and learn which ports are open:
- $ Nmap ip
-
#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:
- * Search for the 10 largest files in the/var directory:
- $ Find/var-type f-ls | sort-k 7-r-n | head-10
-
- * Search for files larger than 5 GB in/var/log:
- $ Find/var/log/-type f-size + 5120 M-exec ls-lh {}\;
-
- * Search for all today's files and copy them to another directory:
- $ Find/home/me/files-ctime 0-print-exec cp {}/ mnt/backup /{}\;
-
- * Find and delete all temporary folders that have exceeded one week:
- $ Find/temp/-mtime + 7-type f | xargs/bin/rm-f
-
- * Find and rename all mp3 files and convert the uppercase letters in the file name to lowercase letters ):
- $ Find/home/me/music/-type f-name *. mp3-exec rename 'y/[A-Z]/[a-z]/''{} '\;
-
- Some examples of the grep command:
- * Print the name of the Apache file root directory:
- $ Grep-I documentroot/etc/httpd/conf/httpd. conf
-
- * View the content of files without comments and empty rows:
- $ Grep-Ev "^ $ | ^ #"/etc/my. cnf
-
- * Print only the IP addresses assigned to this interface:
- $ Ifconfig eth0 | grep 'inet addr: '| cut-d':'-f2 | awk' {print $1 }'
-
- * View the number of email messages sent on a specific date:
- $ Cat/var/log/maillog | grep "status = sent" | grep "May 25" | wc-l
-
- * Find a running process/daemon in the process list. Thanks to staranneph ):
- Ps-ef | grep mysql
-
- * 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:
- [Root @ myserver ~] # Ps aux | grep statistics
- Root 8183 18.4 0.0 58384 2848? D/usr/local/psa/admin/sbin/statistics
-
Original article: Top 5 most useful commands or tools for Linux administrators Author: Linux Admin Zone