In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you what are the commonly used linux commands. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
This article brings you a basic enough Linux command, which will cover all kinds of commands used in blog building series, which are convenient to query and learn to use. I hope it will be helpful to you.
File owner (Owner)
When you create a user, Linux creates a home directory for that user with the path / home/,. We can use cd ~ to quickly enter the home directory. If you want to keep a private file, you can put it in your home directory and set it to view only for yourself.
Group (Group)
Each user has a user group, which makes it easy for multiple people to assign permissions to a group of people. When you create a user, a user group with the same name is automatically created.
If a user belongs to multiple groups at the same time, the user needs to switch between user groups in order to have the permissions of other user groups.
Others (Others)
A user who is neither the owner of the file nor a member of the group to which the file belongs is someone else.
Super user (Root)
Root users are a special class of users who can access all files.
1. Adduser add user and passwd change password
# add a user named git adduser git# to set the password passed git of the git user
However, because the user permissions created are low, sometimes we need to increase the rights for the user, so we can do this:
# will open the sudoers configuration file sudo visudo
Note that also editing the sudoers configuration file, it is safer to use this command than to use sudo vim / etc/ sudoers, in addition to checking the syntax and locking the file during multi-user editing.
After opening the sudoers configuration file, we add this line of configuration:
# Allow git to run any commands anywheregit ALL= (ALL:ALL) ALL
Briefly explain this sentence git ALL= (ALL:ALL) ALL:
Git indicates the user name to which the rule is applied
The first ALL representation rule applies to all hosts
The second ALL indicates that the rule applies to all users
The third ALL representation rule applies to all groups
The fourth ALL representation rule applies to all commands
After we save and exit, the git user will get root privileges.
2. Ls lists files and directories
Ls lists files and directories
[root@iZ2ze learn-typescript.git] # lsbranches config description HEAD hooks index info objects refs
Ls-la consists of-a showing all files and directories (including hidden) and-l showing a detailed list:
[root@iZ2ze learn-typescript.git] # ls-la Total usage 20drwxrwxr-x 7 git git 132 December 15 12:33. Drwx-3 git git 127 December 15 14:51.. drwxrwxr-x 2 git git 6 December 15 12:21 branches-rw-rw-r-- 1 git git 66 December 15 12:21 config-rw-rw-r-- 1 git git 73 December 15 12:21 description-rw-rw-r-- 1 git git 23 December 15 12:21 HEADdrwxrwxr-x 2 git git 4096 December 15 13:10 hooks-rw-rw-r-- 1 git git 217 December 15 12:33 indexdrwxrwxr-x 2 git git 21 December 15 12:21 infodrwxrwxr-x 10 git git 90 December 15 12:33 objectsdrwxrwxr-x 4 git git 31 December 15 12:21 refs
Each row has seven columns. Let's take branches as an example to explain the meaning of each column:
Focus on the contents of column 1. Take drwxrwxr-x as an example, there are 10 bits here, and the first bit represents the file type, where-represents a normal file and d represents a directory file.
Bits 2 to 4 represent owner permissions, where r indicates read permissions, w indicates write permissions, x indicates executable permissions,-indicates no permissions, and bits 2 to 5 are rwx, indicating that the owner is readable, writeable and executable.
Bits 5 to 7 represent group user rights, which is also rwx.
Bits 8 to 10 indicate other user privileges, in this case rmurx, which means readable executable permissions and no write permissions.
Here is an additional point:
For example, the default permission for a root user to create a folder is rwxr-xr-x:
[root@iZ2ze www] # mkdir test [root@iZ2ze www] # ls-ldrwxr-xr-x 2 root root 6 December 17 23:53 test
The default permission for creating a file is rw-r--r--,. Note that the x permission will be removed by default:
[root@iZ2ze www] # touch index.html [root@iZ2ze www] # ls-1 root root 0 December 17 23:54 index.html
This is why we sometimes need to add execution permissions after creating the file.
3. Chown changes the file owner or the file group at the same time.
Chown (change owner) syntax:
#-R: recursively change file group chown [- R] generic principal name file name chown [- R] generic principal name: generic group name file name
Change the owner of index.html to git:
[root@iZ2ze www] # chown git index.html [root@iZ2ze www] # ls-- rw-r--r-- 1 git root 0 December 17 23:54 index.html
Change the owner and group of the index.html to git:
[root@iZ2ze www] # chown git:git index.html [root@iZ2ze www] # ls-1 git git 0 December 17 23:54 index.html
4. Chmod changes file permissions
Permissions can be expressed not only in r w x, but also in numbers. The corresponding relationship between arrays and letters is:
R:4
W:2
X:1
For example, if we want a file to be readable and writable, then we can easily set the permission to 6 (4 + 2). Similarly, if we know that a permission is 3, we can also deduce that the permission is writable, because only 2 + 1 can be equal to 3.
Let's take a look at the specific syntax of chmod (change mode):
#-R: recursively change file ownership group chmod [- R] xyz file or directory
Where xyz represents the permissions of Owner, Group and Others, respectively. If we set the permissions of a file like this:
Chomd 750 index.html
We can know that the permission of Owner is 7, which is readable, writable and executable, the permission of Group is 5, and the permission of Others is 0, which means that it cannot be read, written or executed. The corresponding letter is: rwxr-x---.
In addition to this numerical approach, there is another way to change permissions using symbolic types:
In this way, we abbreviate the three identities Owner, Group, and Others as u (User), g, o, use a to represent all identities, then use +-= to add, remove, and set a permission, and r w x continues to represent read, write, and execute permissions, for example:
Chomd uprixmt gripxmae o ripx index.html
It means that Owner plus execution permissions, Group and Others remove execution permissions.
Of course, we can also set permissions directly.
Chmod uprirwx Magi gendrx Magi Olymr index.html
At this point, the permissions of the file are equivalent to-rwxr-xr--.
In addition, we can omit the identity content such as ugoa and write directly:
Chmod + x index.html
This is equivalent to using a, and execute permissions are added to all identities.
5. Su switch identity
# switch to git user su git
6. Whoami displays the user name
# whoami root
7. Pwd displays the current directory
[git@iZ2ze www] $pwd/home/www
8. Cd changes the working directory
# enter / home/www/cd / home/www# to enter your home directory cd ~ # and enter the upper two layers of the current directory: cd.. /..
10. Mkdir create directory
Mkdir create directory:
Mkdir new_folder
Mkdir-p recursively create a directory:
Mkdir-p one/two/three
11. Touch create file
Used to modify the time attribute of a file or directory. When the file does not exist, a blank file will be created.
Touch new_file
12. Echo printout
Echo is the Shell command for printout:
# display the escape character echo "\" test content\ ""
Create or overwrite the file as "test content":
Echo "test content" > index.html
If you want to add content, use > >:
[root@iZ2ze www] # echo "test content" > index.html [root@iZ2ze www] # cat index.htmltest content [root@iZ2ze www] # echo "test content" > > index.html [root@iZ2ze www] # cat index.htmltest contenttest content
13. Cat connects files and prints them out
View the contents of the file:
Cat / .ssh/id_rsa.pub
Clear the index.html content:
Cat / dev/null > index.html
Write the contents of index.html to second.html:
Cat index.html > second.html
Append the contents of index.html to second.html:
Cat index.html > > second.html
Append index.html and second.html to third.html:
Cat index.html second.html > > third.html
14. Cp copies a file or directory
Copy all files under the directory website/ to the new directory static:
#-r: if the source file given is a directory file, all subdirectories and files under that directory will be copied. Cp-r website/ static
15. Mv move and rename
Rename the file:
Mv index.html index2.html
Hide the file:
# add .mv index.html .index.html to the file name
Move the file:
# just move mv / home/www/index.html / home/static/#, move and rename mv / home/www/index.html / home/static/index2.html
Batch Mobility:
Mv / home/www/website/* / home/www/static
16. Rm deletes a file or directory
# the system will ask rm file#-f to delete directly #-r means to delete all files in the directory # delete all files and directories in the current directory rm-r * # run away rm-rf / *
17. Vi/vim
Linux has a built-in vi document editor. Vim is a text editor developed from vi.
Basically, vi/vim is divided into three modes: command mode (Command mode), input mode (Insert mode) and bottom line command mode (Last line mode). We introduce these three modes as we operate:
We execute vim index.html, and if we don't have this file, we create the file:
Vim index.html
This is command mode, where any character entered is treated as a command, followed by a few commonly used commands:
I switch to input mode.
X deletes the character at the current cursor.
Switch to bottom line command mode
If we press I, we will enter input mode.
In input mode, there is a-- INSERT-- flag in the lower left corner:
At this point, we can make various types of input. When the input is finished, press ESC to return to command mode.
At this point, the INSERT in the lower left corner has disappeared. If we want to save and exit, we first enter:, enter the bottom line command mode.
In the bottom line command mode, common commands are
W Save the file
Q exit program
We type wq to save and exit, and we will find and create a HTML file.
18. Ssh remote connection tool
Note that ssh snooping is port 22.
Its basic syntax is:
Ssh [OPTIONS] [- p PORT] [USER@] HOSTNAME [COMMAND]
Example of listening port:
Ssh-p 300 git@8.8.8.8
Turn on debug mode:
#-v verbose mode, print debugging information about operation ssh-v git@8.8.8.8. These are the common linux commands shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.