在Linux Shell中生存的初学者指南

by Puranjay Mohan

通过Puranjay Mohan

In this article, you'll learn how to kill your fear of the Linux shell by learning the ten most useful Linux commands.

在本文中,您将通过学习十个最有用的Linux命令来学习如何消除对Linux shell的恐惧。

All the best people in life seem to like LINUX - Steve Wozniak

生活中所有最优秀的人似乎都喜欢LINUX- Steve Wozniak

Linux Shell /命令行 (The Linux Shell/Command-Line)

A black screen with white text and no graphics, yes! The Linux Shell does look daunting at first glance, but it is much more powerful than any graphical tool.

黑色的屏幕上有白色文字,没有图形,是的! 乍看上去,Linux Shell确实令人生畏,但它比任何图形工具都强大。

Linux powers 70% of the servers and 90% of super-computers in the world. The learning curve for Linux is steep and to learn it you need to live inside it for some time. Once you get good at the command line, you get a skill which sets you apart from the crowd.

Linux为全球70%的服务器和90%的超级计算机提供动力。 Linux的学习曲线非常陡峭,要学习它,您需要在其中生活一段时间。 一旦您掌握了命令行,就会获得一种使您与众不同的技能。

This article introduces and explains the 10 most useful Linux commands required to survive in the Linux shell environment. After reading this article you should be able to perform all the basic tasks like creating and deleting directories, editing text files, and so on using the command line.

本文介绍并解释了在Linux Shell环境中生存所需的10个最有用的Linux命令。 阅读本文之后,您应该能够使用命令行执行所有基本任务,例如创建和删除目录,编辑文本文件等等。

为什么要学习Linux命令行? (Why should one learn the Linux command line?)

善于使用命令行的好处。 (Perks of being good at using the command line.)
  • You get to know much more about your operating system.

    您将了解有关操作系统的更多信息。

    The shell exposes you to the filesystem more directly than the graphical file browser, it makes you understand the hierarchy and structure of the OS. You also get to play with the configuration files directly and this gives you the power to control your operating system more efficiently.

    与图形文件浏览器相比,外壳程序更直接地向您显示文件系统,它使您了解操作系统的层次结构。 您还可以直接使用配置文件,这使您可以更有效地控制操作系统。

  • You can control computers and servers remotely.

    您可以远程控制计算机和服务器。

    Network protocols like

    网络协议,例如

    SSH and Telnet allow you to remotely connect to computers on a network, but they only provide you with the shell and not the graphical interface. Therefore you can use these protocols only if you are familiar with the shell.

    SSHTelnet允许您远程连接到网络上的计算机,但是它们仅为您提供外壳程序,而不能为您提供图形界面。 因此,只有在熟悉Shell的情况下,才能使用这些协议。

  • You can install Arch Linux without anyone’s help

    您可以在没有任何人帮助的情况下安装Arch Linux

    Arch Linux is a Linux distribution which scares many beginners because of its installation method. To install Arch Linux you need to do all the steps manually from disk partitioning to user creation, using the shell. You need to be very good at the Linux shell to install Arch Linux.

    Arch Linux是一种Linux发行版,由于其安装方法而使许多初学者感到恐惧。 要安装Arch Linux,您需要使用Shell手动执行从磁盘分区到用户创建的所有步骤。 您需要非常精通Linux Shell才能安装Arch Linux。

  • You can get paid to configure and administer Linux Servers.

    您可以获得配置和管理Linux服务器的报酬。

    Most companies have a job posting titled, “Linux System Administrator”. The role of the person at this position is to maintain the Linux computers and make changes and configurations to them as per the requirements. The person at this role has to be very good at the Linux Shell and should know all the commands required to configure a Linux system.

    大多数公司都有一个职位发布,标题为“ Linux系统管理员”。 此职位的作用是维护Linux计算机并根据要求对其进行更改和配置。 担任此职务的人员必须非常精通Linux Shell,并且应该了解配置Linux系统所需的所有命令。

Linux命令提示符 (The Linux Command Prompt)

