Linux knowledge details, linux details

Source: Internet
Author: User

Linux knowledge details, linux details
4 Linux

1 Basic Linux commands
Restart command:
1. reboot
2. shutdown-r now restarts immediately (used by the root user)
3. shutdown-r restarts automatically after 10 minutes (used by root users)
4. shutdown-r restart at (for root users)
Shutdown command:
1. Shut down halt immediately
2. Power off immediately
3. shutdown-h now shut down immediately (used by the root user)
4. shutdown-h: shutdown automatically 10 minutes later
Rpm-qa or yum list | grep installed

1. Basic commands

Command function
Ifconfig displays or configures network devices
Cd .. go to the upper-level directory
Cd [path]: enter a specified folder.
Cd/enter the root directory
Cd ~ Enter the root directory
Ls lists all files and folders in the current directory (excluding hidden files)
Ls-l details display all files and folders in the current directory (excluding hidden files)
Ls-a lists all files and folders in the current directory (including hidden files)
Ls-al details display all files and folders in the current directory (including hidden files)
Clear Screen
Mkdir [Folder name] Create a folder
Pwd

2. Operation directory command
Command function
Mkdir [Folder name] Create a folder
Rm-r [Folder name] Delete folder (confirmation required)
Rm-fr [Folder name] Delete folder (no confirmation required)
Mv [original folder name] [new folder name] change folder name
3. Operation FILE command _ create
Command function
Touh [file name] create a file
Vi [file name] create a file and enter the file to edit it.
4. Operation FILE command _ Delete
Command function
Rm [file name] delete a file (confirmation required)
Rm-f [file name] delete the file (No confirmation required)
5. Operation FILE command _ copy and cut
Command function
Cp [file name] [Folder name] copy the file to the target folder
Mv [file name] [Folder name] Cut the target folder of the file
6. Operation FILE command _ view
Command function
Cat [file name] displays all the content of a file at a time
More [file name] display file content by PAGE
Enter the Enter key to view the next line
Space key to view next page
B. view the previous page
Q exit to view
Less [file name] is similar to more, with some additional features
For example, view the row number less-mN [file name]
Tail [file name] view the end Of the file
7. Operation FILE command _ search
Command function
Find-name 'keyword * 'searches for all files or folders prefixed with keywords in the current directory.
Find [directory name]-name 'keyword * 'searches for all files or folders prefixed with keywords in the specified directory
8. Compress and decompress * tar: Package * tar.gz: Package and compress. GZip
Command function
Tar-zcvf [name of the file to be generated] [name of the file to be packaged] package and compress the file
Tar-zxvf [name of the file to be decompressed] decompress the file to the current directory
Tar-zxvf [name of the file to be decompressed]-C [specified folder] decompress the file to the specified folder

8. Edit the document
Command function
Vim [file name] enters Normal Mode
I enter the insert mode
Exit insert mode with Esc key (upper left corner of the keyboard)
: Wq Save the changes and exit
: Q! Do not save the changes and exit
9 Other commands
Command function
Pwd displays the current working directory
Ps-ef displays all processes
Kill pid to kill the process
Grep [Keywords] [file names] search for keywords in files
Grep [keyword] [file name]-color> Search for keywords in the file and highlight them.
Command 1 | command 2 command 1 result as command 2 input content
Ps-ef | grep usr: Process containing usr found from all processes
Netstat-ano view port usage
Reboot restart
Halt Shutdown
10 File Permissions
* Use the ls-l command to view the details of the current directory. The first section indicates the permission of the corresponding file.
Command function
Chmod [Sum of decimal permissions] [file name] Change the permissions of the specified file
Chmod 777 a.txt change a.txt permission to rwxrwxrwx corresponding to the data is the r-4-w-2-x-1 read and write query sum to indicate Permissions
Run the rpm-ql file name to query the directory of the installed software.
Rpm-qa | grep jdk: query the installed jdk. If you want to query the other jdk, write the name of the jdk.

