How to use the shell, terminal and the advanced tools

How to use the shell, terminal and the advanced tools

Introduction

Why use English instead of Chinese when writing a blog? As time goes by, the more I have learned, the more I have to handle with the English documents or papers. So, I realized it was time for me to adapt to the full English environment to improve my ability.

Though it's not easy for me to write a blog in English, as my mother tongue isn't English, I still write this blog as the first step to determine that I will make full use of my energy to do so.

Just start it from "The Missing Semester of Your CS Education".


Catalog

目录
  • How to use the shell, terminal and the advanced tools
    • Introduction
    • Catalog
    • Permissions
      • User
      • Files and Directories
    • Command
    • stream
    • Path
    • Run program
    • Exercises
    • References


Permissions

User

  • root
    can do anything
  • #​ : a root(shell)
  • $​ : not a root(shell)
  • sudo​ : run command as a root
  • sudo su​ : switch as a root user


Files and Directories

  • ls -l​ : gives the additional information

    • ----------​ : 1+3+3+3

    • d---------​ : directory

      • ---------​ : permissions

        • 1-3 ---​ : set for the owner of the file

        • 4-6 ---​ : set for the group of the file

        • 7-9 ---​ : set for the others of the file

        • ---​ : read( r​ ), write( w​ ), execute( x​ )

          • File: allowed to read, write, and execute this file

          • directory :

            • read: allowed to see which files are inside this directory
            • write: allowed to rename, create, or remove files within that directory
            • execute: allowed to enter this directory
          • -​ : do not have that permission

        • How about 7​ ?

          • ---​ can be present by using the three bits binary digit

          • 7​ = 111​ : rwx

            • 1​ : set the permission
            • 0​ : not set the permission


Command

  • date​ : show the time

  • echo​ : display the given arguments that are separated by whitespace

    • If the arguments consist of multiple words

      Use the ""​ or '​ to quote it.

    • You can use \​ to escape single characters

  • which​ : allows us to know the path of the program that we want to run

  • tee​ : write the contents of input to a file and to the standard out

  • mv​ : change the location or name of the file

  • rm​ : remove a file

    • rm -r​ : remove a directory and all the files within it
  • rmdir​ : remove the empty directory

  • mkdir​ : create a new directory

  • man​ : for manual pages of the program

  • cat​ : cat <​ files >​ standard output

  • cd​ : change the current working directory

    • ~​ : home directory
    • -​ : previous directory
  • tail​ : Print the last 10 lines of each FILE to standard output

  • pwd​ : Print the name of the current working directory.

  • find

  • xdg-open

  • We can give a path to ls​ by offering arguments(flags | options)

    • flags and options usually start with a -

    • --help​ can print out a bunch of information about that command

      • Usage

        • ...​ : means zero or one or more options
        • []​ : means optional
      • Funtion description

        • flag: -​ + single letter

          • No value content also is a flag
        • option: anything that does take a value

In reality, we don't need to memorize them all, because we can query the usage of the command by adding the --help​ or use the man​ for more information about it.


stream

  • Every program by default has two primary streams

    • Input stream : keyboard(default)

    • output stream : terminal(default)

    • rewire these streams

      • <​ : rewire the input for this program to be the contents of this file
      • >​ : rewire the output for this program to be the contents of this file
    • >>​ : append the content but not overwrite the original one.

  • |​ : left program output right program input


Path

When we simply type the echo hello​ or date​, it will work and print the result on the terminal, but how can our shell locate them? The answer is: by paths.

Our shell can locate the program through the environment variable. Paths are a way to name the location of a file on your computer.

  • Environment variable: a variable

    Things that are set whenever you start your shell

  • Example: echo $PATH

    It shows you all of the paths on my machine that the shell will search for programs

  • What is paths?

    • Linux/macOS: /​ separate the paths
    • Windows: \​ separate the paths
    • Absolute paths: fully determine the location of a file
    • Relative paths: relative to where you currently are
    • Command pwd​ can show the present working directory
  • Working directory
    All the relative paths are relative to the current working directory

    • Configure the terminal can show the full path
    • .​ : the current directory
    • ..​ : the parent directory


Run program

  • Methods for running the program anyway

    • method1: give the name of the program and let the shell figure out where it is as if you have added the absolute paths to the $PATH
    • method2: give the absolute paths of the program
  • Program always works on the current working directory(without any other arguments)

  • Command ls​ can list all the files in the current directory

  • In fact, you can regard the shell and the Bash(Bourne Again Shell) as a kind of programing language

    • You can run a program with arguments
    • You can do things like while loops, for loops, conditionals, functions and variables
  • ctrl+L​ : clear the terminal and go back to the top


Exercises

  1. Already on Linux

  2. mkdir missing && cd missing

  3. man touch

  4. touch semester

  5. echo '#!/bin/sh' > semester && echo 'curl --head --silent https://missing.csail.mit.edu' >> semester

  6. ./semester

    ls -l

    -rw-rw-r--​ : no permission to execute the file

  7. sh semester

    #​(root) run the /bin/sh

    $​ run the ./semester

  8. man chmod

  9. chmod u+x semester

    ./semester

  10. ./semester | grep 'last-modified' > ~/last-modified.txt

  11. cat /sys/class/power_supply/BAT0/capacity_level


