征服命令行

by Monica Powell

莫妮卡·鲍威尔(Monica Powell)

UNIX / Mac OS终端入门简要指南 (A brief guide to getting started on UNIX/Mac OS terminal)

When I was first introduced to the command line I really had to adjust to navigating my computer in a black box with just text. So I avoided the command line as much as possible. I was accustomed to the visual cues and feedback that a computer usually provides. In many ways it felt like I was re-learning how to use a computer via the command line.

当我第一次被介绍到命令行时,我真的不得不调整为在只显示文本的黑盒子中导航计算机。 所以我尽量避免使用命令行。 我习惯了计算机通常提供的视觉提示和反馈。 从许多方面来说,感觉就像我正在重新学习如何通过命令行使用计算机。

Yet, since first learning how to navigate my computer using UNIX commands I’ve learned that the command line doesn’t have to be a scary thing just because there’s no visual feedback when typing a password in on the command line. As security, nothing shows up as you type in your password to indicate that any characters have been entered.

但是,自从首次学习如何使用UNIX命令导航计算机以来,我已经知道命令行不必是一件令人恐惧的事情,这仅仅是因为在命令行中输入密码时没有视觉反馈。 为了安全起见,在您输入密码以表明已输入任何字符时,不会显示任何内容。

什么是命令行? (What is the command line?)

The command line is a software that executes commands or instructions for a computer to manipulate or interact with its file system.

命令行是一种执行命令或指令的软件,供计算机操纵或与其文件系统交互。

什么是UNIX? (What is UNIX?)

为什么要使用命令行? (Why Use the Command Line?)
  • Faster to modify, navigate between files

    修改速度更快,在文件之间导航
  • Able to install software as a superuser

    能够以超级用户身份安装软件
  • Can see hidden dotfiles

    可以看到隐藏的点文件

    dotfiles are UNIX configuration files, they tend to be files that are proceeded with a

    点文件是UNIX配置文件,它们通常是以。开头的文件

    . and are hidden to normal users.

    . 并向普通用户隐藏。

    You can

    您可以

    learn more about getting started with dotfiles in this article).

    在本文中了解有关点文件入门的更多信息

In order to get started on the command line you should navigate to your applications and open the Terminal application.

为了从命令行开始,您应该导航到您的应用程序并打开Terminal应用程序。

在命令行上创建一个基本的网站文件夹 (Create a Basic Website Folder on the Command Line)

A folder with the above structure can be create on the command line by typing the commands inside of an empty directory:

通过在空目录内键入命令,可以在命令行上创建具有上述结构的文件夹:

  • Make a directory (also known as a folder) called personal-website

    制作一个称为个人网站的目录(也称为文件夹)

    Make a directory (also known as a folder) called personal-websitemkdir personal-website

    制作一个称为个人网站mkdir personal-website的目录(也称为文件夹)personal- mkdir personal-website

  • Navigate to inside of the directory called personal-website

    导航到名为个人网站的目录内部

    Navigate to inside of the directory called personal-websitecd personal-website

    导航到名为personal- cd personal-website的目录的内部cd personal-website

  • create a directory, inside of the personal-website folder called assets

    在个人网站文件夹内创建一个称为Assets的目录

    create a directory, inside of the personal-website folder called assetsmkdir assets

    在个人网站文件夹内创建一个名为mkdir assets

  • Navigate inside of the assets folder which is inside of the personal-website folder

    导航到个人网站文件夹内的资产文件夹内

    Navigate inside of the assets folder which is inside of the personal-website foldercd assets

    导航到个人网站文件夹cd assets内的assets文件夹内

  • create a directory, inside of the assets folder named images

    在资产文件夹内创建一个名为images的目录

    create a directory, inside of the assets folder named imagesmdkir images

    在资产文件夹中创建一个名为images mdkir images

  • create a directory, inside of the assets folder named js

    在资产文件夹js中创建一个目录

    create a directory, inside of the assets folder named jsmkdir js

    在资产文件夹js中创建目录mkdir js

  • create a directory, inside of the assets folder named css

    在资产文件夹css内创建一个目录

    create a directory, inside of the assets folder named cssmkdir css

    在资产文件夹css的内部创建一个目录mkdir css

