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


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


How to use the shell, terminal and the advanced tools的更多相关文章

  1. 利用Go2Shell 实现 Mac Finder 直接shell端打开当前文件夹

    Finder 窗口 ,点击下图所示的按钮(红色框内),即可打开Shell Terminal. 打开后,如图 用法 安装go2shell后,打开finder的application文件夹,找到go2sh ...

  2. doris: shell invoke .sql script for doris and passing values for parameters in sql script.

    1. background in most cases, we want to execute sql script  in doris  routinely. using azkaban, to l ...

  3. Android Weekly Notes Issue #219

    Android Weekly Issue #219 August 21st, 2016 Android Weekly Issue #219 ARTICLES & TUTORIALS Andro ...

  4. RASPBERRY PI 外设学习资源

    参考: http://www.siongboon.com/projects/2013-07-08_raspberry_pi/index.html Raspberry Pi         Get st ...

  5. 看懂理解 keyboard中 , navigation的设置: 切换工作区和移动窗口到不同的工作区.

    navigation中, 主要有两个方面的内容: 移动窗口到工作区 的shortcuts 切换工作区的shortcuts 首先清楚: 工作区workspace, fedora 23中 好像只有上下方向 ...

  6. Find mac address

    Windows Method 1: Using the Command Prompt 1 Click on the Start button.   2 Type cmd in the search b ...

  7. 9个使用前必须再三小心的Linux命令

      Linux shell/terminal 命令非常强大,即使一个简单的命令就可能导致文件夹.文件或者路径文件夹等被删除.在一些情况下,Linux 甚至不会询问你而直接执行命令,导致你丢失各种数据信 ...

  8. Jmeter安装设置

    Linux: 其实下载之后就可以用,不过为了能在命令行直接敲入”jmeter"就可以调出Jmeter程序,还需要进行如下设置. 1. Download apache-jmeter-2.12. ...

  9. Nagios监控生产环境redis群集服务战

    前言:     曾经做了cacti上展示redis性能报表图.能够看到redis的性能变化趋势图,可是还缺了实时报警通知的功能,如今补上这一环节. 在redis服务瓶颈或者异常时候即使报警通知,方便d ...

  10. tmux tutorial

    This is a great tutorial about tmux quick start: http://www.youtube.com/watch?v=wKEGA8oEWXw&nore ...

随机推荐

  1. IPV6禁用导致 RabbitMQ 无法启动的问题

    问题现象 在开发的过程中遇到了 RabbitMQ 怎么也启动不起来的现象.查看 RabbitMQ 自身的启动日志,并没有发现有什么有用的报错信息,只是从某天开始就一直在打印重启的日志,尝试多次重启也不 ...

  2. Qt编写地图综合应用60-覆盖物坐标和搜索

    一.前言 地图应用中有时候需要开启悬浮工具栏,用户可以直接在地图上绘制矩形.多边形.圆形.线条等,于是需要提供一个函数接口,能够获取到用户绘制的这些图形形状对应的信息.比如坐标点.圆形的中心点和半径. ...

  3. 即时通讯技术文集(第23期):IM安全相关文章(Part12) [共15篇]

    为了更好地分类阅读 52im.net 总计1000多篇精编文章,我将在每周三推送新的一期技术文集,本次是第23 期. [- 1 -] 理论联系实际:一套典型的IM通信协议设计详解(含安全层设计) [链 ...

  4. SQL Server 递归+向上统计

    前几天有个需求需要基于分类数据向上统计总数,一开始第一个想法是通过程序来计算,后再思考能不能通过SQL脚本直接来计算 基础数据 Id ParentId Category Num 1 0 分类1 0 2 ...

  5. 获取不同型号手机小程序导航栏的高度(uniapp)

    uni.getSystemInfo({ success: function(e) { Vue.prototype.StatusBar = e.statusBarHeight; let custom = ...

  6. R语言学习数据挖掘

    1.用R计算数据基本统计量(均值) 学习机器学习和数据挖掘中的各种算法和模型,需要掌握统计学的基本概念.统计学是通过搜索.整理.分析数据等手段,以达到推断所测对象的本质,并预测对象未来走势的一门综合性 ...

  7. Hyper-V创建虚拟机配置IP等网络配置原理(Linux、Windows为例)

    大家知道Windows系统里面内置了Hyper-V管理器,用来创建和管理本地虚拟机环境.今天我创建了两台虚拟机,一台是CentOS7.9(Linux),另一台是Windows 11,然后发现,Linu ...

  8. oracle数据导入导出,备份还原命令expdp&impdp(只导出元数据,不导出表数据,最全,最完善的步骤)

    感谢金龙鱼先生分享,原文来自https://blog.csdn.net/kou869929526/article/details/125791113 一,编码要求以及数据库版本要求 检查数据库版本(用 ...

  9. java中数组和字符串

    数组 数组的声明方式: 类型[] 变量; 数组的创建方式: new 类型[数组长度] 数组的简单声明并且赋值 // 声明一个数组,它的长度是3 String[] arrs= new String[3] ...

  10. DeepSeek+AnythingLLM打造自己大模型知识库

    DeepSeek+AnythingLLM打造自己大模型知识库 目       录 1.      安装Ollama 2.      下载DeepSeek模型 3.      安装AnythingLLM ...