they allow you to run programs, give them input, and inspect their output in a semi-structured way
The most popular one: Bourne Again Shell, or Bash
Basic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
wwwqeo@LAPTOP-QQDH3S15:~$ #this is called a prompt #wwwqeo@LAPTOP-QQDH3S15 is the username
wwwqeo@LAPTOP-QQDH3S15:~$ date Fri Jan 5 13:49:30 CST 2024
wwwqeo@LAPTOP-QQDH3S15:~$ echo$SHELL /bin/bash wwwqeo@LAPTOP-QQDH3S15:~$ echo$PATH /home/wwwqeo/.local/bin:/usr/local/sbin # echo means "print" # the : seperate the listed directories in $PATH # $PATH is the directory that bash search for the programme to run wwwqeo@LAPTOP-QQDH3S15:~$ whichecho /usr/bin/echo # returns the path of the program "echo"
wwwqeo@LAPTOP-QQDH3S15:~$ pwd#pwd: present work directory /home/wwwqeo wwwqeo@LAPTOP-QQDH3S15:~$ cd /home #cd: change directory wwwqeo@LAPTOP-QQDH3S15:/home$ cd .. # .. is the parents dir. of pwd wwwqeo@LAPTOP-QQDH3S15:/$ pwd / # / means the root directory wwwqeo@LAPTOP-QQDH3S15:/$ cd . # . refers to pwd wwwqeo@LAPTOP-QQDH3S15:/$ pwd /
wwwqeo@LAPTOP-QQDH3S15:/$ ls bin dev home lib lib64 lost+found mnt proc run snap sys usr boot etc init lib32 libx32 media opt root sbin srv tmp var wwwqeo@LAPTOP-QQDH3S15:/$ ls --help#help of ls Usage: ls [OPTION]... [FILE]...
wwwqeo@LAPTOP-QQDH3S15:/$ ls -l # -l use long listing format total 2120 lrwxrwxrwx 1 root root 7 May 2 2023 bin -> usr/bin drwxr-xr-x 2 root root 4096 Apr 18 2022 boot drwxr-xr-x 16 root root 3540 Jan 5 13:48 dev ...... #权限 链接 所属人 所属群组 大小 修改日期 文件名 #权限 permission eg. lrwxrwxrwx , drwxr-xr-x #10个字符,第一位:文件类型,-文件,l链接文件,d目录,b和c都是指设备文件 #后面9位每三个rwx一组,依次是所属人、所属群组、其他所有者权限 #r~read,w~write,x~execute(可执行),-~no permission #链接 links:表示有多少文件名链接到这个节点(i-node)上
wwwqeo@LAPTOP-QQDH3S15:/$ man ls#open the manual of ls
wwwqeo@LAPTOP-QQDH3S15:/$ cd ~ # ~ means /home/usr (usr is the username) wwwqeo@LAPTOP-QQDH3S15:~$ pwd /home/wwwqeo wwwqeo@LAPTOP-QQDH3S15:~$ mkdir the_missing_semester #mkdir~make directory; rm~remove wwwqeo@LAPTOP-QQDH3S15:~/the_missing_semester$ touch semester #touch: create blanck file
Connecting Programs
In the shell, programs have 2 primary “streams” (input & output).
#The | operator lets you “chain” programs such that the output of one is the input of another wwwqeo@LAPTOP-QQDH3S15:~$ ls -l / | tail -n1 drwxr-xr-x 13 root root 4096 May 2 2023 var #tail 是一个命令,用于显示文件的末尾行。 #-n1 是 tail 命令的选项,表示只显示最后一行。
wwwqeo@LAPTOP-QQDH3S15:~$ ls / |tee output.txt #将根目录下的文件名写入home下的output.txt中 #tee 用于从输入读取数据,并将其同时输出到标准输出和一个或多个文件中。 wwwqeo@LAPTOP-QQDH3S15:~$ ls -l / >> output.txt #将根目录下的ls -l append到home下的output.txt中