This is the most important skill on the list. Everything else assumes you know where you are. Editing the right config file, pointing a script at the right folder and not overwriting something that matters all come back to this.
Confirm the machine with command hostname
Confirm the user with command whoami
Confirm the directory with command pwd
Do it before you change anything. It is the cheapest habit in this guide.
An absolute path is the full address of a file, the same way a posted letter needs the whole address rather than the name of a room. It starts at the top of the filesystem and names every folder on the way down.
The top of the filesystem is a single forward slash.
Go to the top with command cd /
Go to your own home folder with command cd ~
Name a full path outright with command cd /home/sun
Check where you landed with pwd each time until it stops surprising you.
A relative path gives directions from where you are standing, the way you would tell someone in your house to go up the stairs and turn left rather than reciting your street address.
Go up one level with command cd ..
Go down into a folder by naming it with command cd sun
Chain them together with command cd sun/test
This is why pwd matters. A relative path only means something from a known starting
point.
Try the same cd sun from the top of the filesystem and it fails, because there is no sun
folder there. Nothing is broken. You were just somewhere else.
List the current directory with command ls
Read every option with command man ls
Press q to quit any man page.
The combination worth memorising is long format, sorted by time, reversed.
ls -ltr
That puts the newest file at the bottom, next to your cursor.
It is how you find the file you just made when you have forgotten what you called it.
wc is word count.
Count the words in a file with command wc -w filename
Start typing the filename and press Tab to autocomplete it rather than typing the whole thing.
Count how many entries are in a directory by piping one command into another.
ls | wc -l
The pipe is the vertical bar above the Enter key. It takes the output of the command on the left and feeds it to the command on the right.
ls prints one entry per line, so counting lines counts entries.
Page through output with command ls -ltr | more
Press space for the next page. Press q to quit.
Use less when you want to go back up as well.
ls -ltr | less
Page Up and Page Down both work in less. Press q to quit.
Without one of these, a long listing scrolls past and you only ever see the end of it.
grep searches text for a pattern and prints the lines that match.
Print a whole file with command cat /etc/passwd
That is too much to read, so filter it.
cat /etc/passwd | grep sun
You get back the one line describing that user, including the shell it is set to use.
Press the up arrow to bring back a previous command rather than retyping it.
This is the one you will reuse constantly, for SSH and for anything else you host.
sudo lsof -i -P -n | grep sshd
It needs sudo, so it asks for your password.
The output names the port the service is actually listening on.
Swap sshd for any other daemon to answer the same question about it.
This tells you what is true right now, rather than what a config file says should be true.