Do not be afraid of command line-Mac OS

Source: Internet
Author: User

Do not be afraid of command line-Mac OS

Accept the most useful tools on your computer.

You should have seen it in a movie, even though it has never been raised on your computer: a blank screen with some simple text prompts and a cursor, waiting for you to enter several mysterious commands, you will hear your instructions.

This is the command line. It is a character-based interface, which is earlier than the Windows, icons, and tiles on mainstream operating systems (including Windows to Mac OS X and Linux) that people are familiar.

Command Line is a super powerful tool that uses the basic functions of your computer. For most people, it is also confusing, difficult to understand, and seemingly insignificant. But this is not the case.

Computers under your command control

Enter the character command and press enter to let the computer do something. It sounds like a huge step back to sliding and clicking on the mobile device's touch interface. Even a toddler can use an iPad, right? However, if you know how to use it, the command can save your time and reduce your troubles.

If you really want to learn programming-or want to understand computer technology-you have to master the command line.

Going deep into the command line will teach you a lot about how computers work and manage information. You may find that some common mouse operations are faster.

More importantly, you will be more likely to understand programming languages like Python and software like Git, requiring a little command line basis. Once you are familiar with the command line, you can break the barriers that have prevented you from learning programming in the past.

So here is a quick and Basic Guide on command line. It mainly focuses on Mac OS X Unix-like environments, just because it is familiar to me. Linux users should already be familiar with command line, but new users may still find these tips a bit useful. If you are using Chromebook, Google has provided useful guidance on how to open its own command line tool, which is similar to Mac or Linux. Unfortunately for Windows users, restricted by the command language derived from the MS-DOS, it has only a little bit of intersection with Unix, so this guide is useless to you; however, you can check the information on the dosprompt.info website.

How to start

The first thing you need to do is to figure out how to enter the command line. It is usually done through a software called "shell. Start the terminal application on any Mac running OS X. You can open it through the Finder (it is in the utility directory under the application), or click the magnifier in the upper-right corner of the screen, enter "terminal", and select from the drop-down list.

You are in, but all you see is a blank box with input space. This is the command line! Let's take a better look at this window.

Enter pwd to print the current working directory. In computer languages, printing has nothing to do with paper. It actually just means throwing something on the screen. The result of running this command is to let the computer return the directory path you are currently in. (LCTT annotation, "printing" is derived from the early computer output device is not a display, but a line printer, so the output is "printing"; later, with the display, when operating the remote host on a dumb terminal, the output is echo ")

Actually,/Users/laurenorsini is my main directory. Tip: You can use a Tilde (~) As the abbreviation of your home directory-it is the same as/Users/your user name. For example, you can ~ /Downloads reference your download directory. (If you carefully read the preceding command prompt, you will find a Tilde. This indicates that I am currently in my home directory .)

We certainly don't want our command line experiment to mess up our main directory, so let me use the mkdir command to create a new directory. This is the same as creating a new directory in the desktop operating system. Let's call it "experiments ":

Now we have a new directory. If the graphic interface is used, we can use our own eyes to determine that we have created a new directory. Of course, if I open the Finder and enter my home directory (marked with a small house icon), I will see a directory named "experiments. I implemented it through command line! (In turn, you can create a folder in the Desktop System and view it on the command line. This is only two different representations of the same system .)

Now I need to use the cd (change path) command to change the path ~ /In the experiments directory

My command prompt is set by default, so it automatically displays my current working directory. However, if you look different, you can confirm that "experiments" is the current working directory: Enter pwd again. It should tell you that the current working directory is "experiments ".

Create an archive

Every day I write code, I create and edit files through the command line. It is faster than using a graphical user interface because I can test my program in the command line right after editing. If I need to push it to GitHub at the same time, well, it is more convenient.

Now you have a new directory (also known as a repository or folder) on your computer. Let's start by creating a file that contains the "Hello World" sentence. There are many methods. Here I use the echo command.

Oh no! I spelled "newfile. This is often encountered. Let's take two steps to correct it. First, I will create a file with the correct spelling .)

Then, I will use the mv (MOVE) command to replace the misspelled file with my new file. This is usually the case. The old mv file is a new file ".

Note: Like most commands, music videos are a powerful and misleading command. When we migrate mongonewfil.txtto newfile.txt, the first file will be fully overwritten to the second file. In this example, the content written in newfile.txt will be completely replaced by the content written in newfil.txt.

To prove that there is only one file in my directory, you can use the ls and configuration commands to obtain the list of all files in the directory.

Did you see it? Only one. Then, if I look at this directory in the graphic interface, I can also see this file.

However, it is just a blank text file (LCTT annotation, not blank, its content is "Hello World "). Let's enter the vertex content in the text editor. In the command line, I like to use the nano editor because it is very simple and can be used on almost all types of computers. (LCTT, as a Linux party, it must use vi, but vi is a little difficult for beginners .)

This will immediately open the editing screen in your command line window. Some basic commands are listed for you.

Write down what you want to say and exit with CTRL + X. When it asks if you want to save it, of course, type "Y ".

You can also find these changes in the newfile.txt file by using the mouse in the operating system. You can use any text editor you like to open and edit the file you created.

If you want to delete this file forever, run the rm (remove) command:

Note that the rm command is very powerful! A common trick in hacker forums is to persuade a newbie on the command line to input rm-rf/, and then delete all the files on his computer. The "/" in the command indicates the top root directory of the Computer-everything is under it. Do not enter that command! (LCTT: I hope you haven't entered rm-rf/before reading this sentence /!!!)

Additional reading

This is just the beginning of an infinitely possible command line. You can use this tool to control every aspect of the computer, which makes it powerful and dangerous. Make sure you read the command line prompt before using them, and never blindly enter the statements recommended to you by any stranger.

I have introduced several frequently used commands for coding, but there are more reasons to master the command line. If you want to know more thoroughly, you can try:

Command Line quick tutorial. A free extension course covers the basics of command line applications.

Beginners of the command line are enlightened. The Lifehacker favorites are some useful commands for beginners.

Mac OS X command line entry. The online education website Treehouse provides a detailed introduction to the basics of command line.

After reading this article, you will be more likely to understand the code and tutorials I have previously written, because it cannot be completed without several commands. If you are ready, I suggest you go to the ReadWrite Git tutorial, which uses the command line to introduce collaborative programming to you. Computing is with you!

The topic is from Jason Scott. Other screens are provided to ReadWrite by Lauren Orsini.

This article permanently updates the link address:

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.