2 Jdk/mysql/tomcat/redis Installation and Use
Today's goal
-Build a Development Environment
-Operate Redis String and Hash
-Interrupt command: Ctrl + C

Ps-ef | grep tomcat check whether tomcat is running

Rpm-qa | grep jdk check the jdk version
Source/etc/profile directly re-run the environment file. Then jdk restarts.

Query jdk versions using java-version

1. Install JDK
1. query locally installed JDK. Command: rpm-qa | grep jdk
2. query all locally installed software by rmp-qa
3. Uninstall installed JDK, command: rpm-e [file name] rpm-e-nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686 (first query the jdk software and then copy it to the back to uninstall)
4. Use xFtp to upload files to the/usr/local directory
5. decompress the file to the/usr/local directory. Command: tar-zxvf [file name]
6. Configure the environment variable. Command: vim/etc/profile (enter this file in the directory with the name)
-Add the following content to the file:
Set java environment
JAVA_HOME =/usr/local/jdk1.7.0 _ 72
CLASSPATH = .: J A V A H O M E / L I B . T O O L S . J A R P A T H = "Role =" presentation "> JAVAHOME/lib. tools. jarPATH = J A V A H O M E / L I B . T O O L S . J A R P A T H = JAVA_HOME/bin: $ PATH
Export JAVA_HOME CLASSPATH PATH
-Make the file take effect immediately. Command: source/etc/profile
2. Install MySQL
1. query locally installed mysql. Command: rpm-qa | grep mysql
2. run the command "rpm-e-nodeps [file name]" to uninstall an installed mysql instance. When directly uninstalling an instance, the rpm-e [file name] has two dependencies, which cannot be detached. Therefore, use the preceding command, the dependency is not checked during uninstallation)
3. Use xFtp to upload files to the/usr/local directory
4. Create the mysql folder and run the command mkdir mysql.
5. decompress the file to the/usr/local/mysql directory. Command: tar-xvf [file name]-C mysql
6. Enter the/usr/local/mysql directory, install the client, command: rpm-ivh MySQL-client-5.5.49-1.linux2.6.i386.rpm
7. Enter the/usr/local/mysql directory, install the server, command: rpm-ivh MySQL-server-5.5.49-1.linux2.6.i386.rpm
8. start mysql. Command: service mysql start
9. view the mysql status. Command: service mysql status
10. Set the root user password. Command:/usr/bin/mysqladmin-u root password 'root'
11. Connect to mysql. Command: mysql-u root-p
12. add mysql to the system service. Run the command chkconfig-add mysql (this command must be executed in the mysql folder)
13. Set the mysql service to Automatic startup. Command: chkconfig mysql on (to implement this command in the mysql folder)

Enable MySQL Remote Access
-Enable remote access
-Go to MySQL and run mysql-u root-p.
-Enable remote access and command
Grant all privileges on. to 'root' @ '%' identified by 'root ';
Flush privileges;
-Exit MySQL with the command: exit;
-Open Port 3306 and commands
/Sbin/iptables-I INPUT-p tcp-dport 3306-j ACCEPT
/Etc/rc. d/init. d/iptables save
3. install Tomcat
1. Use xFtp to upload files to the/usr/local directory
2. decompress the file to the/usr/local directory. Command: tar-zxvf [file name]
3. open port 8080, command (in the current file of the compressed package)
/Sbin/iptables-I INPUT-p tcp-dport 8080-j ACCEPT
/Etc/rc. d/init. d/iptables save
4. Start Tomcat, first enter the bin directory of Tomcat, and then execute the command:./startup. sh
5. Close Tomcat. first enter the bin directory of Tomcat, and then execute the command:./shutdown. sh.

