Using Linux endpoints is more than just entering commands. By learning these basic techniques, you will gradually master the bash shell, the terminal tool that is used by default on most Linux distributions.
This article is intended for beginners, and I believe that most advanced users already know all of these techniques, but you can still look at them and perhaps learn what you've been missing for so long.
TAB key Auto-complete
Using the TAB key to auto-complete is a basic technique. It can save you a lot of time, and it's also useful when you're not sure how to spell a file name 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 file name, but you have to be careful with the wrong whitespace (you need to escape). If you type "RM r" and then press TAB, Bash will automatically complete the name of the file 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", when you press the TAB key, bash will complete the "really\" section, because all two files start with this. Then, press TAB again and you will see a list of all the files that can match that beginning, such as.
Then enter the file name you want and press the TAB key. This way, when we lose "L" and then press the TAB key, Bash automatically complements the file name we want.
This method is also applicable for input commands. When you're not sure what command you want, just remember to start with "gnome" and then press TAB and you'll see all the possible results.
Pipeline command
The pipe command allows you to transfer the output of one command to another command. In the design philosophy of UNIX, each program is a function of only few but good. 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 was made.
Put both of these through the pipe command (with the "|" Symbol) together, you can search for a file in the current directory, and the following command searches for "really":
- ls | grep really
Wildcard characters
The asterisk "*" is a wildcard 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:
- RM Really*name
This command removes all files that begin with really and end with name. If you use the "rm *" command, all files in that directory will be deleted and all should be used with caution.
Output redirection
The "" "character can redirect the output of one command to a file without needing to use another command. For example, the code uses the "LS" command to list all the files in the current directory and input the output list to a file named "File1" instead of just the output displayed on the terminal.
- ls > File1
Command line History
Bash remembers the history of the commands you've used. You can use the UP ARROW and DOWN ARROW keys to scroll through the commands you've already used. Using the "History" command will print out the historical commands, so you can use the pipe command to search for the commands you have recently used.
There are a lot of tricks you can use about command line history:
~,.&.
The tilde "~" represents the current user's home directory. So, you can use "CD ~" to switch to your home directory without entering "Cd/home/name". This is also used for relative paths, such as "CD ~/desktop", which switches to the current user's desktop directory.
Similarly, the "." Represents the current directory, "..." Represents the parent directory. All, "CD.." Jumps to the parent directory. This is also true for relative paths, such as when you are in the desktop directory and you want to switch to the document directory sibling to the desktop directory, you can use the CD. /documents "command.
Running commands in the background
By default, bash runs your commands under the current terminal. Normal, no problem, but what if you want to run an application at the same time and continue to use the terminal? For example, if you enter "Firefox" command to run Firefox, Firefox will occupy your terminal and display some error messages such as output until you close it. But adding a "&" symbol behind the command causes bash to run the program in the background:
- Firefox &
Conditional execution
You can also run two commands with bash, one after the other. The second command runs only when the first command is successfully completed. To do this, separate the two commands in the same line with a "&&".
For example, the "Sleep" command takes a parameter in seconds and then the countdown, allowing the end. This command is useless if you use it alone, but you can take it as a delay before running the next program. The following command stops for 5 seconds and then runs the Gnome screenshot tool:
Sleep 5 && gnome-screenshot
Transfer from http://www.geekfan.net/7112/
Go Linux Novice Prerequisites: 8 useful Linux terminal commands