References

  • https://missing.csail.mit.edu/2020/course-shell/


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/800150.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C语言类型与强制类型转换

目录类型关键字sizeof如何理解强制类型转化不同类型的0null字符设备(补充) char有有符号和无符号两种类型,字符是无符号类型.(补充) getchar的返回值为什么是int键盘输入的内容,以及往显示器中打印的内容,都是字符 --> 键盘/显示器称为字符设备 类型C语言为何有类型? 让我们…

如何在 ASP.NET Core Web API 方法执行前后 “偷偷“ 作一些 “坏“ 事?初识 ActionFilterAttribute

ActionFilterAttribute 是一种作用于控制器 Action 方法的特性(Attribute),通过它,你可以在操作执行前后、异常处理时等不同的阶段插入自定义逻辑。 比如在执行操作方法之前修改请求参数、记录日志、进行权限验证等操作,在执行操作方法之后发送邮件、同步数据等等。 本文主…

访问Github卡顿甚至进不去的解决办法(适用于Windows)

本文使用Watt Tookit(原Steam++)解决了Github在国内访问速度卡顿甚至无反应的问题,通过NDM和镜像网站实现Github大文件高速下载。本文首发自个人博客:点我查看 一、前言 Github 是全球知名的开源宝库,但是对国内用户并不友好。当我们在浏览器中输入www.github.com时,如果…

看看mysql干的恶心事

如图: 本文来自博客园,作者:河北大学-徐小波,转载请注明原文链接:https://www.cnblogs.com/xuxiaobo/p/18421514

LoRaWAN网关价格干穿地板了

曾经LoRaWAN网关要上万块钱一台,后来卷到千把块钱,现在可以卷到500以内,还支持4G/ETH/WIFI,应该也是没谁了。 先上图片1.1 产品特点 ◆ 高性能嵌入式硬件平台 ◆ 使用工业级 Cat.1 4G 模块 ◆ 宽压输入 DC 9~28V,工业级稳定性 ◆ 群脉冲:电源2kV,通讯线4kV ◆ 湿度范围…

认知神经科学分析指标——图论指标之全局集群系数

图论指标在认知神经科学或脑科学的研究中,通常作为研究脑网络表现的描述性指标之一,而图论指标从全局性来分可以分为:节点指标和全局指标,而根据描述脑网络整合性表现又可分为:整合指标和分离指标。 该随笔主要涉及图论指标中全局指标及整合指标的全局集群系数,英文全称为…

day4[大模型全链路开源开放体系学习小结]

书生浦语大模型全链路开源开放体系涵盖数据收集、标注、训练、微调、评测、部署等全链路,学习了解其技术发展、性能提升、模型架构、开源生态等。 书生浦语大模型(英文名IN Turn LLM)多次开源,性能不断提升,达到国际先进水平,在推理能力、上下文记忆、自主规划等方面表现…

深入理解ConcurrentHashMap

HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进行put操作,调用了HashMap的putVal(),具体原因:假设两个线程A、B都在进行put操作,并且hash函数计算出的插入下标是相同的;当线程A执行完第六行由于时间片耗尽导致被挂起,而线程B得到时间片后在该下标处插入了元…

成都仪器定制-二进制补码及与原码的互相转换方法

大沙把一些基础的知识说清楚,本文介绍二进制补码及与原码的转换方法。 先说原码,原码‌是一种计算机中对数字的二进制定点表示方法。在原码表示法中,数值前面增加了一位符号位,最高位为符号位,0表示正数,1表示负数。其余位表示数值的大小。二进制补码‌是一种用于表示有符…

函数进阶应用3

认识OFFSET函数函数格式 参数说明 作用OFFSET(参数1,参数2,参数3,参数4,参数5) 参数1:以谁为标准参数2:下一多少行参数3:右移多少列参数4:取几行参数5:取几列 动态获取数据应用:使用offset函数获取表格最后五行数据,并计算平均值 在空白单元格输入“=offset()”,然…

程序员编写技术文章需要的四个辅助神器 ,强烈建议收藏 !

编写技术文章是程序员分享经验和记录学习成果的重要方式。 为了让写作变得更轻松,有许多实用工具可以帮助提升效率,比如 Markdown 编辑器、画图工具等。 接下来,笔者将介绍四款简单实用的工具,帮助程序员更轻松地编写技术文章。1 Typora :Markdown 编辑器 Typora 是一款简…

【专题】2024年9月游戏行业报告合集汇总PDF分享(附原数据表)

原文链接:https://tecdat.cn/?p=37732 在当今数字化高速发展的时代,游戏行业已然成为了文化与科技融合的前沿阵地。中国游戏行业凭借着不断创新的技术、丰富多元的内容以及日益拓展的市场,正以蓬勃之姿在全球舞台上绽放光彩。阅读原文,获取专题报告合集全文,解锁文末153份…