8 Tips to make you a very strong Linux end user

Source: Internet
Author: User
Tags parent directory

Using Linux terminals is more than just typing commands. By learning these basic techniques, you'll get a grip on the bash shell, the terminal tool that is used by default on most Linux distributions. This article is written for inexperienced beginners, and I believe most advanced users already know all of these techniques. But you can still look at it and maybe learn something you've been ignoring for a long time.

TAB key Auto-complement

Using the TAB key for automatic completion is the basic technique. It can save you a lot of time, and it's also useful when you're not sure how to spell a filename or command.

For example, in the current directory you have a file, the filename is "really long file Nam", and you want to delete this file. You can enter the entire filename, but you have to be careful with the wrong spaces (you need to escape). If you type "RM r" and then press TAB, Bash will automatically complete the file name for you.

Of course, if you have a lot of files in the current directory that start with the letter R, Bash will not know which one you are referring to. For example, the current directory, you have another name called "really very long file name", and when you press the TAB key, bash will fill the "really" section, because all two files start with this. Then, press the TAB key and you'll see a list of all the files that match the beginning, as shown below.

Then type in the file name you want and press the TAB key. This way, when we lose "L" and press the TAB key, Bash automatically complements the file name we want.

This method is also true for input commands. When you're not sure what the command you want, just remember to start with "gnome" and then press the TAB key, and you'll see all the possible results.

Pipe command

The pipe command allows you to transfer the output of a command to another command. In the design philosophy of UNIX, each program is only a few fewer features. For example, the "LS" command displays a list of all the files in the current directory, and the "grep" command searches for the input string where it is made.

Put the two through the pipe command (with "|") Symbol), you can search for a file in the current directory, and the following command is used to search for "really"

Wildcard characters

The asterisk "*" is a wildcard character that can match anything. For example, if we want to delete "really long file name" and "really very long file name" from the current directory, we can use the following command:

This command deletes all files that start with really and end with name. If you use the "rm *" command, all files in the directory will be deleted, all of which need to be used with caution.

Output redirection

The "" "character can redirect the output of a command to a file without the need for another command. For example, the code below uses the "LS" command to list all the files in the current directory, and the output list is entered into a file called "file1," rather than just the output displayed on the terminal.

Command-line History

Bash will remember the history of the commands you've used. You can use the UP ARROW and DOWN ARROW keys to flip through the commands you've already used. Using the "History" command prints out the history commands, so you can use the pipe command to search for the commands you have recently used.

~,.&.. The tilde "~" represents the home directory of the current user. So, you can use "CD ~" to switch to your home directory instead of typing "cd/home/name". This is also used for relative paths, such as "CD ~/desktop" switching to the current user's desktop directory.

Similarly, "." Represents the current directory, ".." Represents the parent directory. All, "CD ..." Jumps to the parent directory. This is also valid for relative paths, such as if you are in the desktop directory and you want to switch to the document directory at the same level as the Desktop directory, you can use the CD. /documents "command.

Background Run command

By default, bash will run your commands under the current terminal. No problem at all, but what if you want to run an application at the same time and continue to use the terminal? For example, if you enter the Firefox command to run Firefox, Firefox will occupy your terminal and display some error messages, etc. until you close it. But adding a "&" symbol behind the command causes bash to run the program in the background:

Conditional execution

You can also use bash to run two commands, one after the other. The second command runs only if the first command completes successfully. To do this, separate the two commands in the same line with "&&".

For example, the Sleep command takes a single argument in seconds, and then the countdown is allowed to end. This command is not useful when used alone, but you can use it as a delay before running the next program. The following command stops for 5 seconds and then runs the Gnome screen-cutting tool:

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.