Linux environment to build and common commands and

First, the concept of Linux permissions

There are two user under Linux: ordinary users and super users ().
Ordinary users: do things in linux limited;
superuser: You can do anything linux system without restriction.
Average user prompt is "$", the superuser command prompt is a "#."
Command: su [username]
Function: Changing user
Linux Rights Management
Category 1. Document visitors (people)
the owner of the files and directories: u-User
owner of the file and the file directory where groups of users: g- Group
other users: o-others
species 2. file access
basic rights:
the read to document, has permission to read the contents of the file; for a directory, browse the directory has information rights.
write to the file, the file has permission to modify the contents; For a directory, delete has moved within the directory file permissions.
execute the file, the file has execute permissions; For a directory, has permission to access the directory.
- said they did not have the authority.
3. File permissions worthy representation

  • r-- read-only permission to 0 + 0 + 4 = 4
  • -w- write permission only for the 0 + 2 + 0 = 2
  • --x only executable
  • rw- read and write
  • -wx write executables
  • rx-readable executable
  • rwx read-write executables
  • - No permission
  • rwx 4 wherein W is r is the authority for the 2 x 1, rwx 4 + 2 + 1 = 7

 

Second, the Linux basic commands

1.ls command:
Format :: ls [options] [directory or file]
function: For a directory, listing all the subdirectories and files in the directory; for the file that lists the file name and other information.
Common options:
-a: lists all files in the directory, including hidden files that begin with.
-d: display will be the same directory as the file, instead of showing other files.
-i: i-node index information output file.
-k: indicates the file size in bytes of the form k.
-l: lists the details of the file.
-n: the digital UID, GID instead of the names.
-F: Attach a file name after each character to illustrate the type of the file, "*" indicates a regular file executable; "/" indicates a directory; "@" symbolic link; "l" represents FIFOS; " = "represents a socket.
2.cd command
format: cd [directory name]
Common options:
cd .. go back one level.
cd ../ .. the current directory to move up two.
cd - returns a recent visit to the directory.
3.pwd command
format: pwd
Function: Displays the absolute path of the current working directory.
4.touch command
format: touch [options] filename ...
Function: touch command parameters can change the date and time a document or catalog, including access time and change the time or create a file that does not exist.
Common options:
-a change only the access time of the specified file.
-c or -no-creat does not create any files.
-m change only the modification time of the specified file.
-d specified date and time, not time now.
-f This parameter is ignored no treatment, only responsible for resolving compatibility issues BSD version of the touch command.
5.mkdir command
format: mkdir [options] dirname ...
Function: mkdir command to create directories.
Common options:
-p -parents can be a path name. At this point some of the directory path if competition does not yet exist, after adding this option, the system will automatically build a good directory that does not yet exist, that one can create multiple directories.
-m -mode = MODE will access the new directory to MODE, access is represented by a given octal numbers.
6.rm Command
Format: rm [options] file list
function: rm command to delete a file or directory.
Common options:
-f -force Ignore file does not exist, and without prompting information.
-r -R, -recursive recursively delete the specified directory and its subdirectories subordinate levels and the corresponding documentation.
-i interactive delete files.
Description: rm command to delete the specified file, by default, it can not delete the directory. If the file is not written, the standard input is a tty (terminal equipment). If no option -f or -force, rm command will prompt the user whether to delete the file before deleting; if the user does not answer y or Y, the file is not deleted.
7.rmdir command
format: rmdir [options] dirname
function: delete the directory.
Common options:
-p -parents recursively remove the directory dirname, parent directory when deleting a subdirectory is empty, it is deleted together. If there is non-empty directory, the directory is retained.
8.man command
format: man [options] command
function: man command formats and displays on-line help manual pages for a command.
Common options:
-k based on keyword searches online help.
num num only to find in the first chapter.
-a All chapters are displayed.
Description: Guide surface 8 chapters:
1. General user's command;
2. system call;
3. C language library;
4. explanation of the system and device drivers;
interpretation 5. profile;
6. game program command;
7. useful miscellaneous commands such as macro packages and the like;
8. For system maintenance and management commands.
9.cp command
format: cp [options] source file or directory target file or directory
features: Copy files or directories.
Common options:
-f -force forced to copy a file or directory, regardless of whether the file or directory already exists.
When you copy a file link -d reserved.
-i -interactive first ask the user before overwriting files.
-r recursive processing, the files and subdirectories in the specified directory dealt with together. If the form of the source file or directory, not a directory or a symbolic link, be regarded as an ordinary file processing.
-R or -recursive recursive processing, the files and subdirectories in the specified directory dealt with together.
10.mv command
Format: mv [options] source file or directory target file or directory
features: mv command on a file or directory to rename or move files from one directory to another directory.
Common options:
-f Force mandatory sense, if the target file already exists, but will not be asked directly covered.
-i If the target document (destination) when already exists, it will ask whether to overwrite.
11.cat/tac command
format: cat [option] [file]
Function: View the contents of the target file.
Common options:
-b non-empty output line number.
-n number for all lines of output.
-s not output multiple lines blank line.
12.more command
format: more [options] [file]
Function: more command displays the contents of the file every time a display screen.
Common options:
-n output for all lines of numbers.
-s file in contiguous blank lines into a blank line is displayed.
-num this option to develop an integer representing a screen displaying how many lines.
q to quit more.
13.less command
format: less [parameters] file
functions: less command to the more command similar, but there is difference between the two, less command allows the user to browse the file forward or backward, and the more command can navigate forward.
Common options:
-i Ignore case when searching.
-N display line numbers for each line.
14.head command
format: head [options] [file]
Function: head command displays several lines that begin with the specified file on the screen.
Common options:
-C -bytes = [-] N the first N bytes of each file display.
-n -lines = [-] N N display lines in front of the specified file.
15.tail command
Format: tail [Option] [File]
Function: Used to display the end of the specified file, when the file is not specified, as input information for processing. Common view the log file.
Description: tail command from a specified point write the file to label output. Using tail -f option can easily access to the log files are changing, tail -f filename filename will most tail content displayed on the screen, and constantly refresh, so you see the latest content of the document.
Common options:
-f read cycle.
-n <line number> shows the number of rows.
16. The time-dependent commands
date display
date specified display time format: the Y date +%:% m:% D
date Usage: date: date [the OPTION] ... [the FORMAT +]
% H hour (00..23)
% M min ( 00..59)
% S seconds (00..61)
% X-H equivalent%:% m:% S
% D day (01..31)
% m month (01..12)
% the Y full year (0000 ..9999)
% F. equivalent% Y-% m-% d
Timestamp
time -> timestamp: date +% s
timestamp -> Time: Unix timestamp from January 1, 1970 the number of seconds after the start, regardless of leap seconds.
17.cal command
format: cal [parameters] [month] [year]
Function: used to query the calendar time information, if there is only one argument, the year (1-9999) said that if there are two arguments, then the month and years.
Common options:
pre--3 display system a month, the current month, the next month's calendar.
-j Displays the first few days in the year (the year the date by day, counting from January 1, the default display the number of days in the current month of the year).
-y display the current calendar year.
18.find command
format: find pathname -options
function: to find files in the file tree, and make the appropriate treatment (may access the disk).
Common options:
-name find files by file name.
19.grep command
format: grep [options] Search string file
functions: search string in the file, find the line printed.
Common options:
-i Ignore different case, so the case considered the same.
-n way output line number.
-v reverse selection, i.e. showing no 'search string' content of the line.
20.zip/unzip command
format: zip compressed .zip file directory or file
function: the compressed file into a directory or zip format.
Common options:
-r recursive processing, all the files and subdirectories in the specified directory dealt with together.
21.tar Command
Format: tar [-cxtzjvf] files and directories ... parameters
Function: packing / unpacking, do not open it, look directly at the contents.
-c command to establish the parameters of a compressed file (create meaning).
-x command to unlock a file compression parameter.
-t tarfile view files inside.
-z gzip whether the property has both? Namely the need to use gzip compression?
-j whether bzip also has attributes? Namely the need to use bzip compression?
-v displays the file compression process. This common, is not recommended for use during the execution of background.
-f use the file name, please note that after f immediately then file name, do not add parameters.
-C extract to the specified directory.
22.bc command
bc command can easily perform floating-point operations.
23.uname -r command
format: uname [option]
Function: uname used to obtain information about the computer and operating system.
Common options:
-a or -all in detail all of the information output, followed by the kernel name, host name, kernel version, kernel version, hardware name, processor type, hardware platform type, operating system name.

 

