In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you what the basics about Linux commands are. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
This article stipulates that for each command, it is roughly divided into the following three parts
Function
A brief introduction to the command function.
Give an example
Give the most commonly used examples of this command.
Description
Describe the command in detail.
Other
Other messy or supplementary contents of the command.
For an example of the use of each command, the following is illustrated
Using orgmode format as document format, orgmode format is readable on the one hand, and easy to export to various formats on the other hand.
For a single command operation
The first line of the starting list item gives the purpose of the operation, followed by the specific command, and finally gives a detailed explanation of the command.
For example:
+ list the contents of the current directory = $ls= here, the files in the current directory will be listed.
If the command is too long, use the # + BEGIN_SRC/#+END_SRC pair.
For a series of commands
The specific command is given using lists, while the series described in the command uses subheadings (in orgmode, the typesetting of lists is more prone to errors, so use subheadings to avoid nesting lists as far as possible).
For example:
* * use vi to edit: + first open the file before editing: = $vi filename= after opening the file, do the following: + insert input = a = + exit input =: Q = basic knowledge
Here is a brief introduction to the general syntax format of the linux command line. This is important for beginners, especially when looking up the help manual (man manual) for a command.
Command composition
The general linux command syntax format is as follows:
Command name item parameter (value) command parameter (value)
For example:
Od [OPTION]... [FILE]... Here, the name of the command is = od= and the item is OPTION. Here the item is enclosed in'[]'to indicate that this part is optional in the = od= command. The argument to the command is FILE and cocoa none; '...' Denotes the thing in front of it (here OPTION and FILE can be more than one. Generally speaking (not absolutely), in the = man= manual, parameters in the form of variables such as OPTION and FILE in the command (that is, their values are displayed in a special color depending on the user's typing; and the part of = od= itself is fixed (that is, it cannot be changed by the user to display in another color (for example, bold). There are also descriptions that enclose the variable parts in''.
Another example is:
Cp [OPTION]... SOURCE... DIRECTORY can see from this that the = cp= command parameters SOURCE and DIRECTORY, where SOURCE parameters can be multiple and DIRECTORY can only be one. The OPTION part is optional, but the SOURCE and DIRECTORY parts must be. Specific example: = $cp-r file1 file2 dir= about items
A simple writing form is also a complex writing form. Items in simple forms are generally used-derivation, complex forms are generally used-- derivation, and so on.
For example:
$cp-v file1 file2 is equivalent to $cp-- verbose file1 file2
Here, =-v = is the same as-- verbose,-v is an abbreviated form,-- verbose is a complex form.
Another example is:
Cp-r src des
Where-r is the [OPTION] part of it, or it can be-- recursive.
In addition, some command items do not need to be elicited, such as:
$unrar e test.rar
Use item e to specify the unrar command to extract the test.rar file.
Some command items are prefixed with-and can then be followed by multiple options, such as:
$tar-czvf dir.tgz dir
This command uses the four items of the tar command-c-z-v-f to package and compress the dir directory to generate the result file as dir.tgz.
While items are contained with'[]', separate them with'|'if only one of the values can appear. For example:
Command [- a |-b]
Here, command is a hypothetical command, which means that in this command command, the items-an and-b are either none or only one.
About the parameters of the item
Not only the command, the item of the command can also be parameterized.
Here's a more complicated command.
Gdb [- help] [- nx] [- Q] [- batch] [- cd=dir] [- f] [- b bps] [- tty=dev] [- s symfile] [- e prog] [- se prog] [- c core] [- x cmds] [- d dir] [progcore | procID]]
This is the syntax format of the gdb command, and the key parts are as follows:
[- d dir] means that when you run the gdb command, you can add a reachable item-d, whose argument is dir. In the description of this article, it is not easy to see at once which part of [- d dir] is a fixed string and which part is a string that varies with the user's input, but they are marked as different colors in the man manual, and it is actually easy to know which part is mutable through analysis.
There can be no spaces between some command items and their parameters, and there is a = connection between items and item parameters, such as ~ [- cd=dir] 'here.
Give me another example.
Minicom [- somMlwz8] [- con | off] [- S script] [- d entry] [- an on | off] [- t term] [- p pty] [- C capturefile] [configuration]
This is the command syntax of minicom, where [- c on | off] indicates that the-c item is available (that is, it is not available in the command, it is an option parameter, and the parameter value can be on or off.
Basic command
Here is the frequently used linux command for normal reference purposes.
Generally speaking, the command prompt symbol for a superuser (root) is #, and the command prompt symbol for an average user is $.
Related to document management
Create a directory with the name 1
$mkdir 1
Create a file with the name 1
$touch 1
Delete the file named 1
$rm 1
View the contents of file 1
$cat 1
Force deletion of a directory
$rm-rf dirname
Here, rm-r dirname means to delete recursively, and if you add the-I item, you will be prompted to delete it before deleting it.
Rename / move Fil
$mv. / origin. / newname
Here, there is no specific rename command in Linux, but the move command is actually used here. The original file name is origin, and the new file name is newname.
Copy the file file1 to file2
$cp file1 file2
Here, all operations are performed under the current directory. If you copy to another directory, you can specify a path, such as cp file1 / anotherdir/file2.
Take the directory dir1 to another place as dir2
$cp-r dir1 dir2
Here,-r represents a recursive copy place subdirectory.
Go to a directory
$cd dirname
View the files contained in the directory dirname
$ls dirname
View the details of the files contained in the directory dirname
$ls-l
In this way, the details of the corresponding file will be displayed, including owner, size, permissions, and so on.
View the current directory
$pwd
In this way, the path of the current directory is output.
Create a hard link to the file file
$lnfile lnfile
Here, the format of the directory that uses the link is similar to cp. After establishing a hard link, if you delete the source, you can also access the contents of the file through the hard link, which will always exist unless all the hard links have been deleted. Hard links cannot span the file system or establish hard links to directories.
Create a soft link to the file file
$ln-s file lnfile
Here, to create a soft link, escape\ $is used to represent $in the file name, and try to use an absolute path to prevent errors. Soft links can span the file system and create soft links for directories, but for soft-linked files, if the source is deleted, the link will fail, similar to the shortcut in windows.
Related to rights management
Modify the permission of the file to be readable, writable and executable
$chmod 777 filename
Here, the file owner must be the current user, otherwise the superuser can only execute this command.
Modify the permissions of the file filename to add write permissions for the other user:
$chmod otakw filename
The permission to modify directories and subdirectories is 777
$chmod 777-R dir
View online login users
$who
Add a user to a user group
# usermod-a-G groupA user
Here, don't forget item-a. If you use: usermod-G groupA, this will cause user users to leave other user groups and only be members of this user group groupA.
Change the group of user user to groupA
# usermod-G groupA user
View the users of the place
$cat / etc/passwd
Here, the users are saved in the passwd file, so you can see the users by looking at the contents of the file.
After a new user is successfully created, a line of information about that user is added to the / etc/passwd file in the following format:
(user name): (password): (UID): (GID): (identity description): (home directory): (log in to Shell)
Each of these fields is divided into seven parts by a colon.
Because the UID and GID less than 500 are generally retained by the system, there is no need to do the logo of ordinary users and groups, so the newly added users and groups are generally with UID and GID greater than 500.
View the group where it is located
$cat etc/group
View the group where it is located
$cat etc/group
Here, the users are saved in the group file, so you can see the users by looking at the contents of the file.
Add a user testusr
# useradd testusr
Here, note that it can only be used in superuser mode. Just created without password and home, other items can be found in man.
Add a user testusr and automatically establish its user home directory
# useradd-m testusr
After running, the user's home directory, .bashrc and other files are automatically generated.
Delete a user testusr
# userdel testusr
Here, the command does not delete the home directory.
Delete a user testusr, along with home directory and mailbox cache, etc.
# userdel-r testusr
Switch to user testusr
$su testusr
If the user needs a password, then you need to enter a password to log in to the user.
Switch to superuser
$su
In this way, you will be prompted for the super user's password, and after entering it, you will switch to the super user.
Run a program as a superuser
$sudo app
In this way, the app program will be run as a superuser, which is useful if the current permissions are insufficient. Of course, you need to enter your own password before running. It is also similar to sudo su.
Set to change the password of a user testusr
# passwd testusr
Here, under the superuser, after typing, follow the prompts to enter the old password and the new password. If the passwd running has no parameters, the password of the current user will be changed. To change your password, just enter passwd instead of switching to superuser.
Modify the home directory of user testusr and the shell of login
# usermod-d/home/quietheart-s/bin/bash testusr
Here, the home directory path of the user name testusr is set to / home/testusr, and the login Shell is set to / usr/bin/gcc (- d updates the user's new login directory,-s specifies the new user Shell).
Change the user testusr name to test
# usermod-l test testusr
Change the user name testusr to test (- l change the user's login name, the manual says that the user directory name will also be changed to a new name (the same directory has been practiced). Usermod does not allow you to change the user account name that is online.
View the groups to which the current user belongs
$groups
View the groups to which testusr users belong
$groups testusr
Disk management related
View the current directory size
$du-sh
View the size of the file
$du-sh filename
Here, filename is the name of the file to be viewed.
View partition information
Fdisk-l
Here, information about the disks on your computer, such as partitions, file systems, etc., will be displayed. You must currently be a root user, otherwise you do not have permission.
Related to mounting disk
Your linux system must mount other partitions of other hard drives (such as windows partitions) to the root tree in order to access the corresponding partitions.
Mount partition / dev/sda7 to / mnt/win
# mount-t vfat / dev/sda7 / mnt/win
Such a mount may cause garbled when displaying Chinese, because the decoded character set may not be specified. Must be a superuser to execute.
Specify mount of gb2312 character set
# mount-t vfat-o iocharset=gb2312 / dev/sda7 / mnt/win
When mounting like this, specify to use the gb2312 character set, so there may be no garbled code. Other commonly used characters include cp936,utf8 and so on (ntfs is usually mounted in utf8). Must be a superuser to execute.
View mounted partitions
# mount
Unmount a mounted partition
# umount / mnt/win
Or # umount / dev/sda7
Here, the / dev/sda7 partition is mounted on / mnt/win.
Remount
# mount-o rw,remount / mnt/data
Here, when the file system becomes read-only, try this command.
Set up the system to automatically mount a partition
One way is to add the following to / etc/fstab:
/ dev/sda8 / mnt/winG vfat defaults,rw,exec,iocharset=utf8,umask=0000 00
Must umask=0000, otherwise only root can write, and root cannot change chmod 777-R... I tried it on my own.
Other actions
Clear the screen
$clear
In this way, the current user's screen will be "cleaned" and refreshed, the original input commands and command output will be cleaned out, and you can also use [Ctrl] l to achieve the same effect.
View the code of the system
$locale
After input, for example, the output of my machine is as follows:
LANG=zh_CN.UTF-8 LC_CTYPE= "zh_CN.UTF-8" LC_NUMERIC= "zh_CN.UTF-8" LC_TIME= "zh_CN.UTF-8" LC_COLLATE= "zh_CN.UTF-8" LC_MONETARY= "zh_CN.UTF-8" LC_MESSAGES= "zh_CN.UTF-8" LC_PAPER= "zh_CN.UTF-8" LC_NAME= "zh_CN.UTF-8" LC_ADDRESS= "zh_CN.UTF-8" LC_TELEPHONE= "zh _ CN.UTF-8 "LC_MEASUREMENT=" zh_CN.UTF-8 "LC_IDENTIFICATION=" zh_CN.UTF-8 "LC_ALL=
Launch the xwindow graphical interface
$startx
This command is run under a pure command line.
Switch to the first pure command line terminal
Enter: [Ctrl] [Alt] [F1]
In this way, if you run this command in the graphical interface, you will switch to the first command terminal. It can be [F1] ~ [F7] and so on.
Switch to the graphical interface
Enter: [Ctrl] [Alt] [F7]
In this way, if the command line terminal, then will switch to the graphics terminal is [F7], [F8] and so on, not necessarily, generally [F7].
Exit the graphical interface
Two methods
Method 1, log out (no umount)
Method 2, enter: [Ctrl] [Alt] [Backspace]
After exiting the graphical interface, previously mount partitions are not umount.
Check the kernel version number
$uname-r
Here, if you type uname-a, the kernel information will be displayed.
View the released Linux version number
$cat / etc/issue
Search for recent matching history commands
Use the following steps:
Enter [Ctrl] r
Enter a substring of a previously entered command
Based on the input of 2, the most recent command is automatically matched.
If there is a match, but the command we need is earlier, type [Ctrl] r again.
Enter enter and run the matching command.
Look for the specified file in the current directory
$find-name filename
In this way, the file named filename is recursively looked for in the current directory and its location is returned, where wildcard symbols are supported.
Look for the specified file in the specified directory
$find dirname-name filename
In this way, the file named filename is recursively looked for in dirname.
Find a string in a file
$grep 'string' filename
This looks for the specified string 'string'' in the file filename and returns the location of that string.
Find the specified string in the files in the current directory
$grep-r 'string' *
Here, wildcard symbols are used.
View current time
$date
Operations under the GNome Desktop
Switch the desktop work area
Enter [Ctrl] [Alt]
Lock screen
Enter [Ctrl] [Alt] l
Shortcut keys to switch between different task windows
Enter [Alt] [Tab]
Switch between the desktop and the last program
Enter [Ctrl] [Alt] d
Foreground and background control of the task
Suppose we run multiple vi editors, as well as other programs (whether foreground or background, actually only one foreground program).
Put the current program in the background to stop
Enter [Ctrl] z
View the programs running in the background
$jobs
After the input, the output is as follows:
[1]-Stopped vi [2] + Stopped vi lex
Here, use the previous number to mark each program running in the background.
Change the specified program that stops in the background to run in the background
$bg 1
This will transfer the first background job to run in the background, in fact, just use bg 1.
After doing so, the effect is equivalent to running app &, where app is the running program, and & means it is left in the background.
Put the specified job number running in the background to the foreground to run
$fg 1
This will transfer the first background job to the foreground to run, in fact, just use fg 1.
Put the most recent stopped program to the foreground to run
$fg
Kill the specified background running program
$kill 1
In this way, the job% 1 that will run in the background will be killed. Note: the job number here is marked with%, rather than the process is directly numbered.
The most basic file editing operation
Here is the most basic operation of editing a file using vi, which can achieve most editing purposes.
Open a file with vi
Enter vi filename
Here, filename is the name of the file you want to open. By default, vi is in instruction mode after opening the file.
Enter edit mode to edit an open file
Enter I.
Or enter a.
After entering edit mode, you can type the character you want to enter directly into the file. The difference between the two is that I starts inserting before the current character and a starts inserting after the current character.
Exit edit mode
Enter [Esc]
In this way, you will return to instruction mode, ready to receive and execute the instructions you want to convey to vi, and if you are already in instruction mode, the system will ring to remind you.
The following commands are performed by vi in command mode
Undo the modification
Enter u
Here, compared to the previous vi, vim supports multi-step undo.
Restore modification
Enter [Ctrl] r
Here, contrary to the revocation order, it is the revocation of revocation, which can also be taken more than one step.
Copy rows to clipboard
Enter yy
Reformulate the content to the clipboard
Enter v.
The arrow keys will highlight the contents of the selection.
Enter y.
Here, start typing v so that vi temporarily enters a "selection mode". Enter the arrow keys to select, and enter y to copy the selected contents to the clipboard.
Delete Row
Enter dd
Note that the deletion of vi is equivalent to cutting, and the deleted contents are saved to the clipboard.
Delete fixed content
Enter v.
The arrow keys will highlight the contents of the selection.
Enter d.
Here, start to enter v so that vi temporarily enter a "selection mode", enter the key can be selected, enter d to delete the selected content.
Paste
Enter p
This pastes the contents of the clipboard to the cursor position or the next line of the cursor.
Find the character and navigate to the first match
Enter / character
Here character is the character to be found. Just enter / first, then enter the character to be checked, and then enter the enter to locate the first matching character.
Navigate to the next character of the match lookup
Enter n
Navigate to the previous character of the match lookup
Enter N
Save Fil
Enter: W
Note that after entering:, vim interprets the input after: as the instruction to be executed.
Quit
Enter: Q
Here, if the file is not saved, it will be prompted that you cannot exit unless you force the exit, do not save the file, or save the exit.
Forced exit
Enter: Q!
Save exit
Input: wq
Or enter ZZ.
Check for help
Input: help
Thank you for reading! This is the end of this article on "what is the basic knowledge related to the Linux command". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.