Shell基礎筆記 - The Missing Semester of Your CS Education
可惜還是學生的時候不知道有這門好課,雖然已經有些經驗了,但還是想看看這門課能帶給我什麼新東西
快速複習
Basics of the Shell
- Shell = text-based interface for executing commands.
- Bash (Bourne Again Shell) is widely used.
Basic Commands
date
→ Show current date/timeecho hello
→ Print text to terminalecho $PATH
→ Show directories searched for commandswhich command
→ Locate the binary file of a command
Navigating the Filesystem
pwd
→ Show current directorycd /path/to/dir
→ Change directoryls
→ List filesls -l
→ Show detailed file infocd ..
→ Move up one directorymkdir newdir
→ Create a directory
File Operations
mv old new
→ Rename/move a filecp source dest
→ Copy a filerm file
→ Delete a fileman command
→ Show manual for a command
Redirection & Pipes
command > file
→ Redirect output to a filecommand >> file
→ Append output to a filecommand < file
→ Use file as inputcommand1 | command2
→ Pipe output of one command to another
Examples
echo hello > hello.txt
→ Write “hello” to a filecat hello.txt
→ Display file contentsls -l / | tail -n1
→ Show the last line ofls -l /
outputcurl --head --silent google.com | grep -i content-length | cut -d ' ' -f2
→ Get content length of a webpage
Running Commands as Root
sudo command
→ Run command as superuserecho 3 | sudo tee /sys/class/backlight/thinkpad_screen/brightness
→ Change screen brightness- tee displays program output and copying to a file
Exercises
第五題
- 不能直接寫入,因為
#
是comment - 不能用雙引號因為
!
是event - 要用單引號或是
\
把驚嘆號轉換成字 echo '#!/bin/sh' > semester
echo "#\!/bin/sh" > semester
第九題
- 因為
#!
這行
第十題
./semester | grep last-modified > last-modified.txt
Shell基礎筆記 - The Missing Semester of Your CS Education
https://f88083.github.io/2025/03/26/Shell/