24. How do I find a particular file

find ~ -name "target.java": pinpoint file

find ~ -name "target *": fuzzy lookup file

find ~ -iname "target *": not sensitive file names to find files

man find: More about the find command instructions

25. retrieve the file contents

grep 'partial \ [true \]' bsc-ll.log: retrieves the documents contain a field to show the relevant lines

grep -o 'engine \ [[0-9a-z] * \]': meet the selected regular expression field by option bar o

grep -v 'grep': filtering comprises content related to the string

26. The statistics do file contents (for column operation)

awk '{print $ 1, $ 4}' net.txt: print data of a first row and the fourth column

awk '$ 1 == "tcp" && $ 2 == 1 {print $ 0}' net.txt: printing a first and second columns meet all the data

awk '{enginearr[$1]++}END{for(i in enginearr)print i "\t" enginearr[i]}'

awk '($ 1 == "tcp" && $ 2 == 1) || NR == 1 {print $ 0}' net.txt print meets the first and second columns of the header plus all of the data

awf -F ',' {print $ 2} net.txt: a comma-divided negative

27. The batch replace text (on the row)

sed -i 's / ^ Str / String /' ne.txt String to replace Str

sed -i 's /\.$/\;/' ne.txt: replace the comma semicolon

sed -i 's / Jack / me / g' ne.txt: all the text into a jack me

