Linux common commands and Shell script programming __ Block chain

Source: Internet
Author: User
Tags comparison table delete key pack file permissions
Import public key to trust certificate
Keytool-import-file catserver.cer-keystore "$JAVA _home/lib/security/cacerts"-alias catserver


Remove Public key Alias
Keytool-delete-alias Catserver-keystore Cacerts-storepass Changeit


Remote Debugging Code
Export jvm_opt= "$JVM _opt-dosgi.console=33801"
Export jvm_opt= "$JVM _opt-xdebug-xrunjdwp:transport=dt_socket,address=****:33802,server=y,suspend=y"


Run Jar Pack in debug mode
JAVA-DOSGI.CONSOLE=33801-XDEBUG-XRUNJDWP:TRANSPORT=DT_SOCKET,ADDRESS=****:33802,SERVER=Y,SUSPEND=Y-CP *.jar * * *


SED command replaces file contents
Sed-i ' s?securerandom.source=file:/dev/random?securerandom.source=file:/dev/./urandom?g ' * * *


Restart the sshd service
/etc/init.d/ssh restart
/etc/init.d/sshd restart


JAR File Packaging
JAR-CVF Test.jar Com/bbb.class Aaa.class




To view port occupancy:
NETSTAT-NPL | grep * * * *


Find Files
Find/-name cacerts 2>/dev/null
Find Java Path
which Java


Ignore case when VIM lookup

The effect of items, when "\c" or "\c" work, what values they are set to be irrelevant.

Vim replacement
:%s/source/des/g
% represents the operation of each row
G represents replacing each match in a row


Set Linux machine hardware time
Hwclock--show Display Time
Hwclock--SYSTOHC Sync system time to hardware


Ubuntu Install and uninstall Deb Pack
sudo dpkg-i package name. deb
sudo apt-get Remove package name


Sync time
Client: Ntpdate IP
Server side: NTP


Add a public key to a machine
1. Modify/etc/ssh/sshd_config (Permissions and public key path)
2. Add. ssh folder permissions in the user's home directory 600
3. Add Authorized_keys file permissions under the. SSH folder 600






Linux history commands are not available
Vim/etc/profile
Set histsize=1000


To set the connection timeout time:
Vim/etc/profile
Set tmout=0


findstr usage under Windows (similar to grep in Linux)
Netstat-na | Findstr 12345


Output redirection
>>logs/root.log 2>&1 &


View Linux Version information
Cat/proc/version


Eclipse Set main function argument
Right--> Run as-> run configuration




Extract. xz files
Xz-d LINUX-3.1-RC4.TAR.XZ



Unzip the. tar file
TAR-XF Linux-3.1-rc4.tar



Unzip. tar.gz to the specified folder
Tar-xzf jre-8u144-linux-x64.tar.gz-c/usr/lib/java '


Compress to get. tar.gz files
TAR-CZF all.tar.gz *.jpg



Note:
When extracting files, folders are merged, file is overwrite operation
When you get a compressed file, it's a complete overwrite operation.
Same with CP command, folder is merge operation, file is overwrite operation




Shell script programming-arithmetic operations
Val= ' Expr 2 + 2 '




Output redirection
>>logs/root.log 2>&1 &
Echo Output lost line feed
To preserve line breaks, use the following command to note that double quotes must not be less
echo "${foo}"




Reboot machine:
Reboot




Exit script Run
Exit 0




If Else statement usage:
If ["$yesResult"!= ""];then
Break
elif ["$noResult"!= ""];then
echo "1"
elif ["$unknownResult"!= ""];then
echo "2"
echo "${unknownresult}"
Exit 0
Else
echo "4"
echo "${out}"
Exit 0
Fi


While statement usage:
While "true"
Todo
........
Done




For statement usage + Find a process by name and close all processes:
Processcount=0
For ProcessID in ' Ps-ef | grep xxx |grep java | awk ' {print $} '
Todo
Processcount= ' expr $processCount + 1 '
out= ' Kill $processId '
Done


For Increment loop
For ((i=0;i<10;i++))
Todo
echo "$i"
Sleep 0.1
Done




Invalid shell command line press DELETE key
Stty Erase ' ^h '




