Must be proficient in basic Linux commands

Source: Internet
Author: User
Tags create directory uuid

Recommendation: Command Daquan

http://man.linuxde.net/

Important a few hotkeys [Tab],[ctrl]-c, [ctrl]-d

[Tab] Key---with "command completion" not "file full" function

[Ctrl]-c button---Let the current program "Stop"

[ctrl]-d Key---usually means: "Keyboard input ends (end of File, EOF end ofinput)" meaning; In addition, he can be used to replace exit

1. Common commands

Shutdown-h now shut down immediately.
Shutdown-r now restarts
Reboot now restart
Su-If you are currently a normal user, enter this command to switch to the administrator user (root), and if you want to switch to another user, type Su-user name such as: Su-wangxin
Logout Log off from the current user (if it is a terminal in the graphical interface, enter the Exit command to exit the current user)
CD switch directory "such as: CD/switch to the root directory of Linux!! (/) Represents the root directory "
PWD shows the command under which path the user is currently in (This command is particularly used, and if you do not know the current folder in the command line, you can enter the command pwd
Clear clear the screen

Useradd User Name "Add a user" such as: Useradd wangxin
passwd user name "Change password for specified user name" such as: passwd wangxin
Userdel User Name "Delete a user, but the user's subfolder under the home file will remain" such as: Userdel wangxin
Userdel-r User Name "Delete a user, and delete the subfolder with the user in the home folder" such as: Userdel-r wangxin

Du metric catalog File size
Du–sh show the overall space size of this folder
Number of files
Find Databak-type F | Wc–l number of files in Databak directory
Find. -type F | Wc–l the number of files in the current directory
Ls
ls "List files and directories" such as: Ls/home (List all files and directories under Home)
Ls-l "lists the files and directories displayed in a long list" such as: ls-l/Home
Ls-a "list hidden files and directories" such as: ls-a/Home
mkdir "Create directory" such as: mkdir ABC

RmDir "Delete empty directory" such as: RmDir Xiaoluo (only empty directory can be deleted, if there are other files in the directory, the command is invalid)
Rm-rf/var/lib/mysql #清除目录下所有数据文件!!! Must be used with caution!!!
Rm/etc/my.cnf
Cp
CP "Copy command" such as: Cp/home/test.java/(Copy the Test.java file under the home path to the root directory)
Cp-r dir1 Dir2 "-R for recursion, copy the folder that Dir1 represents and the files inside it to the Dir2 path."
Example: Cp-r/home/xiaoluo/(Copy the Xiaoluo folder under home to the root directory)

MV "Moving files and changing filenames" such as:
Mv/home/test.java/(means to move the Test.java file under home to the root directory)
Mv/test.java/hello.java (indicates that the Test.java file name is changed to Hello.java)
MV data/* Databak cut all files in the data directory to the Databak directory
RM "Delete files and directories" such as:
Rm/test.java (remove Test.java from root) "Note: If the file is a folder, it will not be deleted"
RM-RF * "(-R for recursion, F for forced deletion) removes all content, including directories and folders" such as: Rm-rf/home/xiaoluo (forcibly deleting the Xiaoluo folder under Home)

Touch "Create empty file" such as: Touch Test.java
PWD "Show current directory" pwd
vi Editing a text file
② input i "Go to edit State"
③ typing ESC "Enter the command line input State"
④ type: "This allows you to enter a command. 】
⑤ typing Wq "Save and Exit" q! "Do not save and exit"
Cat/etc/profile (just view the contents of the file)
Vi/etc/profile (view, and can modify the contents of the file)

Two ways to create a new file
VI NewFile
Or
Touch NewFile
Just look at the first few lines of the file head
After a few lines tail
[Email protected] home]# head Openfire_mysql.sql
CREATE TABLE Ofuser (
Username VARCHAR (+) not NULL,
See only a few lines after the file tail
[Email protected] home]# tail Openfire_mysql.sql
INSERT into Ofid (Idtype, id) VALUES (26, 2);
...

Column Travel number
nl
# NL Log2015.log

ln "establishes symbolic links similar to shortcuts in Windows (requires root or appropriate user rights)"
Ln-s source target destination such as: Ln-s/etc/inittab/inittab (This will create a inittab link under the root directory, which points to the Inittab file under the ETC directory)

More
Less "show file contents with pagination" If there is a lot of content in one of our files, you can use the more command to page it
such as: more/etc/prelink.conf (to etc, the contents of the prelink.conf file below the page display)

| "Pipeline Command" "This command is used in many Linux systems" (| The function of this command is to give | The result of the command in front of | The command to be processed later)
Example: Ls/etc | More (| The previous command is to display all files and directories in the ETC folder, | The next command is displayed in pagination form,
So the meaning of this command is to display all the files and directories in the ETC directory by paging.

grep "Querying content in text"
This command is used very much as: grep "Xiaoluo"/home/test.txt (Query the Test.txt file for the line containing the Xiaoluo text information)
If you need to show the number of lines you are looking for, use: Grep-n "Xiaoluo"/home/test.txt (the number of rows in the query out Test.txt file Xiaoluo the line of information and the row of all text)

REDIRECT Command ">, >>, <"
such as: Ls-l/etc> a.txt (etc, the following list information is written to the a.txt file "overwrite", if the A.txt file does not exist before, then create the A.txt file and then write the information in,
If a a.txt file is present, the previous information is overwritten)
Ls-al/etc>> aa.txt (Append the list information of etc to the Aa.txt file information)
Enter information from a file AAA < BBB

2. View IP

IP address Show
#或者
Ifconfig #如果执行不了则需要: Yum install Net-tools

3. Set the static IP

Vi/etc/sysconfig/network-scripts/ifcfg-ens33
Here Ifcfg-ens33 file please view after LS

Default network configuration (DHCP settings)
Type=ethernet
Bootproto=dhcp
Defroute=yes
Ipv4_failure_fatal=no
Ipv6init=yes
Ipv6_autoconf=yes
Ipv6_defroute=yes
Ipv6_failure_fatal=no
Ipv6_addr_gen_mode=stable-privacy
Name=ens33
Uuid=20d0e0a7-151c-451f-8904-63db006104ee
Device=ens33
Peerdns=yes
Peerroutes=yes
Ipv6_peerdns=yes
Ipv6_peerroutes=yes
Ipv6_privacy=no
Onboot=yes
ipaddr=192.168.43.50


Static IP configuration
Type=ethernet
Bootproto=none
Defroute=yes
Peerdns=yes
Peerroutes=yes
Ipv4_failure_fatal=no
Ipv6init=yes
Ipv6_autoconf=yes
Ipv6_defroute=yes
Ipv6_peerdns=yes
Ipv6_peerroutes=yes
Ipv6_failure_fatal=no
Ipv6_addr_gen_mode=stable-privacy
Name=ens33
uuid=7cb5f2a3-f916-402d-bd78-efe652798112
Device=ens33
Onboot=yes
ipaddr=192.168.43.50
netmask=255.255.255.0


Restart configuration after
/etc/rc.d/init.d/network restart
Or:
Service Network restart


Shutting down the firewall

Systemctl Stop Firewalld

4. Modify file and folder permissions properties


chmod command File permission property settings
The control of file or directory permissions is distinguished by reading, writing, and executing 3 general permissions, and 3 special permissions are available for use.
The user can use the chmod instruction to change the file and directory permissions, the format of the use of text or digital code can be.



The representation of a permission range is as follows:
u user, which is the owner of the file or directory;
G Group, which is the group of files or directories;
? Other, except for the file or directory owner or group, other users belong to this scope;
A all, that is, all users, including owners, groups and other users;
R Read permission, the number code is "4";
W Write permission, the number code is "2";
? x Execute or switch permissions, the number code is "1";

-without any permission, the number code is "0";
s special Feature Description: Change permissions for a file or directory.
Syntax chmod (options) (parameter) options
-C or--changes: The effect is similar to the "-V" parameter, but returns only the part of the change;
-F or--quiet or--silent: No error message is displayed;
-R or--recursive: recursive processing, all files and subdirectories under the instruction directory are processed together;
-V or--verbose: Displays the instruction execution process;
--reference=< reference file or directory;: The group of the designated file or directory is set to the same group as the reference file or directory;
< permission scope >+< permission setting;: The option permission setting for the file or directory on which the permission is opened;
< permission scope >-< permission setting;: Close the permission settings for the file or directory of the permissions range;
< permission scope >=< permission setting;: Specifies the permission setting for the file or directory of the permissions range;
--Symbol Type change file permissions:

Other examples:
$ chmod u+x file adds execute permission to the owner of file
$ chmod 751 file assigns read, write, execute (7) permissions to the owner of file, assigns read, execute (5) permissions to the group where the file resides, and assigns permissions to other users to execute (1)
$ chmod Another form of the example on U=rwx,g=rx,o=x file
$ chmod =r file to assign Read permissions to all users
$ chmod 444 File above example
$ chmod a-wx,a+r File above example
$ chmod-r u+r Directory recursively reads permissions for the owner of all files and subdirectories in directory directory
$ chmod 4755 Sets the ID to assign read, write, and execute permissions to the owner, assigning read and Execute permissions to the group and other users.


5. Change the file or directory owner


Chown Command File permission property settings
The Chown command alters the owner of a file or directory and the group it belongs to, which can authorize a user to become the owner of the specified file or to change the group to which the file belongs.
The user can be a user or user D, and the user group can be either a group name or a group ID.
File names can have a list of files separated by spaces, and wildcard characters can be included in the file name.
This command is available only to the file owner and the superuser.

-C or--changes: The effect is similar to the "-V" parameter, but returns only the part of the change;
-F or--quite or--silent: No error message is displayed;
-H or--no-dereference: Only modify the symbol-connected files without changing any other related files;
-R or--recursive: recursively handles all files and subdirectories under the specified directory;
-V or--version: Displays the instruction execution process;
--dereference: The effect is the same as the "-H" parameter;
--help: Online Help;
--reference=< reference file or directory;: The owner of the specified file or directory and the owner of the group and the reference file or directory are the same as the owning group;
--version: Displays version information.

Instance:
$ chown user:market f01//File F01 to UESR, add to market Group


6, Installation JDK1.8


# Cd/usr/lib
# tar–xvf/home/jdk-8-linux-x64.tar.gz
Vi/etc/profile
At the end of the file, add
##########
java_home=/usr/lib/jdk1.8.0
Path= $JAVA _home/bin: $PATH
Classpath= $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
Export Java_home
Export PATH
Export CLASSPATH
############

7. Modify Host Name


One:
#hostname hn1
Two:
Modify the hostname=name1 in/etc/sysconfig/network
Three:
Modify/etc/hosts file 127.0.0.1 name1


8. Time zone and Time settings


To view server time:
Date
Show Calendar
Cal
To modify the time zone:
Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime

Modification Time:
Date-s 9:06:50
9. Install the necessary compilation environment
Loading wget
Yum-y Install wget

--Recommended in this way
Yum–y Groupinstall "Development Tools"

Install Net-tools, or you can't use ifconfig.
Yum Install Net-tools

Installing GCC
Yum Install gcc gcc-c++ kernel-devel

-OR
Yum-y Install GCC
Yum-y Install gcc-c++
Yum Install make


10. View CPU, Memory usage


Top


11, find the location of the service files which

[email protected] bin]# which ifconfig
/usr/sbin/ifconfig

Whereis

[[email protected] bin]# Whereis MySQL
MySQL:/usr/bin/mysql/usr/lib64/mysql/usr/share/mysql/usr/share/man/man1/mysql.1.gz
[Email protected] bin]# Whereis ifconfig
Ifconfig:/usr/sbin/ifconfig/usr/share/man/man8/ifconfig.8.gz


12. Finding files: Find

# parameters related to user or user group name:
-user Name: List files with file owner name
-group Name: List files that belong to the user group named name
-uid N: List file owner as User ID n
-gid N: Lists files that belong to the user group whose user group ID is n
For example
Find/home/wangxin-user Wangxin # Find the owner-wangxin file in the directory/home/wangxin

# Parameters related to file permissions and names:
-name FileName: Find the file named filename
-size [+-]size: Find a file larger than size (+) or small (-)
-tpye Type: Find file of type of file, the value of type is mainly: General file (f), device file (b, C),
Directory (d), connection file (L), socket (s), FIFO pipeline file (p);
-perm mode: Find file permissions just equal to the mode file, mode is represented by a number, such as 0755;
-perm-mode: Find file permissions must all include the mode permission of the file, mode is represented by a number
-perm +mode: Find file Permissions file that contains the permissions of either mode, mode is represented by a number
For example
Find/-name passwd # Finding files with file name passwd
Find. -perm 0755 # 0755 file to find file permissions in the current directory
Find. -size +12k # Find files larger than 12KB in the current directory, note that C means byte
Find/-size +120000k
# Find files larger than 100MB in all directories
[Email protected] bin]# Find/-size +102400k
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/home/wangxin/jdk-8u131-linux-x64.rpm
/home/wangxin/jdk-8u131-linux-x64.tar.gz
/home/openfire.zip

13, Curl use


Download files to Local
Curl-o 1.jpg Http://static.oschina.net/uploads/img/201204/20230218_pNXn.jpg

Print HTML output
Curl-l http://www.centos.org

# Upload the MyFile.txt file to the server
Curl-u ftpuser:ftppass-t myfile.txt ftp://ftp.testserver.com

# download xss.php file
Curl-u Ftpuser:ftppass-o ftp://ftp_server/public_html/xss.php

Request data
Use get to request data, in this way directly through the URL to pass the data
You can use the--data/-d method to specify that data is passed by post
# GET
Curl-u username Https://api.github.com/user?access_token=XXXXXXXXXX

# POST
Curl-u username--data "Param1=value1&param2=value" https://api.github.com

# You can also specify a file to pass the contents of the file as data to the server side
Curl--data @filename Https://github.api.com/authorizations

Real-world examples of post files:
Client Curl Operation
curl-f [Email Protected]/home/new.txt http://192.168.43.170:8070/webUploader/UploadServlet

or specify parameters:
Curl--form name=myfileparam [email protected]/home/new.txt \
Http://192.168.43.170:8070/webUploader/UploadServlet

Must be proficient in basic Linux commands

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.