sed -i '/ inter / d' net.txt: Deletes the specified row

Three, Linux build environment

 

  • MySQL to build a common commands

 

installation:

  • Download: yum install mysql -community -server
  • Decompression: tar -xvzf mysql-5.6.38-linux-glibc2.12-i686.tar.gz
  • To the specified directory: mv mysql-5.6.38-linux-glibc2.12-i686 / mysql
  • View initialize Password: cat /var/log/mysql.log | grep password

1. Turn on and off

  • Open: service mysqld start
  • Close: service mysqld stop
  • Restart: service mysqld restart

2. Log

2.1. Plaintext password

  Syntax: mysql -u user name -p User password

  Example: mysql -uroot -p123456

2.2. Password ciphertext

  Syntax: mysql -u username -p + Enter, and then enter the password

  Example: mysql -uroot -p  

 

3. Change Password

3.1.SET PASSWORD command (login required)

  • Syntax: mysql> set password for the user name @localhost = password ( 'new password');
  • 举例:mysql>set password for root@localhost = password('123456');
  • Or set password = 'new password';
  • I want to set up a simple password prompt error Solution:

3.2. Using sql statement to update the user table (login required) mysql library

  mysql> use mysql;

  mysql> update user set password=password('123') where user='root' and host='localhost';

  mysql> flush privileges;

3.3.mysqladmin command, clear text (without login)

  Syntax: mysqladmin -u username -p password old password new password

  Example: mysqladmin -uroot -p123 password 123456

3.4.mysqladmin command, cipher text (without login)

  Syntax: mysqladmin -u username -p password + Enter the old password, then enter the new password twice

  Example: mysqladmin -uroot -p123 password

 

4. Common Operation (login)

4.1. Display a list of databases

  show databases;

4.2. Create, Delete database

  create database database name;

  drop database database name;

4.3 Display Library Data Sheet

  use mysql;

  show tables;

4.4 Display Data Table Structure

  describe the data table;

 

The import, export database (no login)

5.1. Export all databases

  Syntax: mysqldump -u username -p password --all-databases> Export path

  举例:mysqldump -uroot -p123456 --all-databases >/tmp/all.sql

