Table of Contents
Guide Chapter
Command line overview
Command Line and Terminal
Open the command line
What can the command line do?
Advantages of the command line
It gives you God-like system permissions
It's extremely fast
It can do things that other languages ​​cannot do
Use an application instead of command line
Next steps
Home Web Front-end CSS Tutorial A Deep Look at the Command Line

A Deep Look at the Command Line

Mar 15, 2025 am 11:26 AM

A Deep Look at the Command Line

We have learned about the meaning of npm, and its role and position in web development. Next, we will take some time to understand the command line, as it is how we interact with npm.

Guide Chapter

  1. Who is this guide for?
  2. What does "npm" mean?
  3. What is the command line? (Your current location!)
  4. What is Node?
  5. What is a package manager?
  6. How to install npm?
  7. How to install npm package?
  8. What is the npm command?
  9. How to install an existing npm project?

Command line overview

The command line is a place where we can enter (unexpectedly) commands that will be executed directly by our computer. It's extremely fast and has higher administrator privileges than most applications that try to handle the command line for you. Need to install something on the system, or update it? The command line can do this, let alone uninstall them. Even server-side languages ​​can run on the command line, opening up a range of tools and development techniques.

For these reasons, the command line is considered an indispensable tool for many developers. Even if you are not a developer, you are likely to have encountered the command line at some point. Maybe you visited it when you opened a terminal application in MacOS. Maybe you're using a command line built directly into the code editor - VS Code and many other code editors come with an integrated terminal. Maybe you've even come across third-party terminal applications like iTerm or Hyper.

If you've used a terminal, most of your command line usage so far may just be typing (or pasting) the commands someone else gave you. This is good; it's usually how we get things done.

But let's take a moment to understand what the command line is and why it's used so widely.

Command Line and Terminal

"Command Line" and "Terminal" are technically two different and very different things, but are often used interchangeably. You may also hear that the command line is called "shell", or see that it is abbreviated as "CLI", which is the abbreviation for "Command Line Interface".

Putting aside those nitpicking differences, these terms are often used to mean almost the same. So, to be as simple as possible, I will use them interchangeably from now on.

Open the command line

No matter why you want to call it, you might think of the command line as that scary-looking window, perhaps a black background and white (sometimes green) text where you can type commands your computer seems to understand, even if you don't.

Depending on where and how you work on the command line, one unremarkable thing you might notice is the dollar sign character $, which is displayed on the first line you can start typing. You may even see it in other articles or documents.

It is usually a convention to use the $ character as the prefix of the command - but this is indeed a confusing convention. This is because there is no need to type it. It is not actually part of the command. Instead, $ represents a command to run in the terminal.

So here is the first rule about using the command line: If you find yourself typing or copying a directive containing the $ character, know that you don't need to include it in your work; the terminal already includes it.

 <code>## 无需复制$ $ npm run build</code>
Copy after login

You may see other characters starting a line instead of $, such as >, _, or even arrows. Again, whatever it is, it almost certainly isn't meant to be typed directly or pasted into the command line. Whether the documentation or other tutorial should contain a line of starting characters is a completely different discussion (Chris has discussed it in detail). Either way, it can be confusing, so I want to make sure this is pointed out.

What can the command line do?

Movies and TV shows often portray terminals as quick typing tools used by hackers in dark, secluded rooms. Part of this is simply because it provides good entertainment for people who may not know the difference between the real terminal and the cascade letters in The Matrix. (Neither should they; I can’t tell if the surgery depicted on the TV show is accurate and leave this distinction to the professional with complete satisfaction.)

But the command line is not entirely used to write code. As the name "command line" implies, it is used to write commands . I think you can say that all encodings are commands to some extent, so this is undoubtedly a blurred line. But generally speaking, the code in the terminal is written differently than in the code editor. Instead, you use a terminal to direct your computer to run commands you want it to run immediately .

Advantages of the command line

You might be wondering why developers like to work on the command line in the first place. You might prefer a nice app or graphical user interface (GUI for short, sometimes pronounced as "gooey"), where you can see all the options and intuitively find the best ones. This is absolutely fine, we will discuss the GUI in this chapter and provide some examples.

Many developers feel this way, even if it doesn't look like it. However, working on the command line brings some advantages that visual applications are not always easy to replicate.

It gives you God-like system permissions

The command line is what computer science workers call a "privileged environment." This may sound like it refers to the Yale fraternity, but it simply means it's a place that has little to no limit on what you can do; a place without guardrails.

