Our workstations and servers run Linux. This lesson covers the command-line tools you need every day, from file and process handling to SSH and shell scripts.
Important
Work on this lesson in
advisormode.
Learning goals
- You can look around a Linux system from the shell: files and directories, running processes, disk usage, open network ports, installed packages.
- You can explain file ownership and the nine permission flags, and change them.
- You can make a script executable and run it directly, in bash and in Ruby, using a shebang line.
- You can connect to a server with SSH and copy files to and from it, and you can explain why you log in as the deploy user and what that user may and may not touch.
- You can edit a file in a terminal editor (e.g. vim or nano) and have made it your
$EDITOR. - You use the shell efficiently: history search, tab completion, pipes, and job control to suspend and resume programs.
- You can configure your shell and tools through their dotfiles, e.g.
~/.bashrc,~/.ssh/config,~/.gitconfig. - You can find out how any command works, e.g. with
man,tldror--help.
Resources
Read what's new to you, skim what's familiar, skip what you already master. Stop when you can meet the learning goals.
Your agent can also generate an overview, a tutorial or an explanation for anything here, tailored to what you already know. Just ask.
Pick one introduction
- 📘 Learn Enough Command Line to be Dangerous Show archive.org snapshot — free to read online; also in our library Show archive.org snapshot
- ▶️ The Missing Semester: Course overview + the shell Show archive.org snapshot and shell tools and scripting Show archive.org snapshot — MIT lectures with notes and exercises
For specific goals
- 📄 CLI tricks every developer should know Show archive.org snapshot — history, completion, pipes, aliases
- 📄
Linux file permissions explained
Show archive.org snapshot
— owner, group, the nine flags,
chmod - 📄
Job control
Show archive.org snapshot
—
Ctrl+Z,bg,fg,jobs - 📄 Vim cheat sheet Show archive.org snapshot — enough vim to edit a file on a server; or use nano
- 🎮
tldr— install withsudo apt install tldr;tldr sshshows usage examples for any command (runtldr -ufirst if pages are missing) - 📄 Deployments in our opsComplete deck — why you log in as the deploy user and what that user may touch
Exercises
Get around the system
Solve each task in your terminal. The commands in parentheses are hints — learn them with man, tldr or --help (get more colorful man pages).
- Find out how full your disk is, and which subdirectory of your home directory takes the most space. (
df -h,du -h) - Start
bin/devin your MovieDB, then from a second terminal: which processes belong to it, and on which TCP ports do they listen? Kill one of them by name. (ps,top,ss --listening --tcp,kill,pkill -f) - Check whether a package is installed, search the package index for one you'd like, install it, and bring your system up to date. (
dpkg -l,apt-cache search,sudo apt install,apt update,apt dist-upgrade) - Connect to your staging server, copy a file to it and back. (
ssh,scp) - Fetch a page from your staging app and inspect the response headers; look up the server's IP. (
curl,dig) - In your MovieDB logs, find every request to a movie page — including in rotated logs. (
grepwith|,less,zgrep) - Create a symbolic link and explain how it differs from a copy; update a file's timestamp without editing it. (
ln -s,touch)
Configuration files
Make one improvement to each of the following files and demonstrate it:
-
~/.bashrc— e.g. an alias or a prompt tweak -
~/.ssh/config— aHostalias, sossh <shortname>reaches your staging server -
~/.gitconfig— e.g. a git alias or a useful setting
Note that changes to your ~/.bashrc don't affect already opened shells.
Terminal editor
To edit files from within a terminal, you'll need a CLI editor.
- Choose an editor (
vim
Show archive.org snapshot
or
nano
Show archive.org snapshot
)
- If you chose vim, learn
how to exit
Show archive.org snapshot
an open editor:
-
:qto exit -
:wqto save (write) and exit -
:q!to exit without writing
-
- If you chose vim, learn
how to exit
Show archive.org snapshot
an open editor:
- Persist your choice in the
$EDITORvariable. It defines the default for commands likegit commit:
# Example with vim
# open the configuration file
vim ~/.bashrc
# navigate to the end of the file,
# press "i" to switch to insert mode
# then type out the line you want to add
export EDITOR=vim
# persist your changes
:wq
Note
While you could locally set
$EDITORto a graphical editor likegedit, this is not possible for remote shells to our servers. Getting accustomed to a CLI editor will pay off in the long term.
Terminal shortcuts
Understand what the following shortcuts do in a terminal:
- Up-arrow
TabCTRL+R-
CTRL+Z/jobs/fg/bgShow archive.org snapshot- This allows you to faux-multitask within a single shell. E.g. you can temporarily suspend a running vim editor, take a look around the system, then return to your vim editor.
File ownership
Understand access rights and ownership of files:
- What does "ownership" mean for files?
- Each file has 9 flags, 3 read, 3 write, and 3 executable flags. What do they mean?
- Write a simple bash script that prints a message. How can you execute it?
- Write the same script in Ruby. What do you have to do to just call it from the command line without using the
rubycommand directly? Learn about the "shebang".