When you open the terminal app in your Linux distribution, you will see a black screen with your name and some other information printed. After which, you will see a cursor ready to receive commands. The information shown by the prompt is configurable but is beyond the scope of this tutorial.

当您在Linux发行版中打开终端应用程序时,您会看到一个黑屏,上面印有您的姓名和一些其他信息。 之后,您将看到一个准备接收命令的光标。 提示中显示的信息是可配置的,但超出了本教程的范围。

The Prompt provides information about the username, the host name (your computer’s name as it appears on the network), the present working directory and a ‘$’, which signifies that you are a normal user and not the root user (root user has all privileges and rights in Linux).

提示提供有关用户名,主机名(计算机名称在网络上的名称),当前工作目录和“ $”的信息,这表明您是普通用户,而不是root用户(root用户拥有Linux中的所有特权和权利)。

10个基本命令 (The 10 basic commands)

These 10 commands will enable you to experience the shell in a way where you will be able to perform all the tasks that you have been doing in the Graphical User Interface environment, like creating and deleting directories, writing, editing and deleting files etc., in the shell without facing any problems.

这10条命令将使您能够以某种方式体验Shell,从而可以执行在图形用户界面环境中一直在执行的所有任务,例如创建和删除目录,编写,编辑和删除文件等,在外壳中没有任何问题。

1. pwd (1. pwd)

The print working directory (pwd) command prints the complete path to the directory that you are working in. When you open the terminal app it usually starts the shell at your home folder, therefore running the pwd command will print “/home/(your-username). ‘~’ represents home in the prompt.

打印工作目录(pwd)命令将打印出您正在使用的目录的完整路径。当您打开终端应用程序时,它通常会在您的主文件夹中启动外壳程序,因此运行pwd命令将打印“ / home /(您的-用户名)。 提示中的“〜”表示主页。

2.光盘 (2. cd)

Change Directory (cd) command changes the working directory to the directory whose name is given after cd. Writing cd myfolder will change the working directory to ‘myfolder’ and its name will appear in the prompt, but it will throw an error if ‘myfolder‘ doesn’t exist in the current directory.

更改目录(cd)命令将工作目录更改为以cd命名的目录。 写入cd myfolder会将工作目录更改为“ myfolder”,其名称将出现在提示中,但如果当前目录中不存在“ myfolder”,则会抛出错误。

Running ‘pwd’ command after the above step will show the path to the directory, which we switched to.

在上述步骤之后运行'pwd'命令将显示我们切换到的目录的路径。

Running cd .. command will change the working directory to the previous directory in the hierarchy. In this case, it will change back to the home directory.

运行cd ..命令会将工作目录更改为层次结构中的上一个目录。 在这种情况下,它将变回到主目录。

You can also provide the absolute path to the directory, to which you wish to switch. Absolute paths are complete paths starting from the root directory. For example, the absolute path to ‘myfolder’ will be ‘/home/puranjay/myfolder’, which is the same path shown by pwd command.

您还可以提供要切换到的目录的绝对路径。 绝对路径是从根目录开始的完整路径。 例如,“ myfolder”的绝对路径将是“ / home / puranjay / myfolder”,这与pwd命令显示的路径相同。

3. ls (3. ls)

List (ls) command prints the contents of the current working directory, it prints the names of all the files and directories present in the current directory. Running ls in the ‘myfolder’ directory will show its contents, i.e. file1, file2, etc.

List(ls)命令打印当前工作目录的内容,它打印当前目录中存在的所有文件和目录的名称。 在“ myfolder”目录中运行ls将显示其内容,即file1,file2等。

You can also provide the absolute path to the directory whose contents you wish to see. For example, if the working directory is home and ls /boot is run, the shell will print the contents of the ‘boot’ folder present in the root(/) directory. The working directory will not change. Also ‘boot’ and ‘/boot’ don’t imply the same meaning to the shell. ‘boot’ means a directory or a file in the current working directory but ‘/boot’ means a directory or a file present in the root(/) directory. Running ls boot will print an error message because there is no file or folder named ‘boot’ in the current working directory(home).

您还可以提供要查看其内容的目录的绝对路径。 例如,如果工作目录为home,并且运行了ls /boot ,则Shell将打印root(/)目录中存在的“ boot”文件夹的内容。 工作目录不会更改。 同样,“ boot”和“ / boot”对shell的含义并不相同。 'boot'表示当前工作目录中的目录或文件,但'/ boot'表示root(/)目录中存在的目录或文件。 运行ls boot将打印错误消息,因为在当前工作目录(主目录)中没有名为“ boot”的文件或文件夹。

4.男人 (4. man)

man(manual) command will open the manual page for the command given after man. Manual pages contain documentation about all commands available in Linux, they provide information about the correct use of the command and different options available for the command.

man(manual)命令将打开man之后给出的命令的手册页。 手册页包含有关Linux中所有可用命令的文档,它们提供有关正确使用命令的信息以及该命令可用的不同选项。

To exit from man page press ‘q’.

要退出手册页,请按“ q ”。

For example, running the man ls will open the manual page for ls command.

例如,运行man ls将打开ls命令的手册页。

5. mkdir (5. mkdir)

Make-directory (mkdir) command creates a new directory of the name given after the command, in the current working directory. For example, running mkdir hello will create a folder named ‘hello’ inside the current directory. After the directory has been created, running cd hello will change the current directory to the newly built ‘hello’ directory, ‘~’ will change to ‘hello’.

Make-directory(mkdir)命令在当前工作目录中创建一个在命令之后给出名称的新目录。 例如,运行mkdir hello将在当前目录中创建一个名为“ hello”的文件夹。 创建目录后,运行cd hello会将当前目录更改为新建的“ hello”目录,“〜”将更改为“ hello”。

6. rmdir (6. rmdir)

Remove directory (rmdir) removes/deletes the directory with the name given after the command. Running rmdir hello will delete the previously created ‘hello’ directory. A directory cannot be deleted by running rmdir inside the same directory, which is to be deleted. The command cd .. can be used to go out of the directory and then rmdir hello can be run to delete it.

删除目录(rmdir)使用命令后给出的名称删除/删除目录。 运行rmdir hello将删除先前创建的“ hello”目录。 无法通过在要删除的同一目录内运行rmdir来删除目录。 可以使用命令cd ..移出目录,然后可以运行rmdir hello将其删除。

If a directory is not empty and rmdir is run to delete this directory, then it will fail with an error stating that the directory being deleted is not empty.

如果目录不为空,并且运行rmdir删除该目录,则它将失败,并显示一条错误消息,指出要删除的目录不为空。

To overcome this error and delete directories which are not empty, the -- ignore-fail-on-non-empty flag can be passed to rmdir.

要克服此错误并删除不为空的目录,可以将-- ignore-fail-on-non-empty标志传递给rmdir。

For example, running rmdir --ignore-fail-on-non-empty hello will delete the hello directory although it is not empty.

例如,运行rmdir --ignore-fail-on-non-empty hello将删除hello目录,尽管它不是空的。

7.清除 (7. clear)

Clear command cleans the shell and removes all previous outputs. It comes in handy when you want to clear the clutter on the terminal.

Clear命令将清理外壳并删除所有先前的输出。 当您要清除终端上的杂物时,它非常方便。

8.纳米 (8. nano)

Nano is a terminal based text editor, which can be used to create and edit text files and also edit configuration files. It is similar to any other text editor like notepad, the only difference being that it works through the shell and doesn’t have a GUI. It comes pre-installed with most of the Linux distributions.Running nano in the shell opens the nano text editor and provides an interface where text can be typed.

Nano是基于终端的文本编辑器,可用于创建和编辑文本文件以及编辑配置文件。 它与其他任何文本编辑器(如记事本)相似,唯一的区别是它可通过外壳运行且没有GUI。 它预装了大多数Linux发行版。在外壳中运行nano打开nano文本编辑器,并提供一个可以键入文本的界面。

