Basic linux commands

Source: Internet
Author: User
Basic linux commands-general Linux technology-Linux technology and application information. For more information, see the following section. 1. view the current working directory
# Pwd (print working directory), you can see your current full directory path
2. Change the Directory
# Cd where
Cd is returned to the initial directory when the user logs on.
Cd-is used to return to the initial directory at login.
Cd/to the root directory of the system
Cd/root to the root user's home directory, so that you have the corresponding permissions.
Cd/home to the user's home directory, usually the initial directory when the user logs on to the system
Cd .. Go Back To The parent directory
Cd-otheruser to the initial login directory of other users pointed out by otheruser, provided that you have the corresponding authorization
Cd pathname refers to the directory indicated by pathname. pathname can be a relative or absolute path.
When using the "cd/root" command, if you do not log on as the root user, you need to change your identity. At this time, you can use the su command to temporarily Log On As another user, use exit to restore your identity.
3. view directory content
# Ls
# Ls-a indicates all, listing all files in the directory, including hidden files.
-L indicates long, which lists the license, owner, group, size, creation date, and whether it is a link.
-F indicates the file type. After each item is listed, add a symbol representing the file type./indicates that the item is a directory and @ indicates that the item is a symbolic link, * indicates that this item is an executable file.
-R indicates reverse, listing contents in the directory from the back to the back.
-R indicates recursive, recursively listing the contents of all directories in this directory.
-S indicates the size, which is arranged by size.
4. Locate files and directories
# Locate file
Note: Work is automatically completed by a cron job in the system. cron is a small program executed in the background. It is responsible for regularly executing some pre-arranged tasks, updating the locate database is one of them. The update operation can be performed at night, so the previous shutdown operation may limit the database update. You can use the command
# Updatedb manually updates the database
5. Command Line Printing
# Lpr file name
To print foo.txt, enter the # lpr foo.txt command at the prompt. Use The lpq command to view all tasks in the print queue. The command output is similar
# Active root 386 foo.txt
This indicates that the root user prints the foo.txt file, where 389 is the job number.
You can use the "lprm job number" command to cancel a job in the print queue.
6. Clear and reset the terminal window
# Clear
7. List and merge files
# Cat
For example, "cat filename.txt" will display the content of filename.txt. If the content of the file is very long, the previous content will flash on the screen. You can use "cat filename.txt | less"
8. Use redirection
Redirection refers to Resetting the standard input and output of the shell. When the system starts, the default keyboard is the standard input, the display is the standard output, and redirection is used, you can temporarily change the behavior of the shell.
> A symbol is used to repeat the standard input. It is followed by the input command or program name. For example, when you directly use the ls command, the listed file information will be displayed on the screen, and after "ls> ls.txt" is used, the listed file information will be written into the file ls.txt. Using this technique, combined with the previously learned cat command, you can easily create some simple text files without opening VI, for example: # cat> note.txt
Press enter to enter a new blank line. After entering some text, press enter to end the line and press ctrl + d to end the entire command.
9. append output redirection
When you use> for redirection, if the targeted target file already exists, its original content will be overwritten by the new content, and the system will not give a prompt, there is no time to expect this, you may only want to add the new content to the end of the original content. Use>.
# Cat hello.txt> world.txt
: This command is used to add the content of the hello.txt file to the end of the world.txt file.
10. Redirect standard input
# Cat Then, the catcommand does not need to be input from the standard input, that is, the hello.txt file is read directly and its content is displayed.
11. Pipelines
# Ls-al/etc | less
There are a lot of content in the/etc, and the above command can be displayed on one page,
# Grep female list.txt | lpr
This command prints the lines containing the words female in the list.txt file.
12. more command
The more command and the less command have similar functions. The only difference is that less uses the arrow keys to flip back and forth, and more uses the Space key and B key to move backward or forward.
Use the q key to exit.
13. Read text commands
1. The head command is used to view the header information of a file. By default, it is the first 10 lines of text starting from the first line. You can specify the number of lines as the parameter to view,
# Head-20 filename
2. The tail command is opposite to the head command. You can view the last 10 lines of the file.
3. The grep command is used to search for rows containing the specified string in the file. For example, grep female list.txt will display all rows containing the word female in the file list.txt, without other parameters, search is case sensitive. The enable I is case-insensitive.
3. There are two wildcard characters: * And ?. * The function is to replace one or more characters, faces, and? It can only replace one character, for example
# Ls hello *. txt
Find the desired file, such as helloword.txt?hello1.txt.
# Ls hello ?. Txt
Only files like hello1.txt can be found.
If the file name contains * or? If the file needs to be printed, you must enter
# Cat hello *. txt
It is used to tell the system that the asterisk or question mark at the end is not a wildcard. But a file name.
14. Command Line history
Up to 500 commands can be saved in bash. The value 500 is saved in the environment variable HISTFILESIZE. You can run the "env" command to view the value.
You can use the Tab key for command completion.
If it is updated and press the Tab key, the system will complete the command as updatedb. If you only enter up and press the Tab key, you will hear a computer beep, because the system finds multiple commands that can be supplemented UP, press the Tab key to view the list of available commands.
15. Enter multiple commands at a time
How many commands can be entered at a prompt in Linux. The methods are separated by semicolons (;). For example:
# Date; mozilla; date
Press enter, print the date that appears, and then start the browser. After exiting from the browser, print the time again. From the time difference between the two times, you can see how long you have been surfing the Internet.
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.