Linux 101 Command Line Cheat Sheet
Abstract
Fundamental Linux/Unix commands for the Linux/Unix command line learner. If you are experienced with Linux/Unix: you have probably mastered these commands. If not: you are in the right place.
Note: Some of the examples below presume files and paths that might not match your particular system and tool installation.
Where to Acquire
These tools are installed natively in most Unix/Linux distributions, as well as OS X.
Examples/Use Case
bash basics
Tab-completion:
Folks who are new to the Unix/Linux command line often attempt to type everything by hand. This may work well if you type quickly and accurately. Most of us are much better off using tab completion.
Note that Windows PowerShell also supports tab completion, but it handles ambiguity differently. See the PowerShell cheat sheet for more information.
Type the following, and then press the <TAB>
key:
$ cat /etc/pas
<TAB>
.
Note that it autocompletes to /etc/passwd
.
Now try tabbing with ambiguity:
$ cd ~/Do
<TAB><TAB>
.
Note that it offers two choices: Documents/ Downloads/
.
Now add a "w" and press <TAB>
:
$ cd ~/Dow
<TAB>
. It autocompletes to ~/Downloads/
.
cat
Display a file:
$ cat example.txt
$ cat FileA.txt FileB.txt > FileC.txt
cd
Change Directory (cd) to the /tmp directory:
$ cd /tmp
$ cd
$ cd ~
$ cd /home/student
$ cd ..
echo
Print (echo) the string "Cylon":
$ echo Cylon
$ echo Cylon > example.txt
$ echo Cylon >> example.txt
ls
List the files in the current directory (equivalent to the cmd.exe "dir" command):
$ ls
$ ls -la
$ ls -lat
$ ls -lart
networking
Show network interface configuration:
$ ifconfig
$ ip a
$ sudo /etc/init.d/networking restart
passwd
Change your password:
$ passwd
ping
ping a host forever (until CTRL-C is pressed), see if it is up (and unfiltered):
$ ping 10.5.11.25
$ ping -c3 10.5.11.25
pwd
Print Working Directory (pwd), show the current directory:
$ pwd
sudo
Run a command as root:
$ sudo command
$ sudo bash
A printable PDF version of this cheatsheet is available here: LinuxCLI101