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)06/01 Report--
This article shows you what are the basic commands in Linux, which are concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
target
Proficient in using commands commonly used in Linux
1 > View file information: ls
Ls is the abbreviation of the English word list. Its function is to list the contents of the directory. It is one of the most commonly used commands for users. It is similar to the dir command under DOS.
The Linux file or directory name can be up to 265 characters long, "." Represents the current directory, "…" Represents a higher-level catalog to "." The beginning of the file is hidden and needs to be displayed with the-a parameter.
Common parameters of ls:
The meaning of the information listed in the figure is as follows:
Similar to file operations under DOS, in Unix/Linux systems, it is also allowed to use special characters to reference multiple file names at the same time, which are called wildcards.
2 > clear screen: clear
The function of clear is to clear the display on the terminal (similar to DOS's cls screen clearing function). You can also use the shortcut key: Ctrl + l ("l" is the letter).
3 > switch working directory: cd
When using Unix/Linux, you often need to change the working directory. The cd command helps users switch between working directories. All directories and filenames in Linux are case sensitive
Cd can be followed by either an absolute path or a relative path. If the directory is omitted, it changes to the current user's home directory by default.
Note:
If the path starts from the root path, the path needs to be preceded by "/", such as "/ mnt". It is usually entered into a folder in a directory without a "/" in front of it.
4 > Show current path: pwd
Use the pwd command to display the current working directory, which is simple enough to type pwd directly without parameters.
5 > create directory: mkdir
You can create a new directory with the mkdir command. The parameter-p recursively creates a directory.
It is important to note that the name of the new directory cannot have the same name as an existing directory or file in the current directory, and the directory creator must have write permission to the current directory.
6 > Delete files: rm
Files or directories can be deleted through rm. Be careful when using the rm command, as files cannot be restored after deletion. To prevent accidental deletion of files, you can use the-I parameter after rm to confirm the files to be deleted one by one.
The common parameters and their meanings are shown in the following table:
7 > copy: cp
The function of the cp command is to copy the given file or directory to another file or directory, which is equivalent to the copy command under DOS.
Description of common options:
8 > mv: move, rename
You can use the mv command to move or rename a file or directory.
Description of common options:
9 > create a file: touch
You can create an empty file through touch. The demo is as follows:
Touch hello.txt
Description:
An empty file named hello.txt is created under the current path
There is no strict suffix (format) in the Linux system, so you can create a file with any file name.
1. Output redirect command: >
Linux allows the result of command execution to be redirected to a file, and what should be displayed on the terminal is saved to a specified file.
For example: ls > test.txt (test.txt is created if it does not exist, and its content is overwritten if it exists)
Note: > output redirection will overwrite the original content, > > output redirection will be appended to the end of the file.
two。 Split screen display: more
When viewing the content, when the information is too long to be displayed on a screen, it will scroll quickly, making it impossible for the user to see the contents of the file clearly. At this time, you can use the more command to display only one page at a time, press the space bar to display the next page, press the Q key to exit the display, and press the h key to get help.
3. Pipeline: |
Pipe: the output of one command can be used as the input of another command through the pipe.
We can understand the pipe in real life. One end of the pipe is stuffed in and the other is taken out. Here, the left and right ends of the "|" are divided into two ends, the left end is stuffed (write), and the right end is taken (read).
4. Create a link file: ln
Linux link files are similar to shortcuts under Windows.
Linked files are divided into soft links and hard links.
Soft link: the soft link does not take up disk space, and the soft link is invalid if the source file is deleted.
Hard links: hard links can only link ordinary files, not directories.
Use format:
Ln source file link file ln-s source file link file
If there is no-s option to establish a hard-linked file, two files take up the same size of hard disk space, and the linked file still exists even if the source file is deleted, so the-s option is the more common form.
Note: if the soft link file and the source file are not in the same directory, the source file should use an absolute path, not a relative path.
5. View or merge the contents of the file: cat
6. Text search: grep
Grep command is a powerful text search tool in Linux system, and grep allows pattern search of text files. If a matching pattern is found, grep prints all lines that contain the pattern.
The general format of grep is:
Grep [- option] 'search content string' filename
When entering string parameters in the grep command, it is best to enclose quotation marks or double quotation marks.
For example:
Grep 'a'1.txt
Description of common options:
The grep search content string can be a regular expression.
A regular expression is a logical formula for manipulating a string, that is, a "regular string" is formed by predefined specific characters and a combination of these specific characters. This "regular string" is used to express a filtering logic for a string.
Regular expressions commonly used in grep:
7. Find files: find
The find command is very powerful and is usually used to search for files that meet the criteria in a specific directory, as well as files owned by specific users.
Common usage:
8. Archive Management: tar
Data in your computer often needs to be backed up. Tar is the most commonly used backup tool in Unix/Linux. This command can archive a series of files into a large file, or unarchive files to restore data.
Tar packages filename files using the format tar [parameters]
The tar command is special, and its arguments can be preceded by "-" or not.
Common parameters:
Note: except that f needs to be placed at the end of the parameters, the order of other parameters is arbitrary.
9. File compression and decompression: gzip
Tar is used in conjunction with the gzip command to achieve file packaging and compression. Tar is only responsible for packaging files, but does not compress them. Use gzip to compress tar packaged files, and the extension is generally xxxx.tar.gz.
The format of gzip is as follows:
Gzip [option] compressed file
Common options:
The tar command has no compression function, it is just a packaged command, but adding an option (- z) to the tar command can call gzip to achieve a compression function, implementing a process of packaging and then compression.
Compression usage: tar cvzf compressed package name file 1 file 2.
-z: specifies that the format of the package is: file.tar.gz
Decompression usage: tar zxvf compressed package name
-z: specifies that the format of the package is: file.tar.gz
Extract to the specified directory:-C (capital "C")
10. File compression and decompression: bzip2
Tar is used in conjunction with the bzip2 command to package and compress files (the same as gzip).
Tar is only responsible for packaging files, but does not compress them. Use bzip2 to compress tar packaged files, and the extension is generally xxxx.tar.gz2.
Add an option (- j) to the tar command to call bzip2 to implement a compression function, a process of packaging before compression.
Compression usage: tar-jcvf compressed package name file. (tar jcvf bk.tar.bz2 * .c)
Decompression usage: tar-jxvf compressed package name (tar jxvf bk.tar.bz2)
11. File compression and decompression: zip, unzip
The target file that is compressed through zip does not need to specify an extension, and the default extension is zip.
Compressed file: zip [- r] target file (no extension) source file
Decompress files: unzip-d decompress directory files and compress files
twelve。 View command location: which
13. Modify file permissions: chmod
Chmod modifies file permissions in two formats: alphabetical and numeric.
Alphabetical: chmod u/g/o/a + /-/ = rwx file
If you need to set the permissions of owners, peers and others at the same time, refer to the following:
Numerical method: "rwx" these permissions can also be replaced by numbers
For example, to execute: chmod uprirwx chmod gendrx chmod filename is the same as: chmod upright 7 meme gendarmerie 4 filename
Chmod 751 file:
File owner: read, write, execute permissions
Users in the same group: read and execute permissions
Other users: permissions to execute
Note: if you want to recursively add the same permissions to all directories, you need to add the parameter "- R". For example, chmod 777 test/-R adds 777 permissions to all files in the recursive test directory
14. Switch to administrator account
Simple command to switch to root under Ubuntu:
15. Set user password: passwd
In Unix/Linux, superusers can use the passwd command to set or change user passwords for ordinary users. Users can also use this command directly to change their password without the need to use a user name after the command.
16. Log out of login account: exit
If it is a graphical interface, exit the current terminal
If you are logging in remotely using ssh, log out of the login account
If it is a login user after switching, exit will return to the previous login account.
17. View logged in user: who
The who command is used to view user information for all currently logged in systems.
Common options:
18. Shutdown and restart: reboot, shutdown, init
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
What are the basic commands in Linux? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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.