Terminal bash command on MAC (2) Basics

Source: Internet
Author: User
Tags echo command

Open the terminal and enter the command in it. Generally, the terminal has already entered the "$" symbol for you. You only need to enter the specific command.

1. $ echo

Command ECHO: output text

$ echo "hello world"

Input result: Hello World

 

2. $ cd

Command CD: enter a folder directory or return a directory

1) enter the root directory

$ cd /

2) enter a directory (as follows: Enter the bin directory)

$ cd bin   

3) return to the upper directory

$ cd ..

3) return to the upper-level directory (no space in the middle)

$ cd ../ ../

4) enter the user directory (~)

$ cd ~

 

3. $ ls

The LS command displays all the files and folders in the local directory.

$ ls

When LS is followed by a specific directory, enter the detailed directory information of the folder (for example, the bin directory is as follows)

$ ls bin

 

4. $ whereis

Command whereis: Find the path of a program (for example, GCC is as follows)

$ whereis gcc

Input result:/usr/bin/GCC

 

5. Command memory function:

Press the up/down key to view all commands used

These commands are stored in the user directory. bash_history file :~ /. Bash_history

 

6. Automatic completion:

1) press the tab key. When the first word of the next command string is followed, the command is automatically supplemented.

2) press the tab key to automatically complete the file name or file directory after the second word in the next command string.

3) press the tab key twice. (If you press the tab key again in the preceding two cases, the command starting with some letters or all file names in the current directory will be displayed.

 

7. Command alias function: $ alias

When a command is too long, you can use the alias command to set aliases for other commands.

For example, to view all files in the local directory, including hidden files, run the following command:

$ ls -al

To make it easier to remember, you can get an alias lsall for the above command. The operation is as follows:

$ alias lsall=‘ls -al‘

Then you can run the $ lsall command to view all the files in the local directory.

 

8. $ man

Command man is used to view the detailed description file of a command (for example, to view the LS command instructions)

$ man ls     

Enter Q when exiting

 

9. $ type

Command type is used to determine whether a command is a bash built-in command, or from external sources (such as the CD command and LS command :)

$ type cd

Output "CD is a shell builtin", indicating that CD is a bash built-in command

$ type ls

Output "ls is hashed (/bin/LS)", indicating that ls is an external command, followed by the program path

If the alias of a command is lsall, run the $ TYPE command to view the lsall

$ type lsall

Output "lsall is aliased to 'LS-al'", indicating that lsall is the alias of the LS command

10. Cross-line commands, escape Command Execution key (Escape return key)

When you enter a command line that is too long, you can enter "\" first, enter the Enter key, and jump to the next line.

The ">" symbol will appear before the next line, and you can continue to write the uncompleted command

Enter the complete command in two lines, for example:

$ CD/users/xiaoa \ press ENTER

Press enter to replace it with a carriage return, and ">" will appear next to it. Enter "/test" again"

> /test

The two-line command is equal to the following line:

$ cd /Users/xiaoa/test


11. Enter the $ bash command in Bash to start a subbash program and exit the subprogram with the $ exit command.

 

12. Command combination and priority execution

Enclose the command with a single quotation mark (that is, the key on the left side of the number key 1 above the keyboard, not a single quotation mark): Begin command

Or $ (command) to first execute a command, and then use the returned content as the input of other commands, for example:

$ echo `ls -a`
$ echo $(ls -a)

The preceding command statement has the same effect: first use the $ LS command to obtain all the files with file names including. In the current path, and then print the returned results using the $ echo command.

Generally, you need to execute more commands with $ (command), because the single quotation marks are too likely to cause ambiguity.

 

Terminal bash command on MAC (2) Basics

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.