Linux中国

Linux 命令行简介

如果你是 Linux 新手,或者从来没有花时间研究过命令行,你可能不会理解为什么这么多 Linux 爱好者坐在舒适的桌面前兴奋地输入命令来使用大量工具和应用。在这篇文章中,我们将快速浏览一下命令行的奇妙之处,看看能否让你着迷。

首先,要使用命令行,你必须打开一个命令工具(也称为“命令提示符”)。如何做到这一点将取决于你运行的 Linux 版本。例如,在 RedHat 上,你可能会在屏幕顶部看到一个 “Activities” 选项卡,它将打开一个选项列表和一个用于输入命令的小窗口(类似 “cmd” 为你打开的窗口)。在 Ubuntu 和其他一些版本中,你可能会在屏幕左侧看到一个小的终端图标。在许多系统上,你可以同时按 Ctrl+Alt+t 键打开命令窗口。

如果你使用 PuTTY 之类的工具登录 Linux 系统,你会发现自己已经处于命令行界面。

一旦你得到你的命令行窗口,你会发现自己坐在一个提示符面前。它可能只是一个 $ 或者像 user@system:~$ 这样的东西,但它意味着系统已经准备好为你运行命令了。

一旦你走到这一步,就应该开始输入命令了。下面是一些要首先尝试的命令,以及这里是一些特别有用的命令的 PDF 和适合打印和做成卡片的双面命令手册。

命令 用途
pwd 显示我在文件系统中的位置(在最初进入系统时运行将显示主目录)
ls 列出我的文件
ls -a 列出我更多的文件(包括隐藏文件)
ls -al 列出我的文件,并且包含很多详细信息(包括日期、文件大小和权限)
who 告诉我谁登录了(如果只有你,不要失望)
date 日期提醒我今天是星期几(也显示时间)
ps 列出我正在运行的进程(可能只是你的 shell 和 ps 命令)

一旦你从命令行角度习惯了 Linux 主目录之后,就可以开始探索了。也许你会准备好使用以下命令在文件系统中闲逛:

命令 用途
cd /tmp 移动到其他文件夹(本例中,打开 /tmp 文件夹)
ls 列出当前位置的文件
cd 回到主目录(不带参数的 cd 总是能将你带回到主目录)
cat .bashrc 显示文件的内容(本例中显示 .bashrc 文件的内容)
history 显示最近执行的命令
echo hello 跟自己说 “hello”
cal 显示当前月份的日历

要了解为什么高级 Linux 用户如此喜欢命令行,你将需要尝试其他一些功能,例如重定向和管道。“重定向”是当你获取命令的输出并将其放到文件中而不是在屏幕上显示时。“管道”是指你将一个命令的输出发送给另一条将以某种方式对其进行操作的命令。这是可以尝试的命令:

命令 用途
echo "echo hello" > tryme 创建一个新的文件并将 “echo hello” 写入该文件
chmod 700 tryme 使新建的文件可执行
tryme 运行新文件(它应当运行文件中包含的命令并且显示 “hello” )
ps aux 显示所有运行中的程序
ps aux | grep $USER 显示所有运行中的程序,但是限制输出的内容包含你的用户名
echo $USER 使用环境变量显示你的用户名
whoami 使用命令显示你的用户名
who | wc -l 计数所有当前登录的用户数目

总结

一旦你习惯了基本命令,就可以探索其他命令并尝试编写脚本。 你可能会发现 Linux 比你想象的要强大并且好用得多.

via: https://www.networkworld.com/article/3518440/intro-to-the-linux-command-line.html

作者:Sandra Henry-Stocker 选题:lujun9972 译者:qianmingtian 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出


本文转载来自 Linux 中国: https://github.com/Linux-CN/archive

对这篇文章感觉如何?

太棒了
0
不错
0
爱死了
0
不太好
0
感觉很糟
0
雨落清风。心向阳

    You may also like

    5 Comments

    1. 350fairfax nordvpn coupon
      You can definitely see your skills within the article you write.
      The arena hopes for more passionate writers like
      you who are not afraid to say how they believe.
      At all times go after your heart.

    2. Hi, I think your website might be having browser compatibility issues.
      When I look at your website in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping.
      I just wanted to give you a quick heads up!
      Other then that, excellent blog!

      Look at my page: Nordvpn Coupons Inspiresensation

    3. It’s awesome to pay a visit this web site and reading the views of
      all friends regarding this article, while I am also zealous of
      getting know-how.

      Here is my web blog; nordvpn coupons inspiresensation (t.co)

    4. Its such as you read my mind! You seem to grasp a lot approximately this, like you wrote the guide in it or
      something. I feel that you could do with a few p.c.
      to drive the message house a little bit, but instead
      of that, that is great blog. A great read.
      I’ll certainly be back.

      my webpage: nordvpn coupons inspiresensation

    5. Superb blog! Do you have any tips and hints for aspiring writers?
      I’m hoping to start my own blog soon but I’m a little lost on everything.

      Would you propose starting with a free platform like WordPress or go
      for a paid option? There are so many options out there that I’m totally overwhelmed
      .. Any ideas? Thanks!

      Here is my web-site: nordvpn coupons inspiresensation (https://t.co/eVysfVwFqe)

    Leave a reply

    您的邮箱地址不会被公开。 必填项已用 * 标注

    这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

    More in:Linux中国