Publish the project to Tomcat in Linux (copy the inverted war package to the wappspace space under tomcat and decompress it automatically)
Redis history
4. Redis Installation
1. Use xFtp to upload files to the/usr/local directory
2. decompress the file to the/usr/local directory. Command: tar-zxvf [file name]
3. install the gcc environment, command: yum install gcc-c ++ (directly in the/local/redis-3.0.7/src directory)
-Differences Between rpm and yum
-Rpm is generally used for offline installation.
-Yum is generally used for online installation. It not only installs the specified software package, but also automatically installs the dependency of the software package.
4. Enter the redis-3.0.7 directory, execute the make command, compile
5. Go to the redis-3.0.7 directory and install redis. Command: make PREFIX =/usr/local/redis install
6. Go to the redis-3.0.7 directory, copy the redis. conf file to the/usr/local/redis/bin directory, command: cp redis. conf/usr/local/redis/bin
7. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf

8. ctrl + c: Disable the server account: Password: to connect a virtual machine to the network, connect to the network on the real computer first, then the virtual machine uses the NAT connection mode. If you want other students to connect to your computer, the virtual machine uses the bridge mode.

5. Start the backend of Redis (because the entire window is occupied after it is started)
1. Go to the redis/bin directory, modify redis. conf, and change daemonize = no to daemonize = yes. Command: vi redis. conf
2. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf
3. Check whether redis is enabled
-Method 1: ps-ef | grep redis. If you can see redis-related processes, the startup is successful.
-Method 2: run the command./redis-cli to start the client, and then run the ping command. If the returned result is pong, the startup is successful.
1. Use of Redis
6 Redis stores String-type data
1. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf
2. Start the client. Command:./redis-cli

Command function
Set [key] value stores data
If the key already exists, overwrite the previous value.
Get [key] get Data
Del [key] delete data
Incr [key]: add the number corresponding to the key to 1
If the key does not exist, the default value is 0.
Decr [key] converts the number corresponding to the key to-1.
If the key does not exist, the default value is 0.
Keys * view all keys
7. Redis stores Hash data
-The hash type here is actually the HashMap in Java.
1. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf
2. Start the client. Command:./redis-cli

Command function
Hset [key] [field name] [field value] stores a key-value pair to the set key.
Hget [key] [field name] Get the value of the field in the set key
Hdel [key] [field name] Delete the corresponding field in the set key
You can specify multiple field names and delete multiple fields at the same time.
If all fields in a set are deleted, the set is also deleted.
Del [key] Delete the entire set

8. Redis stores List-type data
-The List type is similar to the listing List in Java.
1. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf
2. Start the client. Command:./redis-cli
The stored values are of the string type.

Command function
Lpush [listname] [value1] [value2]… Insert data from the left-side collection
Rpush [listname] [value1] [value2]… Insert data from the right-side collection
Lrange [listname] [start] [end] obtains data in the set.
The value range is from start to end.
Lrange [listname] [start]-1 get all data in the Set
-1 indicates the first to last data.
Lpop [listname] deletes 0th elements in a collection.
Rpop [listname] deletes the last element in the set.
Llen [listname] gets the length of the Set

Redis storage List-type data extension command
-The List type is similar to listing 1 in Java. go to the redis/bin directory and start redis. Command :. /redis-server redis. conf 2. start the client and run the following command :. /redis-cli
Command function
Lpushx [listname] [value] If the set exists, insert data to the left.
If the set does not exist, no data is inserted.
Rpushx [listname] [value] If the set exists, insert data to the right.
If the set does not exist, no data is inserted.
Lrem [listname] [count] [value] deletes count specified values from the set.
If count> 0, delete from left to right
If count <0, delete from right to left
If count = 0, delete all
If the value is a string, it must be caused "".
Lset [listname] [index] [value] sets the value at the specified position of the Set, which overwrites the previous value.
Linsert [listname] before [value1] [value2] Insert a new value before value1, value2
Linsert [listname] after [value1] [value2] Insert a new value after value1, value2
Rpoplpush [list1] [list2] removes the last value in list1.
Add this value to the left of list2