Check and install the Java environment
#install JRE Environment
ECHO-E "\nchecking java environment ..."
String= ' java-version 2>&1 |awk ' nr==1{gsub (/"/," "); print $} '
Version= ' java-version 2>&1 |awk ' nr==1{gsub (/"/," "); print $} '
if [$string = = Version]; Then
Echo-e "Java exist! version--$version \ n "
Else
echo "Java Environment not found,installing ..."
#make a floder and discard stderr output
out= ' Mkdir/usr/lib/java 2>/dev/null '
#unzip the file
out= ' tar-zxf jre-8u144-linux-x64.tar.gz-c/usr/lib/java '


out= ' update-alternatives--install/usr/bin/java java/usr/lib/java/jre1.8.0_144/bin/java 2>/dev/null 1>/ Dev/null '
Echo-e "Install Java succeed!\n"
Fi


Get the location that the linked file points to
Readlink-f


awk Set Separator
Awk-f '/bin/java ' {print $} '




When you call another script in a script, the input is passed directly behind the arguments.
The called script can be used for more than $10 with ${10} (starting from 1, no $)




Script sleep:
Sleep 5 (in seconds, can have decimal points, such as 0.1)


Xftp Show hidden folders
Open: Tools-"Options-" There is a "Show hidden files" option, on the hook.


Linux Show hidden folders
CTRL + H


Recursively modify users and user groups
Chown-r Ossuser:ossgroup./


Vim modifies the file format:
: Set Ff=unix


Shell grep uses regular expressions
such as grep ". *aaa" for characters that end with a


Automatically stop input to file every 1s loop greater than 100
Count=1
While "true"
Todo
Count= ' expr $count + 1 '
echo "$count" >> test____ ^_^ ____.txt
Sleep 1
Done




Set xftp default override
Tool-> Option-> Transport-> Advanced options-> overwrite file to change upload download to overwrite



Nohup./test.sh & Solve the problem whether the original process (script, or Java program, or other) is still executing, the script will continue to execute
If you do not use (Nohup./test.sh &) This type of writing, if the previous process completes normally, the script that the process opens can execute normally, but if the process is killed, then the startup script will be terminated.
For example, the Process.waitfor () was used, and the process of waiting for the end was killed.


When invoking the up script in Java code to execute another ST script
ST has echo-e this syntax when the statement behind the print log does not normally output to log files
In the up.sh, out= './st.sh ' was not written in a way that st.sh was unable to perform successfully, without knowing why.


Ubuntu setup software to run the Jar pack automatically


There are two rc.local files. The/etc/init.d/rc.local file will call the/etc/rc.local file when the system starts. Typically, the startup content is placed in the/etc/rc.local file


Directory-related information is not known when executing script files in other directories in script rc.local, but it may be necessary to use relative paths when executing scripts. This can be done to invoke/home/copbint/test/start.sh as an example:


Sed-i '/sleep && d '/etc/rc.local
hasexit= ' cat/etc/rc.local | grep "^exit 0$"
If ["$hasExit" = ""];then
echo "Sleep &&/bin/bash/home/copbint/test/start.sh" >>/etc/rc.local
Else
Sed-i ' \#^exit 0$ #i sleep &&/bin/bash/home/copbint/test/start.sh '/etc/rc.local
Fi
To explain in a unit of behavior:
1. Delete before execution to prevent repeated additions when this command is repeated repeatedly
2. Confirm that there are ^exit 0$,^ in the script that represent the line start, $ for the line terminator, and filter out exit 0 in the comment.
4. If there is no ^exit 0$ in the script. Append content directly to the script.
6. If there are ^exit 0$ in the script. Inserts a row before the row. This is the use of the SED command. Unfamiliar can refer to: Linux sed command usage examples




Also, note the following two types of errors: |
#i can not be followed by the #, will be entered as normal characters:
Sed-i ' \#^exit 0$ #i #sleep &&/bin/bash/home/copbint/test/start.sh '/etc/rc.local
The last side of the command cannot be followed by a #, which is entered as a normal character:
Sed-i ' \#^exit 0$ #i sleep &&/bin/bash/home/copbint/test/start.sh# '/etc/rc.local



Use expect to automatically remotely log in and execute commands (you need to perform the sudo apt-get install command to install first


#!/usr/bin/expect
Set Timeout 5
#set username [lindex $argv 0]//Save script parameters to variable
#set Password [lindex $argv 1]
#set hostname [lindex $argv 2]
Spawn ssh xxxx@127.0.0.1
Expect {
"(yes/no)?"
{
Send "yes\n"
Expect "Password:"
Send "xxxxx\n"
}


"Password:"
{
Send "xxxxx\n"
}
}


Expect "~"
#sleep 0.5
Send "cd/home/xxxx/test\n"
Expect "~"
#sleep 0.5
Send "echo ' Date ' >> haha.txt\n"


Interact

Encountered a big pit is, the outermost expect of the curly braces I changed lines, resulting in the password can not be automatically entered. have been unable to find the reason, and finally control the other people's script to try to find the wrong here, do not know what the rules behind this. But the inner layer of the expect can be changed line.
A little experience:
In fact, the working principle of expect is to monitor the server sent back messages, or to the shell of the content, although do not know at what level to do the capture. Prompt information on the screen, such as "xxx@ubuntu:~/test$", is returned from the server side. So if expect captures the desired content, you know that you can continue to send the next command with the Send command for the server to execute.
So there is a way of violence, directly after each of the commands to send a certain amount of sleep, without expect, in general, the server can normally execute the command. Of course, violence is not elegant enough, and it may not guarantee accuracy.
The role of interact is to give the user the right to interact. If the end of the script does not add interact, the connection is turned off, and closing the connection may be higher than the precedence of the command execution, which may result in some of the last commands not being executed, so it is possible to sleep at a certain time after the last command so that all commands are properly executed.



View file or folder size

Du-sh


String transcoding ASCII code
printf "%d\n" "' A '"


Construct an ASCII code comparison table
echo "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZaccdefghijklmnopqrstuvwxyz" >a.txt;od-t d1c a.txt















Related Article

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.