This is where the command line’s reputation comes from—whatever command you type, it will be executed immediately as long as it works, and is often irreversible. It is able to interact with hidden files that the operating system tries to block you from editing. You can access anything in the system. You can even interact with similar core files on remote servers—we all know the proverb, great responsibility comes with this power.

It may be helpful to treat the command line as a lazy security guard. It assumes that you always know what you are doing and lets you go directly through the entrance. It's really a bit of a risky one, yes, but it also makes it very powerful and perfect for certain tasks and projects.

It's extremely fast

Another advantage of the command line over a typical application is that it is very fast .

This is not always the case; the speed of the command line is often exaggerated and depends to a large extent on the task in question. But when it does get faster, it can usually be many times faster. In addition, the real flash of the command line is often where the code project needs the most speed, that is, downloading and creating files.

As we will see in other chapters of this guide, a key part of npm is installing things on your machine (usually in the specified folder of the project you are working on). This is why the command line works well with package managers (we will also understand what this means) like npm – it downloads and transfers files between computers – is usually much faster, much faster, than using a browser to do this.

The command line enables npm to generate large amounts of files at incredible speeds. The ability to run a single command at lightning speed to install, update or delete these files simultaneously makes the terminal the fastest and most effective tool for many jobs.

It can do things that other languages ​​cannot do

Another reason why working in a terminal is that many of the tools you may want to use in your project can be used without any additional settings.

But let's review it a little.

When you hear the phrase "server-side language", you may think of PHP, Ruby, or Java. Perhaps a new member of the field, such as Rust or Go. You may even already know that Node belongs to the list, but if not, forgive me a little bit ahead of time.

Anyway, when most people think of these server-side languages, they tend to think of a web server that waits for a request and then responds to them. For example, WordPress is idle until it receives a request to start PHP. When you send a new tweet, that is a request to the Twitter server, which eventually arrives at the Ruby method in Rails.

Server-side languages ​​are considered to be more powerful than web languages. HTML, CSS, and JavaScript are great, but they can't handle file systems, send emails, process images, issue system commands, interact with the operating system, or run scheduled tasks; and many other things that an application or website may need to do. By default, JavaScript in the browser won't even run unless someone is actively viewing the web page in the browser.

Server-side languages ​​are generally considered to be a powerful engine behind more powerful applications and software. And, in many cases, this is accurate. But let's take a moment to realize that in order to run the code, your machine is a server . Not a web server, although (it could be one, but that would be weird and probably unwise). But it's a server anyway.

You can install and run any of the server-side languages ​​we mentioned, maybe you have done so at some point (or at least tried). You might have PHP installed so that you can run WordPress (although there are better ways to do this now), or you might have Ruby installed so that you can follow some tutorials on Rails, to name a few.

Or, maybe not. Maybe you have never installed the entire programming language before. Either way, just know that these languages ​​run on the server , not on the web browser - for that, your machine is a server.

Apart from that, many of the tools you may want to use in your development workflow—such as Sass for compiling CSS—actually run on a server-side language. So use the command line to place you where all the most powerful tools are available at any time.

Use an application instead of command line

We briefly introduce the GUI before this article. It is worth noting that some command line tasks have corresponding GUIs that make the command line work more intuitive and programmatic.

Good examples include GitHub Desktop (for managing code repositories) and CodeKit (for processing, bundling, and compiling assets), although the Source Code Management tab in VS Code also qualifies. Even though these GUIs are often focused on specific tasks, they allow you to complete tasks in real application windows outside of the terminal window through a beautiful visual user interface.

GUI is great as an option, and although I've been used to working on the command line over the years, I still want to have more GUIs to do the things that command-line makes possible – for my own convenience and lowering the barriers to entry for new developers.

However, the reason I believe there are no more such applications is speed. Building a command line interface (CLI) is much faster and easier than building a complete application, usually several orders of magnitude faster. So if we want to get something good today, the command line is usually where we need to go.

Next steps

We just spent some time getting familiar with the command line. Even if the command line is not npm specific , it is the core of working with npm. It is the interface we tell the system what to do, and it gives us amazing ability to complete a large number of tasks at an extremely fast speed at the system or server level. As a package manager, npm is responsible for installing, updating, and deleting files (and other things) for web projects. The command line is the way we communicate with npm to do all of these operations.

Next, we will break down in more detail what npm is by focusing on the first letter in the abbreviation: "n" stands for Node. What is that, why is it in the name? This is what we are paying attention to next.

← Chapter 2 Chapter 4 →

The above is the detailed content of A Deep Look at the Command Line. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles