Command Line Intermediate: Text, Processes and Users
Packages and Networking Tools
In this lesson you will
- Install and update software with apt
- Test connections and fetch web content with ping and curl
- Explain environment variables and PATH
Introduction
Software on Linux is not downloaded from random websites. It comes from repositories, managed by a package manager. This lesson also covers the tools you use to check networks and connect to other machines.
Package managers
Different distributions use different tools. On Debian and Ubuntu it is apt:
Terminal
sudo apt update # refresh the list of available packages
sudo apt install htop # install a program
sudo apt upgrade # update installed packages
apt search "text editor" # search
sudo apt remove htop # uninstallFedora uses dnf, Arch uses pacman, and macOS has the popular third-party Homebrew (brew install). Packages come from signed repositories, which is much safer than downloading and running unknown scripts. Keep your system updated for security fixes.
Environment variables and PATH
An environment variable is a named setting available to programs.
Terminal
echo $HOME # your home folder
echo $PATH # folders searched for commands
export GREETING="Hello"
echo $GREETINGPATH is a list of folders, separated by colons. When you type git, the shell looks through each folder in PATH for a program with that name. which git shows the one it finds.
To add a folder, put this in your shell startup file (such as ~/.bashrc):
Terminal
export PATH="$HOME/bin:$PATH"Quick quiz
What is the PATH variable used for?
Checking the network
Terminal
ping -c 4 example.com # is the host reachable? (4 tries)
ip addr # your IP addresses (Linux)
nslookup example.com # DNS lookup
curl -I https://example.com # fetch only the response headers
curl -O https://example.com/file.zip # download a file
curl -s https://api.example.com/data | head # fetch and pipe the resultcurl is the Swiss Army knife for talking to web servers and APIs. -s hides the progress meter. Treat downloaded scripts carefully: never pipe an unknown script straight into a shell.
Connecting to another computer with ssh
SSH (Secure Shell) gives you an encrypted terminal on a remote machine.
Terminal
ssh [email protected]The first time, you are asked to confirm the server's fingerprint, which identifies it. Once connected, commands you type run on the remote machine. Type exit to return. Better security comes from using key pairs instead of passwords, covered in the advanced course.
Copy files with scp:
Terminal
scp report.txt [email protected]:/home/alice/Try it yourself
Check where git is installed with which git. Run ping -c 3 example.com, then curl -I https://example.com and find the status line at the top of the output.
Summary
- A package manager such as
aptinstalls and updates software from trusted repositories. - Environment variables hold settings, and PATH tells the shell where to find commands.
ping,curl,sshandscptest networks, fetch content and connect to other machines.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading