Shell

Posted by Chauncey on June 10, 2020

Terminal & Shell

Terminal is just the interface of the shell, and to other command line programs that will be running inside it. Kind of like how the web browser is an interface to websites and services.

Echo

chaunceydong@Chaunceys-MacBook-Pro ~ % echo Hello, Shell!
Hello, Shell!

# !! means repeat the previous command
chaunceydong@Chaunceys-MacBook-Pro ~ % echo Hello, Shell!!
echo Hello, Shellecho Hello, Shell!
Hello, Shellecho Hello, Shell!

chaunceydong@Chaunceys-MacBook-Pro ~ % echo Hello, Shellecho Hello, Shell!
Hello, Shellecho Hello, Shell!

chaunceydong@Chaunceys-MacBook-Pro ~ % echo 'Hello, Shell!!'
Hello, Shell!!

Directory & Files

directory ~= folder

  • ls: List the files in the directory.
  • cd: Change Directory
  • pwd: Print Working Directory
  • mkdir: Make (Creates) directories.
  • mv: Move files from a directory to another.
  • cat: View file content.
  • less: View file content screen by screen.

space: next page, B: back, /: Search, q: quit

  • rm: Delete files. (SAFRE rm -i)
  • rmdir: Delete directories.
  • grep: “global regular expression print,” processes text line by line and prints any lines which match a specified pattern

-c: count

  • wc: “short for word count” reads either standard input or a list of files and generates one or more of the following statistics: newline count, word count, and byte count
chaunceydong@Chaunceys-MacBook-Pro ~ % ls
Applications			Public
CLionProjects			PycharmProjects
Desktop				Virtual Machines.localized
Documents			eclipse
Downloads			eclipse-workspace
Dropbox				nltk_data
Enfi_Downloads			opt
Library				rsa_private_key.pem
Movies				rsa_public_key.pem
Music				seaborn-data
OneDrive			tk.csv
Pictures

chaunceydong@Chaunceys-MacBook-Pro ~ % ls Desktop
$RECYCLE.BIN
2020-05-13- 2 copy.md
2020-05-13-OOP & C++.md
2020-05-13.md
3000
GRE填空机经1250题解析.pdf
Thumbs.db
WechatIMG38.jpeg
desktop.ini
大连理工_董传林_Black-Schles&ARIMA.docx


# -l = long list: 
# Info shwon: The name of each listed file or directory; The date and time that a file was last modified; The size of a file, in bytes.
chaunceydong@Chaunceys-MacBook-Pro ~ % ls -l Desktop
total 15024
drwxr-xr-x@ 3 chaunceydong  staff       96 Dec 27 23:05 $RECYCLE.BIN
-rw-r--r--@ 1 chaunceydong  staff      456 May 13 13:09 2020-05-13- 2 copy.md
-rw-r--r--@ 1 chaunceydong  staff     2507 May 23 22:05 2020-05-13-OOP & C++.md
-rw-r--r--@ 1 chaunceydong  staff      456 May 14 15:46 2020-05-13.md
-rw-r--r--@ 1 chaunceydong  staff     1000 Mar  1 14:56 3000
-rw-r--r--@ 1 chaunceydong  staff     1012 Apr  7 18:26 GRE填空机经1250题解析.pdf
-rwxr-xr-x@ 1 chaunceydong  staff   433152 May 22 01:40 Thumbs.db
-rw-------@ 1 chaunceydong  staff    96359 Apr 28 15:37 WechatIMG38.jpeg
-rwxr-xr-x@ 1 chaunceydong  staff      282 Jan 13 14:14 desktop.ini
-rwxrwxrwx@ 1 chaunceydong  staff  7107022 May 15 00:55 大连理工_董传林_Black-Schles&ARIMA.docx

# find all .md file
chaunceydong@Chaunceys-MacBook-Pro ~ % ls -l Desktop/*.md  
-rw-r--r--@ 1 chaunceydong  staff   456 May 13 13:09 Desktop/2020-05-13- 2 copy.md
-rw-r--r--@ 1 chaunceydong  staff  2507 May 23 22:05 Desktop/2020-05-13-OOP & C++.md
-rw-r--r--@ 1 chaunceydong  staff   456 May 14 15:46 Desktop/2020-05-13.md


chaunceydong@Chaunceys-MacBook-Pro ~ % cd Movies; ls
Captures	Videos		desktop.ini

chaunceydong@Chaunceys-MacBook-Pro Movies % pwd
/Users/chaunceydong/Movies

# .. = Parent Directory ; . = Current Directory
chaunceydong@Chaunceys-MacBook-Pro Movies % cd ..; ls
Applications			Public
CLionProjects			PycharmProjects
Desktop				Virtual Machines.localized
Documents			eclipse
Downloads			eclipse-workspace
Dropbox				nltk_data
Enfi_Downloads			opt
Library				rsa_private_key.pem
Movies				rsa_public_key.pem
Music				seaborn-data
OneDrive			tk.csv
Pictures

# ~ = Home Directory
chaunceydong@Chaunceys-MacBook-Pro ~ % cd ~; ls
Applications			Public
CLionProjects			PycharmProjects
Desktop				Virtual Machines.localized
Documents			eclipse
Downloads			eclipse-workspace
Dropbox				nltk_data
Enfi_Downloads			opt
Library				rsa_private_key.pem
Movies				rsa_public_key.pem
Music				seaborn-data
OneDrive			tk.csv
Pictures


# create a folder named writing
chaunceydong@Chaunceys-MacBook-Pro ~ % mkdir Desktop/writing
# move all .md files into writing folder
chaunceydong@Chaunceys-MacBook-Pro ~ % mv Desktop/*.md Desktop/writing 



# grep dictionary.txt and pipe it to less
grep shell dictionary.txt | less


URL

  • CURL: See URL, is used in command lines or scripts to transfer data.