To exit nano, press CTRL+X, it will ask you if you want to save the file.

要退出nano,请按CTRL+X ,它将询问您是否要保存文件。

If you press ‘Y’, it will ask you to enter the name for the file and pressing ‘ENTER’ after typing the name will close nano. A file with the name you gave will be created in the current directory.

如果按“ Y”,它将要求您输入文件名,键入名称后按“ ENTER”将关闭nano。 具有您给定名称的文件将在当前目录中创建。

9.猫 (9. cat)

Cat command is used to print the contents of a file on the shell console, it is mostly used when you want to see what is present inside a file. To use the cat command, cat filename can be run in the shell, it will output the contents of the file on the screen.

Cat命令用于在Shell控制台上打印文件的内容,通常用于想要查看文件中存在的内容的情况。 要使用cat命令,可以在shell中运行cat filename ,它将在屏幕上输出文件的内容。

10. rm (10. rm)

Remove(rm) command is similar to the rmdir command but it deletes files instead of directories. To use this command, rm filename can be run in the shell. It will delete the file if it is present in the current directory.

Remove(rm)命令类似于rmdir命令,但是它删除文件而不是目录。 要使用此命令,可以在外壳中运行rm filename 。 如果文件存在于当前目录中,它将删除该文件。

11. mv(奖金命令) (11. mv (Bonus Command))

mv command can be used for moving or renaming files. Renaming is just moving a file to another name. The mv command has the format, mv source destination. You need to provide the complete path to the source and destination if it is outside the current working directory.

mv命令可用于移动或重命名文件。 重命名只是将文件移动到另一个名称。 mv命令的格式为mv source destination 。 如果源和目标位于当前工作目录之外,则需要提供完整的路径。

注意事项和要记住的要点: (Side notes and points to be remembered:)

  • Linux shell is case-sensitive, therefore ‘desktop’ and ‘Desktop’ don’t imply the same meaning.

    Linux Shell区分大小写,因此'desktop'和'Desktop'的含义并不相同。
  • Care should be taken while writing paths in Linux because ‘boot’ and ‘/boot’ are two different folders.

    在Linux中写路径时应小心,因为“ boot”和“ / boot”是两个不同的文件夹。
  • The only way to master the Linux shell is by spending time in it and using it every day. It is an added advantage if your main OS is Linux.

    掌握Linux Shell的唯一方法是花费时间并每天使用它。 如果您的主要操作系统是Linux,那么这是一个附加的优势。
  • Anything that you do in the Linux OS, try to find a way to do the same thing but from within the shell. Stack Overflow is a great place to get your Linux questions answered.

    您在Linux操作系统中所做的任何事情,都尝试找到一种方法,但要从外壳程序中执行相同的操作。 堆栈溢出是使您的Linux问题得到解答的好地方。

  • If you really want to hone your Linux skills and become a Linux master, then you can read the Linux Bible, which is the most in-depth Linux guide ever written.

    如果您真的想磨练您的Linux技能并成为Linux高手,那么您可以阅读Linux圣经 ,这是有史以来最深入的Linux指南。

结论: (Conclusion:)

My first encounter with the Linux terminal was 5 years ago and I too was very intimidated by it. For these five years, I have been learning something new about Linux every day. The energy and time that you spend while learning Linux is completely worth it and will never go in vain. Linux is the biggest and the oldest Open-Source project and learning it is the first step in the process of contributing to it.

我第一次接触Linux终端是在5年前,我对此也感到非常恐惧。 这五年来,我每天都在学习有关Linux的新知识。 您在学习Linux上花费的精力和时间是完全值得的,并且永远不会徒劳。 Linux是最大,最古老的开放源代码项目,对其进行了解是学习Linux的第一步。

Feel free to point out any mistakes you find, constructive criticism does no harm.

随时指出您发现的任何错误,建设性的批评无害。

Thank You.

谢谢。

翻译自: https://www.freecodecamp.org/news/a-beginners-guide-to-surviving-in-the-linux-shell-cda0f5a0698c/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值