Linux Basic Common Sentences

Source: Internet
Author: User
Keywords linux linux sentence linux commands

This article mainly introduces the basic commands commonly used in Linux, simple and practical, for your reference, if there are errors, welcome everyone to point out. Let's begin the introduction.

Query: ls

View all content: ls -n
Delete: rm -rf file name
Create directory: mkdir
Unzip: rpm-
Verify installation: rpm -p file name
rpm -ivh --nodeps installation without preconditions
Query current path: pwd
Query java environment variables: java -version

How to view the file: cat file name

mv original name change name change file name
rpm -qa |grep java to see if java is installed
echo $PATH to see if the environment variable is configured with the java path
find / -name java Find java files

Check the permissions of the /etc/sudoers file, if read-only permissions, modify them to write permissions
[root@localhost ~]# ll /etc/sudoers
-r--r-----. 1 root root 4030 December 10 09:55 /etc/sudoers
[root@localhost ~]# chmod 777 /etc/sudoers
[root@localhost ~]# ls -l /etc/sudoers
-rwxrwxrwx. 1 root root 4030 Dec 10 09:57 /etc/sudoers

Uninstall the built-in mariadb before installing SQL
Query rpm -qa|grep mariadb
Delete rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64

File editing

Enter after pressing Enter, press i to start editing. To exit press ESC, enter the middle mode, press colon: followed by command)

: Wq

tar

-c: create a compressed file
-x: unzip
-t: view content
-r: append files to the end of the compressed archive file
-u: update the files in the original compressed package

Unzip

tar -xvf file.tar //Unzip the tar package

tar -xzvf file.tar.gz //Unzip tar.gz

tar -xjvf file.tar.bz2 //Unzip tar.bz2

tar -xZvf file.tar.Z //Unzip tar.Z

unrar e file.rar //Unzip rar

unzip file.zip //unzip zip

to sum up

1. Decompress *.tar with tar -xvf

2. Decompress *.gz with gzip -d or gunzip

3. Decompress *.tar.gz and *.tgz with tar -xzf

4. Use bzip2 -d to decompress *.bz2 or bunzip2

5. Use tar -xjf to decompress *.tar.bz2

6. Uncompress *.Z with uncompress

7. Decompress *.tar.Z with tar -xZf

8. Decompress *.rar with unrar e

9. Decompress *.zip with unzip

 

Unzip jdk to the specified folder:

tar -xzvf jdk-8u131-linux-x64.tar.gz -C /usr/local/java
Description of input and output
The operation of the command line is divided into two aspects: input and output:

Input: Open the terminal, press the keyboard to input, press Enter to end the input and execute;
Output: The output will return the result you want, for example, if you are looking at a file, the content of the file will be returned. If it is an executed program, the execution failure will tell you what went wrong, if the execution is successful, there will be no output. This is the philosophy of linux: no result is the best result.

Improve shell input efficiency
Reasonable use of shortcut keys can indeed significantly improve work efficiency. A summary of commonly used shortcut keys in shell is as follows:

Tap: Click the Tab key to complete command completion, directory completion, and command parameter completion;

Ctrl+c: Forcibly terminate the current program (commonly used);

Ctrl+d: End of keyboard input or exit the terminal (commonly used);

Ctrl+s: Pause the current program, press any key after pausing to resume operation;

Ctrl+z: Put the current program to run in the background, and restore it to the foreground as the command fg;

Ctrl+a: Move the cursor to the beginning of the input line, equivalent to the Home key;

Ctrl+e: Move the cursor to the end of the input line, equivalent to the End key;

Ctrl+k: delete from the cursor position to the end of the line, often used with ctrl+a;

Alt+Backspace: delete a word forward, often used with ctrl+e;

Shift+PgUp: scroll up the terminal display;

Shift+PgDn: Scroll down the terminal display;

Up and down arrow keys: browse history input records;

Proficiency in the use of the above operating skills will greatly improve the efficiency of our command line operation, but to really solve the problem requires the application of various bash commands, the following is a brief introduction to commonly used commands:

Common bash commands
File related

ls: List files in a folder, add parameters to achieve more detailed functions,

ls -a lists all files, including hidden files

ls -l lists files and their detailed information

cd to switch directories, and an error will be reported when cd to a directory that does not exist

pwd print current directory

cat: read the contents of a file

wc: Get the number of lines and words of a certain file

$ wc package.json
# 79 175 2712 package.json
cp: copy a file

mkdir: create a directory

rmdir: delete directory

rm-rf:r deletes all internal files, the f parameter means mandatory, rm-r junk deletes all files in the junk directory and below;

mv move mv photos.jpg Photos move photos to the folder Photos

sort

diff: compare the similarities and differences between two files

System related:

date: Get the current time

uname: return the system name

hostname: returns the host name of the system

Network related:

host xx.xxx.com: Display the hosting server/mail server related to a domain name

ping 8.8.8.8 to detect connection

Search related commands:

whereis:

Description: simple and fast

Use $whereis who

Note: This search is very fast, because it does not search sequentially from the hard disk, but directly queries from the database. whereis can only search binary files (-b), man help files (-m) and source code files (-s).

locate:

Description: fast and complete

Use $ locate /etc/sh (find all files beginning with sh under /etc), $ locate /usr/share/\*.jpg (note that you must add the backslash escape before the * sign, otherwise it will not be found. )

Note: Search through the /var/lib/mlocate/mlocate.db database, but this database is not updated in real time. The system will use a scheduled task to automatically execute the updatedb command to update once a day, so sometimes the file you just added may be Can't find it, you need to manually execute the updatedb command once (it must be executed once in our environment). It can be used to find different file types in the specified directory

Can take parameters: such as -i parameter can ignore case for search

which:

Description: small but fine

Use: $ which man

Note: We usually use which to determine whether a specific software is installed, because it only searches for commands from the path specified by the PATH environment variable

find:

Description: fine and detailed

Use: $ sudo find /etc/ -name interfaces/ format find [path] [option] [action];

Note: find should be the most powerful of these commands. It can not only search by file type and file name, but also search according to file attributes (such as file timestamp, file permissions, etc.). find is very powerful and relatively complex, so I won’t go into details here;
$ sudo find /etc/ -name \*.list

other:

--version/-V View the version of a program

history show history

echo: return the value you give, which can be simply understood as the console in js or print in python

man uses a program called less to view the help documentation of a certain command

less:linenumer u d keyarray search (case sensitive), regular expression

Globbing:

-You can use wildcards in parameters when using commands
-`*`: match 0 or more characters. For example, `ls *.html` will match all files ending with html, and `ls b*.png` will match all files starting with b and ending with png;
-`?`: match any character, such as `ls abc?.png` can match abcd.png/abce.png
-`[list]`: match any single character in list
-`[!list]`: Match characters except any single character in list
-`[c1-c2]`: match any single character in c1-c2 such as: [0-9] [a-z]
-`{string1,string2,...}`: Match either string1 or string2 (or more), such as `{css,html}`, `ls app.{html.css}` will match app. css and app.html;
-`{c1..c2}`: match all characters in c1-c2 such as {1..10}
-Use `man` to view help (man is classified as follows:)
-Note that wildcards are case sensitive
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.