Summary of Common commands in Linux

Source: Internet
Author: User

The previous sections briefly explain the permissions of Linux Files. Now let's take a look at common commands, starting from a simple:

1. Switch the Directory

CD

To the/tmp directory: CD/tmp

To the upper Directory: CD ..

2. view the current directory

PWD

3. Create a new folder:

Mkdir

Create a directory:

Create a multi-level directory:

4. delete a directory:

Rmdir [-p] If you need to delete directories at a level, you need to add P (only empty directories can be deleted)

5. query environment variables

Echo $ path or $ path

 

6. Switch users:

Su User Name

7. Move files

 

 

Bytes

 

8. view files and directories

Ls

Ls-a directory name: list all files in the directory

Ls-Al directory name: List long strings, including some details about the file

If the directory name is not specified, it is the current directory.

 

9. File Replication:

CP [-adfilprsu] source file target file // copy the source file to the target file

CP src1, src2,... des // copy multiple source files to the destination folder

 

The CP command is very important. Executing different identities has different effects on commands, especially the-A and-P parameters. for different identities, the difference is very large.

Example 1:

Run the following command with root:

If we want to copy all the attributes of the file, we need to add the parameter-

 

Copy a directory to another directory CP-r/src/DESC

 

 

10. Remove files or directories

Rm [-fir] file or directory

-F indicates that the file does not exist and no warning is reported.

-I Interactive Mode: before deletion, you will be asked whether to delete

-R: recursive Deletion

 

I will not demonstrate it here. Do you remember the previous rmdir? Only empty directories can be deleted. Therefore, only Rm-R can be used to delete non-empty directories.

11. File category Query

Cat

-B: List row numbers.

-N: List row numbers, including blank rows.

 

Cat displays data on the screen at a time. What if I want to view the data one page at a time?

Use the more command

When running more, you can press the following buttons:

Space key: Indicates turning one page down

Enter: Indicates rolling down a row

Q: leave more

B: turning back

 

 

12. Create a file

Touch

Touch a.txt will be created under the current directory a.txt

 

13. file search commands

Whereis, find

Whereis [-bmsu] file or directory name

-B: Binary File

-M: Only search for the information in the manual path of the instruction file.

-S: only find the source file

-U: Find other special files that are not in the preceding three options.

 

Whereis ifconfig

 

Next let's take a look at the find command

 

Find [path] [Option] [actioin]

Find the Gavin file under/home

Find/home-user Gavin

Search for files that do not belong to anyone in the system

Find/-nouser

Find the file named passwd.

Find/-name passwd

Search for files with socket type

Find/-type S

 

14. Disk and directory capacity

DF: list the total disk usage of the file system

Du: Evaluate the disk usage of the file system

15. Create a link file

Ln [-SF] source file target file

 

-S: Creates a soft connection. If it is not added, it is a hard connection.

-F: if the target file exists, the file is deleted and then created.

 

[Root @ localhost Test2] # echo 'good'> a.txt
[Root @ localhost Test2] # ls
A.txt
[Root @ localhost Test2] # ln-s a.txt B
[Root @ localhost Test2] # ls
A.txt B
[Root @ localhost Test2] # ll
Total 12
-RW-r -- 1 Root 5 Aug 8 0:09 a.txt
Lrwxrwxrwx 1 Root 5 Aug 8 0:09 B-> a.txt
[Root @ localhost Test2] # echo 'hello'> B
[Root @ localhost Test2] # Cat B
Good
Hello
[Root @ localhost Test2] # Cat a.txt
Good
Hello
[Root @ localhost Test2] # ln a.txt C
[Root @ localhost Test2] # ll
Total 20
-RW-r -- 2 root Root 11 Aug 8 0:09 a.txt
Lrwxrwxrwx 1 Root 5 Aug 8 0:09 B-> a.txt
-RW-r -- 2 root Root 11 Aug 8 0:09 C
[Root @ localhost Test2] # echo 'bad'> C
[Root @ localhost Test2] # Cat C
Good
Hello
Bad
[Root @ localhost Test2] # Cat a.txt
Good
Hello
Bad
[Root @ localhost Test2] # Cat B
Good
Hello
Bad
[Root @ localhost Test2] # rm a.txt
RM: Remove regular file 'a.txt '? Y
[Root @ localhost Test2] # Cat B
Cat: B: No such file or directory
[Root @ localhost Test2] # Cat C
Good
Hello
Bad
[Root @ localhost Test2] #

 

Run the preceding command line. I believe your use of LN will be very clear.

 

15. Attach a cd

16. File compression

Tar

-C: Create a compressed file

-V: displays the compression process.

-F: indicates the compressed file name.

-X: Decompress the file

-T: view the files in the compressed package.

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.