I haven't written a blog for a long time, I hope the following content can help my colleagues! ! !
Common shortcut keys:
Ctrl+a: The cursor returns to the beginning of the command line. (a: ahead)
Ctrl+e: The cursor returns to the end of the command line. (e: end)
Ctrl+b: Move the cursor one character to the beginning of the line. (b: backwards)
Ctrl+f: Move the cursor one character to the end of the line. (f: forwards)
Ctrl+w: Delete the characters from the cursor to the beginning of the line.
Ctrl+k: Delete the characters from the cursor to the end of the line.
Ctrl+u: Delete entire command line text characters.
Ctrl+h: Delete a character to the beginning of the line.
Ctrl+d: Delete one character to the end of the line.
Ctrl+y: Paste Ctrl+u, Ctrl+k, Ctrl+w deleted text.
Ctrl+p: The last used history command. (p: previous)
Ctrl+n: The next historical command used. (n: next)
Ctrl+r: Quickly retrieve historical commands. (r: retrieve).
Ctrl+t: Swap the character under the cursor with the character before it.
Ctrl+i: Equivalent to the Tab key.
Ctrl+o: Equivalent to Ctrl+m.
Ctrl+m: Equivalent to the Enter key.
View command help
man [command name]
For example: man date
Check what command interpreter the current linux system belongs to
echo $SHELL
View the current system time
date "+%Y-%m-%d %H:%M:%S" date format is accurate to hours, minutes and seconds
date "+%j" today is the day of the year
View current network status and configuration
ifconfig
View current system kernel version information
uname -a
Current system memory usage information
free -m statistics in units of "megabytes" -k statistics in units of "kilobytes"
View all login records of the system
last -2 linux -d -a View the two login records of linux users and convert the login ip to the host name and display it in the last column
View the command record used by the current user
history
Or open the log file of the current user's home directory
cat ~/bash_history
Working directory switch
cd - change to last working directory
cd ~ Change to the current user's home directory
cd ~user switches to another user's home directory
pwd get the current directory
cd .. go back to the previous directory
View current folder files
ls -al View detailed information of all files in the current folder
ls -dl information about the current folder
ls -format pass* Get all file information starting with pass
How to find a directory under the current folder
ls -F | grep '/$' Add entry indication and search for directories starting with "/", all directories end with "/"
ls -l|grep "^d" Query the detailed information of the file, the query starting with d will be queried, and a d letter will be added at the top when viewing the directory details
find . -type d -maxdepth 1 Find all directories (including hidden directories) at the first level of the current directory
Quick way to clear files
echo > filename
echo "" >filename
: > filename
View text files (shorter)
cat -n filename displays line numbers
cat -b filename displays line numbers, excluding blank lines
cat -nA filename displays line numbers and invisible special symbols
Used to view plain text documents (longer), specific options to view the help documentation of the command
more can only be used to turn pages backwards and not forwards, and less can be used to turn pages forwards and backwards
head View from scratch
tail View from the end
less can turn pages back and forth more suitable than more
View specially formatted files
from
Convert a set of characters in a text file cat text view command already | pipe command character
cat filname.txt | tr [az] [AZ] Convert all characters in the text to uppercase and output
Count the number of lines, bytes, and characters of the specified text
wc -c filename.txt count bytes
wc -m filename.txt count characters
wc -l filename.txt count the number of lines of text
Show all users of the current system
cut -d: -f1 /etc/passwd
Create text file
touch test.txt
Create folder
mkdir directory --- mkdir command can only create folders
delete file information
rm -rf filename recursively delete all files including subfiles, directories, etc.
rm -rf aa[12] delete files with 1 or 2 after aa
rmdir filename only deletes empty directories, i.e. directories that do not contain files
Modify file permissions
chmod u+x filename add the current file owner executable permission
chmod g+x filename Add the executable permission of the group to which the current file belongs
chmod o+x filename adds the file owner and other groups and users executable permissions other than the group to which the file belongs
chmod ux filename removes the executable permission of the current file owner
Change file owner
chown user1 filename specifies that the owner of the file is user1
chown user1:group filename Modify the owner of the file to user1 and change the group to which the file belongs to group
chown -hR user1 filename Modify the owner of the file (if it is a folder, including all its subfolders and files) to be user1
Compare the difference between two files
diff fileName1 fileName2
Copy files recursively
cp -r filename1 filename2
Add a new user (home directory, uid, specify bash, etc.)
useradd -d /home/user1 -u 123 -s /bin/bash user1
Modify user password and view user password status
passwd user change password
passwd user -S View user password status
Delete the user and delete the user's home directory, mail directory
userdel -rf user
Modify user information
usermod -c i'm first user Modify user remarks
usermod -dm /home/first_user user The directory data before modifying the user's home directory will also be migrated
Compressed file
tar -czvf aa.tar.gz documents/aa
Unzip the file to a directory
tar -xzvf aa.tar.gz -C / directory
Search for how many times a character appears in a text (multiple times on the same line)
grep -n /sbin/nologin /etc/passwd
Search for text containing a character and append it to another text file
grep you hello.txt >> test.txt
Pipe command character "|": use the current output as the input of the second command
ls -l format pass * | wc -l
Redirection (input and output redirection) command characters (">>", "<<"):
Output redirection:
grep -n nologin passwd > /root/Documents/test.txt Output the user information that cannot be logged in to the text of test.txt and overwrite it
grep -n nologin passwd >> /root/Documents/test.txt Append non-login user information to the end of test.txt without overwriting
Input redirection:
grep -n you < hello.txt >test.txt takes the text hello.txt as input into the grep command and redirects the output of the grep search to the test.txt file
User's mail directory address:
/var/spool/mail/linux (username)
Enter the mail command under the current user to view the received mail
View email content
cat /var/spool/mail/linux (username)
Read in the new password from the standard input pipe
echo "hello123"|passwd --stdin user
Description of escape symbols:
\ (backslash): escape the following single character
'' (single quote): Escape all characters within quotes
"" (double quotation marks): Variables quoted in quotation marks are still valid
`` (backtick): execute the command statement enclosed in quotation marks
set command alias
alias cp=" cp -i"
alias for cancel command
unalias cp
View the path variable
echo $PATH
Set environment variables, each variable is separated by a colon
PATH=$PATH:/bin
View environment variables in the system
env
add environment variable
env cur=/home/tomcat/bin
delete environment variable
env -u cur
Promote variable to global variable
export cur --- Execute under superuser
which: find which path a command is in, such as which cp or which java
whereis: where to look for files e.g.
vim editor
When the document is being edited and not saved, a hidden file of ".filename.swap" will be generated to lock the current file and maintain the consistency of the file. You can delete the file to unlock it and edit the file again.
command line mode
dd delete the line where the cursor is located
5dd deletes five lines starting with the line where the cursor is located
yy Copy the line where the cursor is located
5yy Copy the five lines starting from the line where the cursor is located
p lines deleted or copied before pasting at the cursor
/string Search string string, from top to bottom
?String search string string, bottom to top
n Displays the next string under the search command
N displays the previous string under the search command
u undo the previous operation
last line mode
:w save current changes
:wq save and quit
:wq! Force save and quit
:q! Force quit
:q quit
:set nu display line number
:set nonu don't show line numbers
: command to execute the command
: integer jump to the line
Modify hostname
vim /etc/hosts -- modify the file hostst through the vi editor
Configure network card information
Directory: /etc/sysconfig/network-scripts
For REHEL6 NIC configuration files are prefixed with ifcfg-eth eg ifcfg-eth0
Prefix ifcfg-eno for REHEL7 NIC configuration files such as ifcfg-eno16777736
Step 1: vim ifcfg-eth0 Use vim to edit the network card information in the configuration file
Step 2: Restart the network card with the command "systemctl restart network"
Step 3: Use "ping ip address" to check whether the network card configuration takes effect
yum software repository configuration file directory
etc/yum.repos.d/
List all software repositories
yum repolist all
list all packages
yum list all
show package information
yum info package name
Package installation, reinstallation, upgrade, removal
yum install package name
yum reinstall package name
yum update package name
yum remove package name
System critical directory or file
1. System configuration etc/syscofig
1.1 Network configuration etc/sysconfig/network-scripts
2.yum software repository configuration etc/yum.repos.d
2.1 yum software repository configuration file *.repo
3. User password related information file etc/passwd
4. All shell interpreter information files in the system etc/shells
5. User account and UID information etc/passwd
6. User password information etc/shadow
7. Group name and GID etc/group
Three ways to execute scripts
1. Script path: ./example.sh When executed in this way, the value of $0 is the file path "./example.sh"
2. sh script path: sh example.sh When executed in this way, the value of $0 is the file path "example.sh"
3. Source script path: source example.sh When executed in this way, the value of $0 is the file path "bin/bash"
Note: The newly created script generally does not have execution permission for the current creator or file owner, you need to add execution permission for the current user chmod u+x example.sh
Notes on writing scripts
1. When assigning a variable name, there must be no spaces on the left and right sides of the equal sign ("=").
2. When using expressions to calculate, there must be spaces on the left and right sides of the calculation symbol
3. When using conditional expressions, there must be a space between the brackets and the expression
Script incoming parameter related value description
$0 represents the current script name, the name varies depending on the execution method
$1 $2 represents the first and second parameter values that are currently passed in, and so on
$# indicates the number of parameters currently passed in
$* lists the values of all incoming parameters in sequence
$? Determines whether the previous command was executed successfully. 0 means successful execution, non-0 means failure
File judgment conditional format: [ -d filename ] If the output result is 0, it means that it is true, and other non-zero numbers indicate that it is not true.
1. -d to determine whether it is a directory
2. -f to judge whether it is a file
3, -e to determine whether the file or directory exists
4, -r to determine whether the file or directory is readable
5. -w determines whether the file or directory is writable
6, -x to determine whether the file or directory is executable
Declare a variable and copy the result of the command statement to the variable. The outermost statement uses backticks to indicate the execution of the command statement, and single quotes are used to escape all characters within the quotes.
FreeMan=`free -m|grep cache:|awk print '{print $3}'`
output variable value
echo $FreeMan
Integer value comparison format: [ number 1 operator number 2 ]
1, -gt to judge whether it is greater than
2, -lt to judge whether it is less than
3. -eq to judge whether it is equal to
4, -ne to judge whether it is not equal to
5. -ge to judge whether it is greater than or equal to
6. -le to judge whether it is less than or equal to
String comparison format: [ string 1 operator string 2 ]
1, = means that the contents of the strings are equal
2. != means that the contents of the strings are not equal
3. -z means the string is empty [-z "" ] Return the number 0 means the string is empty
Conditional statement format:
1. If conditional statement:
if condition 1 then
echo "do something"
elif condition 2 then
echo "do another thing"
else
echo "do final thing"
be
2. For loop statement:
for item in `cat user.txt`
do
echo "$item is my name"
done
3. While statement:
while condition
do
echo "do something"
done
4. case statement
File type (the first permission bit represents):
-: Indicates a normal file
d: Represents a directory file
l: indicates the link file
b: Represents a block file
c: Represents a character device file
p:pipe file
Assign user input parameters to variables: read -p prompt statement variable name
read -p "enter you score(0-100):" GRADE
Expression calculation (addition, subtraction, multiplication and division, take substrings according to regular rules, see "expr" for details) Command format: expr a1 + a3 Value $(expr a1 + a2)
Some special characters such as * indicate that the multiplication needs to be enclosed in single quotes '', which are expressed as escape characters
1. Add: echo $(expr 100 + 100)
2. Multiply: echo $(expr 100 '*' 100)
3. Take the length of the string: echo $(expr length "rere")
Su command and sudo service: sudo command is more conducive to system security management than su command
switch user
su - user name switch and switch environment variables at the same time
su username only switches users without switching environment variables
Use sudo service to make normal user execute superuser cat command
1. Use the visudo command to edit the configuration file of the sudo program (etc/sudoers)
2. Add the configuration linux ALL=(root) /bin/cat to the configuration file to indicate that linux users can execute the cat command as root on all hosts
3, similar to the vi editor method to save and exit
4. Switch to the linux user and use sudo -l to view the commands executed by sudo that the current user (linux) can execute.
5. Use the cat command to open files that can only be viewed by the root user. For example: cat etc/shadow
A user can execute arbitrary commands as arbitrary without authentication:
linux ALL=NOPASSWORD:ALL
User executes cat and ls commands as root
linux ALL=(root) /bin/cat /bin/ls
file access control list
Set the operation permission of the specified user or team for a specified file
For example, add a rule that the user linux corresponds to the root directory with rwx permissions
setfacl -Rm user:linux:rwx /root/
delete rule
setfacl -Rb /root/
View the ACL rules of the root file
getfacl /root/
redhat input method installation
1. Download the rpm of the input method (fcitx-3.0.0-1.i386.rpm)
2. Clear the local input method rpm -e miniChinput
3. Install rpm -ivh fcitx-3.0.0-1.i386.rpm
4. Enter the directory cd usr/bin
5. Execute the command ln -sf fcitx chinput
Redhat9 installation insert Chapter 2 iso can not be mounted problem: select the virtual machine of the currently installed system - "right click - "settings - "edit the hardware image of the cd/dvd as the second iso file and check the two device states (already connect, connect at startup)
question:
1. The command "systemctl restart network" to restart the network card fails
2. The yum warehouse configuration has not been implemented
3. Timed tasks have not been practiced
Configure the redis service:
cp /usr/local/redis-2.8.9/utils/redis_init_script /etc/rc.d/init.d/redis
Copy redis_init_script to /etc/rc.d/init.d/ and rename it to redis
then vi /etc/rc.d/init.d/redis
Add on the second line of the document
# chkconfig: 2345 80 90
then notice
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
Because our installation directory is /usr/local/redis-2.8.9, the above two lines are changed to
EXEC=/usr/local/redis-2.8.9/src/redis-server
CLIEXEC=/usr/local/redis-2.8.9/src/redis-cli
Also pay attention to the redis file
$EXEC $CONF
Here, add & after CONF
$EXEC $CONF &
"&" means that the service is transferred to the back to run, otherwise, when the service is started, the Redis service will occupy the foreground, occupying the main user interface, and causing other commands to fail to execute.
4. You can see that in the /etc/init.d/redis file, there is such a line:
CONF="/etc/redis/${REDISPORT}.conf"
So copy the redis configuration file to /etc/redis/
mkdir /etc/redis
cp /usr/local/redis-2.8.9/redis.conf /etc/redis/6379.conf
5. Configure the access password in 6379.conf
Find the line #requirepass and rewrite it to requirepass with the new password (eg 123)
6. By default, redis only allows local access. Commenting out bind 127.0.0.1 means that all ips are accessible
5. After completing the above operations, you can register the service:
chkconfig --add redis
Set up to start automatically
chkconfig redis on
Then start the redis service
service redis start
Redis can run as a service.
After configuring redis, to be able to access from the outside, you need to close the firewall and configure the client password or bind an accessible user ip
Turn off the firewall:
1.chkconfig /etc/init.d/iptables stop then restart linux
2. Open the redis client in linux to set the password
Start the server: redis installation directory/src/redis-cli
Set the server password: config set requirepass 123
The redis address is already using the solution:
Find the redis process: ps -aux | grep redis The process id obtained is assumed to be 3038
Kill the process: kill -9 3038
Configure, install and uninstall jdk
Install jdk:
1. Download jdk wget http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.rpm
2. Install rpm -ivh jdk-8u121-linux-x64.rpm
3. The default installation is under the /usr/java/ path
Configure jdk environment variables
1.vi /etc/profile
2. Add the following 3 lines
export JAVA_HOME=/usr/java/jdk-8u121
export CLASSPATH-.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
3. Execute the command java -version to verify that it is installed correctly
Uninstall jdk:
1. Go to the directory cd /usr/bin
2. Establish a synchronous link in another directory for the two executable programs of java and javac
ln -s -f /usr/java/jdk-8u121/bin/javac
ln -s -f /usr/java/jdk-8u121/jre/bin/java
3. Check the jdk-8u121 package name: rpm -qa | grep jdk to get the package name jdk-8u121-fcs.i586
4. Execute the uninstall command rpm -e jdk-8u121-fcs.i586 (the package name just obtained)
Installation and configuration of tomcat (provided that jdk is installed and configured correctly):
1. Download tomcat to the /usr directory wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.11/bin/apache-tomcat-8.5.11.tar.gz
2. Unzip tar -xvf apache-tomcat-8.5.11
3. Start the tomcat service
Method 1: tomcat directory /bin/startup.sh
Method 2: Modify the directory name and start the service in the new directory mv apache-tomcat-8.5.11 tomcat Start the service: tomcat/bin/startup.sh
Method 3: Use ln to synchronize the link ln -s /usr/apache-tomcat-8.5.11/ /usr/tomcat Start the service: tomcat/bin/startup.sh
Add tomcat as a linux service to start automatically with boot
1. Copy the tomcat installation directory /bin/Catalina.sh to the directory /etc/init.d/ and set the name to tomcat8 (change the name to the service name) Execute the command: cp tomcat installation directory /bin/Catalina.sh / etc/init.d/tomcat8
2. Edit the script tomcat8 just now and add the relevant configuration
Add content 1: Insert after the third line of the script (service run level, start priority, stop priority, must add #) #chkconfig: 2345 10 90 (service description must add #) #description:Tomcat service
Add content 2: Set the jdk directory and the tomcat directory in the script JAVA_HOME=/usr/java/jdk1.8.0_111 CATALINA_HOME=/usr/apache-tomcat-8.5.9
3. Add tomcat8 script with executable permission chmod 755 /etc/init.d/tomcat8
4. Execute the add service command: chkconfig --add tomcat8
5. Set the service to start automatically at boot: chkconfig tomcat8 on
6. View the custom service chkconfig --list
7. Serious result of starting the service: service tomcat8 start
Redhat cannot connect to the network solution:
Solution 1: Shut down the virtual machine -> select the virtual machine "Edit" -> virtual network editor -> select vmnet8 -> click restore to initialize the network configuration -> start the virtual machine to connect to the Internet
Solution 2: Switch to administrator identity su - root and execute the command /etc/init.d/networking restart
This article is continuously updated. Please correct me for the deficiencies and errors of this article. If you have any questions, please leave a message!