Woops! We forgot to create an index.html file :(

哇! 我们忘记创建index.html文件了:(

We are in the assets folder and want an index.html file in our main personal-website folder. Typing cd .. will move us out of the assets folder and into the directory above which is personal-website. Now that we are in the personal-website folder if we type touch index.html a blank index.html file will be created.

我们在assets文件夹中,并且在我们的个人网站主文件夹中需要一个index.html文件。 输入cd ..将把我们从资产文件夹移到个人网站上方的目录中。 现在,如果我们输入touch index.html ,我们将位于个人网站文件夹中,将创建一个空白的index.html文件。

一些常用的终端命令是: (Some frequently used terminal commands are:)

导航/操纵文件系统的命令 (commands to navigate/manipulate the filesystem)

ls list the contents of a directory

ls 列出目录的内容

pwdprint working directory for the terminal to display the directory you are currently working on

pwd 打印终端的工作目录 ,以显示您当前正在使用的目录

touch create or open a file without making any changesvery handy when wanting to create empty files without leaving the command line

想要创建空白文件而无需离开命令行时, 轻触创建或打开文件而无需进行任何更改

sudo this allows you to run commands as a super user

sudo这允许您以超级用户身份运行命令

mv move a file or directorythis can be used to move or rename a file by updating the file path

mv 移动文件或目录,可以通过更新文件路径来移动或重命名文件

cd change the current directory you are working on so that you can access files on a different part of the systemcd moves you to the root directory (top level folder on computer — usually the current User)cd . current directory cd .. navigates to directory two levels up

cd 更改您正在使用的当前目录 ,以便可以访问系统其他部分的文件cd将您移至根目录(计算机上的顶级文件夹,通常是当前用户) cd . 当前目录cd ..导航到上一级目录

mkdir make a new directory (or a folder)

MKDIR 创建一个新的目录 (或文件夹)

安装软件的命令 (Commands to Install Software)

You can install some software from the command line using the following commands:

您可以使用以下命令从命令行安装某些软件:

  • in Python pip install <package name>.

    在Python pip install <package nam e>。

    Pip is a software package manager for Python.

    Pip是Python的软件包管理器。

  • in JavaScript npm install <package name>

    在JavaScript npm install <package na me>

    NPM is a package manager for JavaScript pages.

    NPM是JavaScript页面的程序包管理器。

运行软件的命令 (Commands to Run Software)

In order to run a script on the command line you need to provide a command prompt and file name. Some examples are:

为了在命令行上运行脚本,您需要提供命令提示符和文件名。 一些例子是:

  • in Java javac filename.java and then java filename compiles java projects and then runs them.

    在Java中使用javac filename.java ,然后java filename编译Java项目,然后运行它们。

  • in Python python filename runs python scripts.

    在Python中, python filename运行python脚本。

If you find you are repeating a lot of commands you can scroll through your recent commands using the up/down arrows and edit them and re-run by navigating to them and then pressing enter.

如果发现您正在重复很多命令,则可以使用向上/向下箭头滚动浏览最近的命令,并编辑它们,然后通过导航到它们然后按Enter来重新运行。

命令行提示入门的其他资源 (Additional Resources to Get Started with Command Line Prompts)
装饰命令行 (Decorating the Command Line)

You can completely customize the colors and outputs on the command line to better suit your visual and aesthetic needs.

您可以在命令行上完全自定义颜色和输出,以更好地满足您的视觉和审美需求。

Here’s how I’ve made my command line prettier :

这是使命令行更漂亮的方法:

How to install Tomorrow Nighthttps://github.com/chriskempson/tomorrow-theme/blob/master/OS%20X%20Terminal/Tomorrow%20Night.terminal

如何安装Tomorrow Night https://github.com/chriskempson/tomorrow-theme/blob/master/OS%20X%20Terminal/Tomorrow%20Night.terminal

Customize the terminalI love the terminal. Besides the fact it makes you look awesome while using it, it can also do about a gazillion…mindthecode.com

定制终端 我爱终端。 除了它使您在使用它时看起来很棒之外,它还可以使您的工作量增加…… mindthecode.com

If you enjoyed reading this article consider tapping the clap button ?. Wanna see more of my work? Check out my GitHub to view my code and learn more about my development experience at http://aboutmonica.com.

如果您喜欢阅读本文,请考虑点击拍手按钮?。 想看我更多的作品吗? GitHub上查看我的代码,并在h ttp://aboutmonica.com上了解有关我的开发经验的更多信息

翻译自: https://www.freecodecamp.org/news/conquering-the-command-line-f85f5e46c07c/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值