zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Introduction to Command Line

to Command line Introduction
2023-09-14 09:13:32 时间

What is the command Line?

The command line is a text interface for the computer's operating system.You can use it to traverse and edit your computer's filesystem.Though the command line, you can create new files, edit the contents of those files.delete files.and more.

On Mac and Linux systems, we access the command line through something called bash.

  • Navigation
  • Manipulation
  • Redirection
  • Configuration

Introduction

The command line is a text interface for your computer.It's a program that takes in commands and passes them on to the computer's operating system to run.

The advantage of using the command line is its power.You can run  programs, write scripts to automate common tasks, and combine simple commands to handle difficult tasks.All of these traits come together to make it an important programming tool.

Filesystem

A filesystem organizes a computer’s files and directories into a tree structure:

  1. he first directory in the filesystem is the root directory. It is the parent of all other directories and files in the filesystem.
  2. Each parent directory can contain more child directories and files. 
  3. Each directory can contain more files and child directories. The parent-child relationship continues as long as directories and files are nested.

ls

The first command we’re going to look at is ls. A command is a directive to the computer to perform a specific task. When you type ls, the command line looks at the directory you are in, and then “lists” all the files and directories inside of it. Be sure to type the letter l as in “List” and not the number 1.

In the terminal, the first thing you see is $. This is called a shell prompt. It appears when the terminal is ready to accept a command.

pwd

The next command we’re going to look at is pwd, which stands for “print working directory.” It outputs the name of the directory you are currently in, called the working directory.

Together with ls, the pwd command is useful to show where you are in the filesystem.

cd I

Our next command is cd, which stands for “change directory.” Just as you would click on a folder in Windows Explorer or Finder, cd switches you into the directory you specify. In other words, cd changes the working directory.

cd II

Instead of using cd twice in order to move from 2015 to memory, we can use it once and give it a longer argument:

$ cd jan/memory

To navigate directly to a directory, use cd with the directory’s path as an argument. Here, cd jan/memory navigates directly to the memory directory.

To move up one directory, we use cd ..:

$ cd ..

Here, cd .. navigates up from jan/memory/ to jan/.

mkdir

Now that we can traverse the existing filesystem, let’s try editing it by making directories (folders) through the command line. The command for that is mkdir:

$ mkdir media

The mkdir command stands for “make directory”. It takes in a directory name as an argument and then creates a new directory in the current working directory.

Here we used mkdir to create a new directory named media/ inside our working directory.

touch

Now we know how to create directories through the command line, but how do we create new files?

We can do this using the command touch:

$ touch keyboard.txt

The touch command creates a new file inside the working directory. It takes in a filename as an argument and then creates an empty file with that name in the current working directory.

Here we used touch to create a new file named keyboard.txt.

Helper Commands

Now that we’ve covered the basics of navigating your filesystem from the command line, let’s look at some helpful commands that will make using it easier!

clear is used to clear your terminal, which is useful when it’s full of previous commands and outputs. It doesn’t change or undo your previous commands, it just clears them from the view. You can scroll upwards to see them at any time.

tab can be used to autocomplete your command. When you are typing the name of an existing file or directory, you can use tab to finish the rest of the name.

The up and down arrows (↑ and ↓) can be used to cycle through your previous commands. ↑ will take you up through your most recent commands, and ↓ will take you back through to the most recent one.