"Linux Comprehensive Learning" 6.Linux common commands (emphasis)

Source: Internet
Author: User
Tags create directory

Linux Common commands
(1) LS
View all directories and files in the current directory


Ls-l will queue directories and files, and can provide file data

The leftmost "D" begins with the directory, and the file begins with "-". The following is the file and directory permissions, followed by the size of the space occupied, then the creator and everyone who is, then the actual space occupied, followed by the creation of the time, the rightmost is the directory or file name.

Ls-m will fit the left and right screen widths list directories and files

The back of the less commonly used no longer introduced, used to find out

(2) CD
Open Directory

CD/Open root directory
Cd/dev Open the Dev directory (absolute path)
CD/after CD dev Open dev Directory (relative path)
Cd.. Return to Upper Path

(3) PWD
See what the current path is


(4) Mkdir,rmdir,touch,rm
"Create directory" and "Remove directory"

First, create a test directory under the root directory, where we create and remove the directory under this directory:


We create a directory under the test directory, called DL


Delete DL directory using "RmDir DL"


Then we re-create the DL directory and create a DDL directory under the DL directory


At this time we go to delete the DL directory, is not deleted

The error message is "directory not empty." This means that the rmdir instruction can only delete directories with empty contents. But generally we do not use this, you can delete the folder directly without determining whether the folder is empty, using the "recursive" algorithm to delete the directory. Linux provides us with a recursive removal of the instruction "Rm-r"

Let's remove all files from the DL directory level directory

But always pop up the Ask box asks if you want to delete, this is very troublesome, so often there is a command is forced to delete called "RM-RF DL", will directly delete all files in the directory level directory.


The "RM-RF" command not only deletes the directory, but also deletes the file. We create a DL and create a file named "Test" under the DL:

Above we also created a dd1 directory to compare with, "-" The Beginning is the directory, "D" is the file.

We use the "RM-RF" command to delete the file:


(5) CP,MV
CP is the meaning of copy copy, and MV is the meaning of move

Create the "DD1" directory under the DL and a file named "Test2", then we return to the parent directory TestDir use "Ls-r" to view the overall structure of the file layer:


We come to the DL and copy the Test2 file to a test3


But we can not directly use "CP" to copy the directory, you need to use "cp-r" recursive way to copy the directory, such a copy will be able to copy the directory and all the files in the directory:


We then use the "MV" instruction, the DD1 folder moved to the parent directory TestDir


In the mobile directory, there are sub-directories with sub-files, or to add "-r" for recursive movement.

(6) VI
An instruction that edits information to a file and is also a text editor.

We execute "VI test3" in the Dirtest directory, edit it if there is a test3 file, create a test3 if it does not exist, and edit it


Press ENTER to edit the file we entered:


Default entry, is "command mode", that is, can not directly in the file typing, need to enter the command, we use "append" here to switch to edit text mode, you can type


Hit "ESC" Back to command mode, and then hit the colon ":" Can lose the command, knock "W" is to save, knock "Q" is to exit, knock "q!" is not to save the exit, knocking "Wq" is to save and exit, we save here


There are many other editing commands, not to remember, just need to remember the most basic good, need to check the relevant documents.

(7) More,cat,tac,head,tail
List the details in the file, More,cat,tac "Details", "positive order content", "reverse content".

We look at the contents of the Test3 file we just created, using the MORE,CAT,TAC directive, respectively:


There is also a head and tail command:
Usage:
Head displays the first x rows of each specified file to the standard output. For example, we just want to see the first 3 lines of the file:


Tail Displays the X line at the end of each specified file to the standard output. For example, we just want to see the last 3 lines of the file:


(8) Find
Find where the file is located (by size/time, etc.)

Suppose we can't remember where the test2 is in the TestDir directory (even the name only remembers the Est2), we use the following command to search:


(9) Whereis
The whereis+ command name, such as "Whereis ls", will tell you where LS is from, which file is executed when you knock the LS command, and where some of its help documents are in this command.


(Ten) Echo
From the command line, see what the current environment variable refers to (this command window is almost the same)

Delimiter is a colon ":"

(one) ln
ln is a link command. Let's use it down here.
First we create a test folder, and then create a 3.txt text document below

We use the VI command to deposit the following information in 3.txt


We will link the 3.txt to 4 and then we look at 4 content and find the same as 31 touch:

So will everyone think that linking and copying are not the same effect? In fact, the case of the link, when the content of 3 changes, 4 of the content will be changed:



They are two different files, and there is an association between the two files, which is called a link, and the above is called a "hard link", which is equivalent to copying a copy of the file, and then in the two files to add a link.

There is also a kind of called "soft Connection", also called Symbolic link (plus-s,-s is single), the equivalent of Windows "shortcut", just a file to guide, the file itself has no content.


We remove 3.txt to see the difference, we will 3.txt delete, see what 4 and 5 are respectively:

As we can see, 4 still exists, and 5 because the missing link has failed.

Reprint Please specify Source: http://blog.csdn.net/acmman/article/details/51985270

"Linux Comprehensive Learning" 6.Linux common commands (emphasis)

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.