首页 > 系统相关 >How to use the shell, terminal and the advanced tools

How to use the shell, terminal and the advanced tools

时间:2024-09-19 23:12:25浏览次数:1  
标签:paths use shell terminal semester program file directory

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


标签:paths,use,shell,terminal,semester,program,file,directory
From: https://www.cnblogs.com/riskmoumou/p/18421574/how-to-use-the-shell-terminal-and-the-advanc

相关文章

  • WPF System.Windows.Media.Color A value must be set, display ball and number in c
    privateColorGetRndColor(){Colorcr=newColor();cr.A=255;cr.R=(byte)(rnd.Next(0,255));cr.G=(byte)(rnd.Next(0,255));cr.B=(byte)(rnd.Next(0,255));returncr;}         //usercontrol.......
  • shell编程初识
    1.Shell概述,编程语言.1.1编程概述应用广泛:Shell占据的Linux半壁江山.企业要求:面试要求运维人员必会.目标:1.能够熟练书写超过多行的脚本:检查类:系统巡检,系统加固,优化:(检查,配置优化)系统优化(初始化)(第2阶段开头).......
  • 易优eyoucms网站php5.4版本,报错:Can't use method return value in write context
    当你在使用PHP5.4版本时遇到“Can'tusemethodreturnvalueinwritecontext”的错误,这通常是因为你在代码中错误地使用了方法返回值。这种错误通常发生在试图将方法返回值直接赋值给变量或用于其他上下文时。解决方案以下是一些常见的原因和解决方法:1.检查代码中的赋......
  • 使用 PowerShell 管理 DNS 服务器,你可以执行多种操作,如添加、删除和修改 DNS 记录,以及
    使用PowerShell管理DNS服务器,你可以执行多种操作,如添加、删除和修改DNS记录,以及管理DNS区域。以下是一些常用的cmdlet示例:查看所有DNS区域powershellCopyCodeGet-DnsServerZone添加新的DNS区域powershellCopyCodeAdd-DnsServerPrimaryZone-Name"yourdomai......
  • 【Java基础】ThreadLocal<LoginUser>:存储登录用户信息
    ......
  • 易优eyoucms网站请检查数据库连接信息,Access denied for user 'root'@'localhost' (us
    当你遇到“Accessdeniedforuser'root'@'localhost'(usingpassword:YES)”这样的错误时,这意味着数据库系统拒绝了你的连接请求,通常是由于提供的凭据不正确。你可以按照以下步骤来检查和修改数据库连接信息:检查数据库连接信息:确认数据库用户名(通常是root)、密码、以及数......
  • 大数据-140 - ClickHouse 集群 表引擎详解5 - MergeTree CollapsingMergeTree 与其他
    点一下关注吧!!!非常感谢!!持续更新!!!目前已经更新到了:Hadoop(已更完)HDFS(已更完)MapReduce(已更完)Hive(已更完)Flume(已更完)Sqoop(已更完)Zookeeper(已更完)HBase(已更完)Redis(已更完)Kafka(已更完)Spark(已更完)Flink(已更完)ClickHouse(正在更新···)章节内容上节我们完成了如下的内容:MergeTre......
  • 大数据-139 - ClickHouse 集群 表引擎详解4 - MergeTree 实测案例 ReplacingMergeTree
    点一下关注吧!!!非常感谢!!持续更新!!!目前已经更新到了:Hadoop(已更完)HDFS(已更完)MapReduce(已更完)Hive(已更完)Flume(已更完)Sqoop(已更完)Zookeeper(已更完)HBase(已更完)Redis(已更完)Kafka(已更完)Spark(已更完)Flink(已更完)ClickHouse(正在更新···)章节内容上节我们完成了如下的内容:MergeTre......
  • 两个用于改善图形渲染质量的属性UseLayoutRounding和SnapsToDevicePixels
    UseLayoutRounding:获取或设置一个值,该值指示是否应向此元素的大小和位置布局应用布局舍入。UseLayoutRounding当元素的属性为true时,在传递Arrange过程中Measure计算的所有非整型像素值都会舍入到整个像素值。在像素边界上绘制对象时,当边缘落在设备像素中间时,消除由抗锯齿生成的......
  • react hooks--useCallback
    概述useCallback缓存的是一个函数,主要用于性能优化!!!基本用法如何进行性能的优化呢?useCallback会返回一个函数的memoized(记忆的)值;在依赖不变的情况下,多次定义的时候,返回的值是相同的;语法:constmemoizedCallback=useCallback(()=>{doSomething(a,b);......