5.2. Export specified database

  Syntax: mysqldump -u username -p password --databases database name> Export path

  举例:mysqldump -uroot -p123456 --databases testdatebase >/tmp/testdatebase.sql

5.3. Export specified database structure (no data)

  Syntax: mysqldump -u username -p password --no-data --databases database name> Export path

  举例:mysqldump -uroot -p123456 --no-data --databases testdatebase >/tmp/testdatebase_no_data.sql

5.4. Export specified table in the specified database

  Syntax: mysqldump -u username -p password --databases database name --tables table name> Export path

  举例:mysqldump -uroot -p123456 --databases testdatebase --tables t_user >/tmp/testdatebase_user.sql

5.5. Exporting the indicated structure specified in the database table (no data)

  Syntax: mysqldump -u username -p password --no-data --databases database name --tables table name> Export path

  举例:mysqldump -uroot -p123456 --no-data --databases testdatebase --tables t_user >/tmp/testdatebase_user_no_data.sql

5.6. Export specified database specified table, set query conditions

  Syntax: mysqldump -u username -p password --databases database table name name --tables --where = 'condition'> export path

  举例:mysqldump -uroot -p123456 --databases testdatebase --tables t_user --where='user_no=1'>/tmp/mysql_user_no.sql

5.7. Cross-server backup database

  Import all the data in the db1 database server host1 to host2 in the db2 database, db2 database must exist otherwise an error

  (Tested in mysql5.5 version, DB2 can be present, the actual name of the database to generate consistent with db1; plus -C parameter to enable compression transmission)

  Syntax: mysqldump --host = host1 -u user name -p password --databases db1 | mysql --host = host2 -u user name -p password --databases db2

  举例:mysqldump --host=192.168.1.101 -uroot -p123456 -C --databases testdatebase |mysql --host=192.168.3.102 -uroot -p123456 --database testdatebase

5.8. Sql file into the database by

  Syntax: mysql -u username -p password <import path

 

  Example: mysql -uroot -p123456 </tmp/testdatebase.sql

  • Nginx build
  1. Installation: yum install nginx
  2. Start service nginx start / (restart)
  3. Stop: service nginx stop
  4. Overload: service nginx reload
  5. Search nginx process is started: ps -ef | grep nginx
  • Cache Service

      memcached

  1. Installation: yum install memcached
  2. Start: memcached -d -l -m -p
  3. Stop: kill pid

      Redis basic operations

  1. Source compiler installation 
  2. Start: redis -server start / restart
  3. Stop: redis server stop
  4. Client: redis -client
  • java installation
  1. yum -y install java-1.8.0-openjdk*
  • Apache basic operations
  1. Installation: yum install httpd
  2. Start: service httpd start / restart
  3. Stop: service httpd stop
  4. Overload: service httpd load

 

Fourth, the role of each directory of the Linux system root directory

/ Bin binary executable command. It kept the average user commands in this directory

 

Device file / dev system, i.e. the driver device

/ Home user's home directory to store files, user data

/ Lib kept the system running and related libraries

/ Mnt temporary storage mapping file, usually some other devices used to install subdirectory

/ Boot storage boot linux core document

/ Media with a removable storage device, such as floppy disks

/ Misc store the definition of some special characters

/ Net store some files and network-related

/ Proc to store the user's interaction with the kernel information

/ Sbin system management commands, is stored in a program where system administrators

/ Srv system startup service can access the database directory

/ Tmp temporary files, automatically cleared after restart

Frequently changing the file / var storage system produced by

/ Etc System configuration files are all in this directory

/ Opt (option: freedom of choice) to the main source selected when installing the software installation directory location

/ Root directory superuser

/ Selinux mainly used to reinforce the operating system to improve system security

/ Sys file management device

/ Usr largest catalog, the storage of applications and files

/ Lost-found directory is usually empty, "homeless" when the file system is not shut down properly and left the store will be here

 

Guess you like

Origin blog.csdn.net/weixin_44002432/article/details/93764978