Redis Stores Set-type data
-The set here is an unordered set, which cannot contain duplicate data.
1. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf
2. Start the client. Command:./redis-cli
Command function
Sadd [setName] [value1] [value2]… Data entry/exit from set
If the data set to be inserted already exists, insertion fails.
Smembers [setName] obtains all data in the set.
Sismember [setName] [value]: determines whether a set contains a value.
Srem [setName] [value] [value]… Remove a value from set.
Sdiff [set1] [set2] difference set operation. Get data belonging to set1 but not set2
Sinter [set1] [set2] Intersection operation. Get data that belongs to both sets
Sunion [set1] [set2] union operation. Get all data of Two Sets
If duplicate data exists, only one copy is retained.

Redis storage Set-type data extension command
1. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf
2. Start the client. Command:./redis-cli

Command function
Zrangebyscore [setName] [min] [max] obtains data of the specified score range. The returned results are sorted from small to large scores.
Zrangebyscore [setName] [min] [max] limit [offset] [pageSize] Get the data of the specified score range. When returning the result, remove the first offset and intercept the pageSize.
Paging queries similar to databases
Zincrby [setName] [score] [value] adds the score to the specified value
Zcount [setName] [min] [max] gets the number of elements in the specified score range.
Zrank [setName] [value] obtains the ranking of a specified Element in the set.
The minimum score returns 0. The higher the score, the larger the return value.
Zrevrank [setName] [value] obtains the ranking of a specified Element in the set.

Keys wildcard
1. Go to the redis/bin directory and start redis. Command:./redis-server redis. conf
2. Start the client. Command:./redis-cli

Command function
Keys * Get all keys
Keys ??? Obtains the key with three characters.
A few question marks represent several characters.
Del [keyName] deletes a key.
Exists [keyName] determines whether a key exists
Rename [oldName] [newName] rename the key
Expire [keyName] [seconds] sets the expiration time of a key, in seconds.
The key will be deleted after expiration.
Ttl [keyName] gets the expiration time of a key
-1 is not set.-2 is returned if no result exists.
Type [keyName] indicates the type of the key to be obtained.
2. Use of Jedis
-Home Page
-Procedure
1. Open Port 6379
/Sbin/iptables-I INPUT-p tcp-dport 6379-j ACCEPT
/Etc/rc. d/init. d/iptables save
2. Import the jar package
3. Code Implementation
// Create an object
Project 1 in six days
1 BaseServlet use reflection to call the method based on the user name
Method method = this. getClass (). getDeclaredMethod (action, HttpServletRequest. class, HttpServletResponse. class );
// Set the access permission
Method. setAccessible (true );
// Method for reflection execution
String result = (String) method. invoke (this, request, response );
// Each setting has a return value. If a return value is returned after the method is executed, it is forwarded to the corresponding page.
If (result! = Null & result. trim (). length ()> 0 ){
Request. getRequestDispatcher (result). forward (request, response );
}
2. Custom BeanUtils String-Date conversion
// Parameter 1: Custom Converter
// Parameter 2: converted data type, corresponding to the bytecode File
// Register a custom Date converter. In this way, BeanUtils will use this converter to process data of the Date type.
ConvertUtils. register (new DateConverterUtils (), Date. class );
User user = new User ();
// BeanUtils can only process basic data types and java. SQL. Date
// Because the birthday field in our User is of the java. util. Date type
// You must implement a converter by yourself.
BeanUtils. populate (user, request. getParameterMap ());
1 Registration
2. log on, remember the username, and log on automatically.
3. log out

3. Date converter for encapsulating data from the client with DButils

// The Custom Date Converter must implement the Converter interface in DButils to convert the String type to the Date type.
Public class DateConverterUtils implements Converter {

// Arg1: the data before conversion. // For this case, the Date entered by the user in the birthday input box on the registration page @ Overridepublic Date convert (Class arg0, Object arg1) {try {// to be processed, converts a date of the string type to java. util. date type Date // int I = 10; SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd"); date Date = sdf. parse (String) arg1); * content emphasized *

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.