Shell

Collect some commands in bash I didn’t know before.

Navigating in shell

  1. ls -l dir

drwxr-xr-x ...:

  • d: tell that missing is a dir

  • rwx: 依次表示三方对 missing 文件的权利 - the owner of the filethe owning group(users)others

    x 表示 execute

Gets more info about a program’s args, inputs, outputs and how it works: use man

1
man ls

Connecting programs

  1. Simplest: redirection is < file and > file

  2. use >> to append to a file, this kind shines in the use of pipes. The | operator lets you ‘chain’ programs such that the one’s output is the latter one’s input.

1
2
3
4
missing:~$ ls -l / | tail -n1
drwxr-xr-x 1 root root 4096 Jun 20 2019 var
missing:~$ curl --head --silent google.com | grep --ignore-case content-length | cut --delimiter=' ' -f2
219

Versatile and powerful tools

How does shell know that the file is supposed to be interpreted using sh : shebang(Unix)

1
2
#!/bin/sh
curl --head --silent https://missing.csail.mit.edu
  • # starts a comment in Bash
  • ! even within double-quoted (") strings has special meaning (?)

If surreptitious, chech shebang link.

Exercise

1
tail -c 22 // shows the last 22 characters