1. String Common commands:
Replace:
1). In%s/**/g, replace all the contents of the current interface with the rules.
2). Replace the contents of the string in the file:
Find-name ' filename to look for ' | Xargs perl-pi-e ' s| replaced string | replaced string |g '
3). Replace the strings in multiple folders:
Sed-i "s/original string/new string/g" ' grep original string-rl directory '
Statistics:
1). The number of rows in the statistics file that contain a string: Grep–c ' str ' filename//C is the meaning of count?
2). Number of occurrences of a string in the statistics file: Grep-o ' str ' filename | Wc–l//grep-o ' str ' means printing content that conforms to the rules, wc-l count rows
Find:
1). Find the specified string in the specified directory or file:
Find <directory>-type f-name "*.C" | Xargs grep "<strings>"
<directory> is the folder you are looking for and if the current folder can be omitted
-type F Description, find only files
-name "*.c" means only files that end in. c are found. Or you can not write, it means finding all the files.
<strings> is a string you're looking for
2). Text Open (Vi,more), enter the command:/, then enter what you want to find, press ENTER to start the search. Then press the N key to find the next.
2. file Handling Common commands:
1). Number of lines of Linux statistics file: WC [options] File
2). Empty the running file:
Cat/dev/null > FileName
Cp/dev/null filename//Seemingly more efficient, but not feeling. Prefer the first one.
3. Decompression and compression:
ZIP file: Unzip **.zip
Jar file: Jar-cvfm0 Game.war./0 This is the Arabic numeral, only packing does not compress the meaning
JAR-XVF Game.war extract to current directory
Tar file: When Linux hits the tar.gz package, there may be an error if there is a change in the file. Consider copying a copy before you hit the tar package.
TAR-CZVF **.tar.gz need to compress the file (folder) name//compress the file into the current directory.
Tar-czvf/mytest/**.tar.gz need to compress the file (folder) name//compress the file into the MyTest directory.
TAR-XZVF **.tar.gz//Unzip the file to the current directory
TAR-XZVF **.tar.gz-c Specify directory//Extract files to the specified directory, change to directory DIR
4. View directory and disk usage:
Du-sh dirname/file//view specified file or directory size, s:sum, H:human
Df–h//view each home directory capacity size
DU-SH * |sort-n//Calculates the size of files and folders in the current directory and sorts them. Collations are numbered by file size and do not contain units.
5. Date and time of modification:
# date-s "20131215 09:02:25"
Date Modified:
The order of the time set to May 10, 2009 is as follows:
#date-S 05/10/2009
Modification Time:
The command to set the system time to 10:18 A.M. 0 seconds is as follows.
#date-S 10:18:00
6. folder operation:
Copy: CP–IR/HOME/ABC/HOME/ABCD//R means recursive processing, and the files under the specified directory are processed together with subdirectories.
Mobile: MV/HOME/ABC/HOME/ABCD//MV command can be used to move and rename directories or files
Delete: RM-RF/HOME/ABC//Rm:remove; R:regular, recursive deletion; F:force coercion
NEW: Mkdir-p/HOME/ABC//P:parent, which indicates that if a parent directory is used or not, a new parent directory is created, which creates a multi-tiered directory.
Linux under Copy (CP) to current directory, current directory with "." Said. such as: Cp/app/test.txt.
7. Check the operation of the program:
1). Find out which program is consuming the most CPU by top
2). Find specific programs by Ps–ef|grep PID
3). kill-9 pid forced termination. (The standard KILL command usually achieves the goal.) Terminate the problematic process and release the resources of the process to the system. However, if a process initiates a child process, only the parent process is killed,
The child process is still running, so resources are still consumed. Kill-9 pid forced termination. )
8. set the ISO file to a Yum Source:
1). New directory: Mkdir–p/media/iso
2). Set the ISO to Yum Source:
Mount your-iso-file.iso/media/iso/-T Iso9660-o Loop
Or
Mount-t Iso9660-o Loop Your-iso-file.iso/media/iso
Note: iso9660 is a format
3). Edit a library script in the/ETC/YUM.REPOS.D directory, such as: Iso.repo, as follows:
[Rhel-source]
Name=iso
Baseurl=file:///media/iso
Enabled=1
Gpgcheck=0
Enabled=1: Enables the current Yum source, which is disabled if set to 0. The default value is 1.
Gpgcheck=1: Specifies whether to check the digital signature of the RPM package before installing the package in the Yum source, 1 for check, and 0 for no check.
4). Image offload: Umount/media/iso
9. operation between multiple servers:
1). Jump: SSH remote server IP
2). Copying files between servers:
SCP Local_file [Email Protected]_ip:remote_folder
Copying folders between servers:
Scp-r Local_folder [Email protected]_ip:remote_folder
Copying from a remote server to a local server
The SCP command from remote Copy to local is identical to the one above, as long as the 2 parameters are swapped sequentially after the command copied locally to the remote.
For example:
SCP [Email Protected]:/home/linux/soft/scp.zip/home/linux/others/scp.zip
SCP www.mydomain.com:/home/linux/soft/-r/home/linux/others/
Ten. firewall on and off:
Turn on firewall: Chkconfig iptables on
Turn off firewall: Chkconfig iptables off
All two of these commands must be restarted for the system to take effect.
If you don't want to take effect immediately by rebooting the system.
You can use the "service" command. The disadvantage is that the settings are lost after rebooting the system.
Turn on firewall: service iptables start
Shut down firewall: Service iptables stop
To set some ports in the firewall switch, you can modify the edit/etc/sysconfig/iptables file, such as open SSH Port 22, you can add the following:
-A rh-firewall-1-input-m state――state new-m tcp-p tcp――dport 22-j ACCEPT
One . Configure environment variables you can create a new *.sh file in/ETC/PROFILE.D that adds the contents of the configured environment variable. Generally do not modify the/etc/profile file.
such as java.sh:
Export Java_home=/usr/local/java/default
Export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/jt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib
Summary of Common Linux commands (i)