Basic Linux knowledge

Source: Internet
Author: User

Run the command:./**. Sh

1. if the login succeeds, we will get shell (shell is a program used to interact with users, it is like the command in DOS. com, but in Linux, there can be a variety of shells to choose from, such as Bash, CSH, KSh, etc.). If you log on as a root user, the obtained prompt is "#". otherwise it will be "$ ".
2. like Windows 9x, there are common files and directory files in Linux, but the directory files are abbreviated as directories in windows. In Linux, a special file is a device file.
3. Like in windows, files are organized through directories in Linux. But the difference is that there is only one root directory in Linux, instead of one root directory in windows. If multiple partitions exist, Mount other partitions to the root directory.
4. After Linux is installed, there are many directories. The following describes some important directories:
/Bin: stores over one hundred Common commands and tools in Linux
/Dev: stores all the device files in Linux!

/Home: the user's home directory. Each time a user is created, a new directory with the same name as the user will be created here to give the user a space.
/Lost + found: as the name suggests, some lost files may be found here
/Mnt: the mount point of an external device. Two sub-directories, CDROM and floppy, are usually used! It simplifies the use of Cd and floppy disk. You only need to plug in the disc and run: Mount/mnt/CDROM to mount the content on the disc to/mnt/CDROM. Then you can access it. However, you should leave the Directory and execute umount/mnt/CDROM. Similarly, the floppy disk is Mount/mnt/Floppy and umount/mnt/floppy.
/Proc: This is actually a false directory. Here you can access the content in the memory.
/Sbin: system-level commands and tools are stored here.
/Usr: usually used to install various software
/Usr/x11r6 X Window directory
Commands and tools installed after/usr/bin and/usr/sbin
/Usr/include,/usr/lib, and/usr/share are used to store some shared link libraries.
/Usr/local is often used to install new software
/Usr/src Linux source program
/Boot: Linux is started from here
/Etc: Most configuration files are stored in Linux.
/Lib: static Link Library
/Root: the root user's home directory. This is one of the privileges!
/Var: usually used to store things in change!
/Var/log: stores system logs.
/Var/spool: stores emails, news, and print queues.
In addition, the concepts of "Current directory" and "path" in Linux are the same as those in windows.
5. Anyone who has used the doscommand should know that we can use the type command to view the content of a file. There are five related commands in Linux, each of which has its own unique functions. However, they are similar to type commands and can only be used to view text files.
1) Cat command
The cat command is the most similar to the type command. The method is simple: "cat file name ". What is more powerful than the type command is that it can view multiple files at the same time: "cat file name 1 file name 2 ".
2) More command
If the text file is too long to be fully displayed on a single screen, you may not be able to see it clearly using the cat command. Here we can simply use more to replace the cat command. The effect is similar to that of type file name/P. Use the more command to display the text of a screen at a time. When the screen is full, stop and display the percentage of all content. Press the Space key to view the next screen.
3) less command
The less command is similar to the more command and displays files by page. The difference is that the less command allows users to read files both forward and backward when displaying files.
? Forward: Press B;
? Backward flip: Press p;
? Specified position: Input percentage
? Exit: Q
I often use more and less, and almost do not use Cat to view files.
4) Head command
You can use the head command to view only the first few lines of a file in the format:
Header row name
If no number of rows is specified, the default value is 10.
5) tail command
In contrast to the head command, we can use the tail command to view the content at the end of the file. It is usually used to monitor whether a file is modified in real time, and is usually used to observe logs. For example:
Tail-F maillog

6. edit the file
There are many text editing tools in Red Hat Linux 7, the most common of which should be VI, which is an editor widely used in all UNIX systems. Its usage is somewhat special:
First, you can use the "VI file name" command to open a file.
At the time of startup, VI is in the command status and cannot enter any characters. In this status, you can use the direction keys to move the data. When you need to enter the content, you need to enter the "I" or "A" command to enter the editing status. After editing, Press ESC to return to the command status.
In the command status, you can enter ": Q !" If the disk is not saved, enter ": WQ" to exit.

7. Copying, deleting, and moving objects
We are already familiar with using the copy, Del, and move commands in DOS to copy, delete, and move files. Next, let's talk about how to perform the above operations in Linux.
1) CP command: File/directory Copy command
Its Syntax format is: CP [Option] source file or directory target file or directory
Common options include:
? A. This option is often used when copying directories. It retains links and file attributes and Recursively copies directories, just like xcopy/s in DOS.
? F if the target file or directory already exists, overwrite it without prompting

? I is the opposite of option F. When it is overwritten, the user will be asked to answer "Y" to confirm
? P with this option, the modification time and access permission will be retained during file copy.
? R if the source is a directory, CP will recursively copy all subdirectories and files in the directory, but this requires that the target is also a directory name.
In addition, you should note that if the source is a file name and the target is a directory name, you can use the CP command to specify multiple source file names. For example:
$ CP a.txt B .txt/home/user1
The command will copy the.txt and B .txt files to the/home/usr1 directory.
2) Rm command: File/directory deletion command
Its Syntax format is: Rm [Option] file...
Common options include:
? F. Directly Delete the object without giving any instructions during the deletion process.
? R indicates that Rm recursively deletes all directories and subdirectories listed in the parameter.
? I interactive deletion. A prompt is displayed when each file is deleted.
Be careful when using the RM command, especially when the root user logs on, I have seen a friend mistakenly converted the command "RM-RF/home/tmp" to "RM-RF/home/tmp" when using the RM command to delete the/home/tmp directory", as a result, the entire system was deleted when he walked back to the computer!
3) mV command: File/directory movement command
Its Syntax format is: MV [Option] source file or directory target file or directory
Common options include:
? F if the operation is to overwrite an existing target file, no instructions are given.
? I interactive operation. If an operation needs to overwrite an existing target file, the user will be asked whether to overwrite
The Running Effect of the MV command is different from that of the parameter type!
Result of the second parameter (target) of the first parameter (source)
Change the file name to the target file name.
File Name directory name move the file to the target directory
Directory Name directory name target directory already exists: Move the source directory to the target directory
The target directory does not exist: Change the name
Directory Name file name Error

8. Directory-related operations
1) create a new directory: mkdir. Its usage is the same as that of the dos md: mkdir directory name;
2) Delete the empty directory rmdir, which is the same as the RD in DOS: rmdir directory name;
3) change the Directory: CD, which is basically the same as the CD command in DOS. The only difference is that no matter what the directory name is, there must be spaces between the CD and the directory name, that is, "CD/" and "CD .. "," CD. "is invalid, but should input:" CD/"," CD .. "," CD. ", if you directly enter the command" cd "without adding any parameters, it will return to the user's home directory.
4) display the current directory: pwd
5) column directory command: ls, which is equivalent to dir in DOS
Its syntax is: ls [Option] [directory or file]
Common options include:
? A: displays all subdirectories and files in the specified directory, including hidden files;
? C. sort by file modification time
? L The detailed information of a file is displayed in a long format. Each file contains a row of information, including the file type and the number of permission links. The file name is the file size of the main file group. The last modification time is the file name.

9. file and directory permission operations
In Linux, each file and directory has the corresponding access permission. We can use it to determine who can access and operate files and directories. The access permissions of files or directories are divided into three types: readable, writable, and executable, which are represented by R, W, and x respectively. Their meanings are as follows:
R w x
File readable and executable
The directory can be listed. You can perform write operations in the directory to access the directory.
When a file is created, the file owner can set its permissions.
For an object, you can divide the user into three types and grant different permissions to them:
1) file owner
2) users in the same group as the file owner
3) Other users
Each file or directory has three groups of access permissions, each group is represented by three digits, for example:
D rwx R-x r --
Part 1: "D" indicates the directory. Others: "-" indicates the common file. "C" indicates the character device file;
Part 2: Permission words of the file owner. Here, R w X indicates readable, writable, and executable (the executable directory can enter the Directory );
Part 3: Permission words for users in the same group as the file owner. Here, R-X indicates readable, writable, and executable. Because there is a lot of communication between users in the same group, let him look at the file and don't modify it.
Part 4: Permission words for other users. Here is---. Of course, it is for people I have nothing to do with. Of course, my files won't be written or read by you.
1) command for setting file/directory permissions: chmod
This is one of the most common commands for Linux system administrators. It is used to change the access permissions of files or directories. This command has two usage methods:
? Use the text setting method that contains letters and operator expressions
Syntax format: chmod [who] [opt] [mode] File/directory name
Which indicates the object, which is one or a combination of the following letters:
U: indicates the file owner.
G: indicates the same group of users.
O: other users
A: indicates all users.
Opt indicates the operation, which can be:
+: Add a permission.
-: Cancel a permission.
=: Grant the given permissions and cancel the original permissions.
Mode indicates the permission:
R: readable
W: writable
X: executable
For example, to add the read and write permissions for file a.txt to users in the same group:
Chmod g + RW a.txt
? Set by number
The number setting rule is simpler: chmod [mode] File Name
The key is the mode value. At first many beginners will be confused. In fact, it is very simple. We regard rwx as a binary number. If there is 1, there is 0, then rwx R-x r -- can be expressed:
111 101 100
Convert each three digits into a decimal number, that is, 754.
For example, we want to grant the permission for the.txt file:
Other users in the same group
Readable is yes
Writable is yes
Executable
Then, we first obtain the permission string RW-r -- Based on the table above, and convert it to the binary number 110 110 100, and then convert each three digits into a decimal number, we get 664, So we run the following command:
Chmod 664 a.txt
2) Change the file owner command: chown
Syntax format: chown [Option] user name file/directory name
The most common option is "r". With this parameter, you can change the owner of all subdirectories and files in the entire directory to a specified user.
3) command for changing the file group: chgrp
This command is also simple: chgrp group name file name

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.