Skip to content

Commit

Permalink
more on RTFM
Browse files Browse the repository at this point in the history
  • Loading branch information
livialima committed Nov 7, 2023
1 parent b0b34ab commit 610ed38
Showing 1 changed file with 103 additions and 30 deletions.
133 changes: 103 additions & 30 deletions docs/02.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,108 @@
# Day 2 - Basic navigation

* [Complementary video](https://youtu.be/x_VBskTUzxg)
* [Lesson video](https://youtu.be/x_VBskTUzxg)

## INTRO

Most computer users outside of the Linux and Unix world don't spend much time at the command-line now, but as a Linux sysadmin this is your default working environment - so you need to be skilled in it.

When you use a graphic desktop such as Windows or Apple's macOS (or even the latest Linux flavors), then increasingly you are presented with simple "places" where your stuff is stored - "Pictures" "Music" etc but if you're even moderately technical then you'll realize that underneath all this is a hierarchical "directory structure" of "folders" (e.g. *C:\\Users\\Steve\\Desktop* on Windows or */Users/Steve/Desktop* on macOS - and on a Desktop Linux system */home/steve/Desktop*)
When you use a graphic desktop such as Windows or Apple's macOS (or even the latest Linux flavors), then increasingly you are presented with simple "places" where your stuff is stored - "Pictures" "Music" etc but if you're even moderately technical then you'll realize that underneath all this is a hierarchical "directory structure" of "folders" (e.g. *C:\\Users\\Steve\\Desktop* on Windows or */Users/Steve/Desktop* on macOS - and on a Desktop Linux system */home/steve/Desktop*)

_From now on, the course will point you to a range of good online resources for a topic, and then set you a simple set of tasks to achieve. It’s perfectly fine to google for other online resources, refer to any books you have etc - and in fact a *fundamental element* of the design of this course is to force you to do a bit of your own research. Even the most experienced sysadmins will do an online search to find advice for how to use commands - so the sooner you too get into that habit the better!_
From now on, the course will point you to a range of good online resources for a topic, and then set you a simple set of tasks to achieve. It’s perfectly fine to google for other online resources, refer to any books you have etc - and in fact a fundamental element of the design of this course is **to force you to do a bit of your own research**. Even the most experienced sysadmins will do an online search to find advice for how to use commands - so the sooner you too get into that habit the better!

## YOUR TASKS TODAY

* Use the provided resources to check out the basic commands and concepts
* Login to your server via SSH and move around the directory structure at the command-line
* Take note of how your “prompt” changes as you change directory
* Be sure to understand how `cd` on its own takes you back to your “home directory”
* Understand what `cd ~` and `cd ..` do
* Use the `ls` command to list the contents of directories, and try several of the “switches” - in particular `ls -ltr` to show the most recently altered file last
* Use the `mkdir` command to create a new directory (folder) `test` in your home folder ( e.g `/home/support/test`)
* Find the documentation for the commands we used so far - [demo](https://asciinema.org/a/619679)
* Navigate between directories, then create, list, move and delete files - [demo](https://asciinema.org/a/619680)

## STEP-BY-STEP
## RTFM

This is a good time to mention that one of the many advantages of Linux is that it's designed to let you know the system, to let you learn how to use it. The documentation available in form of text manuals, guides and forums is where you will spend most of your time during this journey.

Whereas proprietary systems have some free documentation, you see much more frequently the use of paid customer support to fix issues or find how a particular task can be executed. Although you can also do this with Linux (Canonical, RedHat and SuSE are examples of companies that offer support in the same fashion), this is most likely not the case. And you are here to learn, so...

Which leads us to the famous acronym [RTFM](https://en.wikipedia.org/wiki/RTFM). Reading the manual is **the first thing** you should do when you're learning a command. We will go through the many ways to obtain that information but if at the end of that search you need more insight, you can always [ask a well written question](https://opensource.com/life/16/10/how-ask-technical-questions) in forums and other communities.

Starting with the `man` command. Each application installed comes with its own page in this manual, so that you can look at the page for `pwd` to see the full detail on the syntax like this:

`man pwd`

You might also try:

man cp
man mv
man grep
man ls
man man

As you’ll see, these are excellent for the detailed syntax of a command, but many are extremely terse, and for others the amount of detail can be somewhat daunting!

And that's why `tldr` is such a powerful tool! You can easily [install it](https://tldr.sh/) with `sudo apt install tldr` or follow [this demo](https://asciinema.org/a/619672).

```bash
$ tldr pwd
pwd
Print name of current/working directory.More information: https://www.gnu.org/software/coreutils/pwd.

- Print the current directory:
pwd

- Print the current directory, and resolve all symlinks (i.e. show the "physical" path):
pwd -P
```

If you know a keyword or some description of what the command is supposed to do, you can try `apropos` or `man -k` like this:

```bash
$ apropos "working directory"
git-stash (1) - Stash the changes in a dirty working directory away
pwd (1) - print name of current/working directory
pwdx (1) - report current working directory of a process

$ man -k "working directory"
git-stash (1) - Stash the changes in a dirty working directory away
pwd (1) - print name of current/working directory
pwdx (1) - report current working directory of a process
```

But you'll soon find out that not every command has a manual that you can read with `man`. Those commands are contained within the shell itself and we call them [builtin commands](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html).

There are some overlaping (i.e. builtin commands that also have a man page) but if `man` does not work, we use `help` to display information about them.

* Login to your server using ssh
```bash
$ man export
No manual entry for export

$ help export
export: export [-fn] [name[=value] ...] or export -p
Set export attribute for shell variables.

Marks each NAME for automatic export to the environment of subsequently
executed commands. If VALUE is supplied, assign VALUE before exporting.

Options:
-f refer to shell functions
-n remove the export property from each NAME
-p display a list of all exported variables and functions

An argument of `--' disables further option processing.
Exit Status:
Returns success unless an invalid option is given or NAME is invalid.
```
The best way to know if a command is a builtin command, is to check its `type`:
```bash
$ type export
export is a shell builtin
```
And lastly, `info` reads the documentation stored in [info](https://en.wikipedia.org/wiki/Info_(Unix)) format.
## NAVIGATE THE FILE STRUCTURE
* Start by reading the manual: `man hier`
* `/` is the "root" of a branching tree of folders (also known as directories)
* At all times you are "in" one part of the system - the command `pwd` ("print working directory") will show you where you are
* Generally your prompt is also configured to give you at least some of this information, so if I'm "in" the _/etc_ directory then the prompt might be `steve@202.203.203.22:/etc$` or simply `/etc: $`
Expand All @@ -34,25 +114,19 @@ _From now on, the course will point you to a range of good online resources for
* By convention, files with a starting character of "." are considered hidden and the `ls`, and many other commands, will ignore them. The `-a` switch includes them. You should see a number of hidden files in your home directory.
* A note on switches: Generally most Linux command will accept one or more "parameters", and one or more "switches". So, when we say `ls -l /var/log` the "`-l`" is a switch to say "long format" and the "`/var/log`" is the "parameter". Many commands accept a large number of switches, and these can generally be combined (so from now on, use `ls -ltra`, rather than `ls -l -t -r -a`
* In your home directory type `ls -ltra` and look at the far left hand column - those entries with a "d" as the first character on the line are directories (folders) rather than files. They may also be shown in a different color or font - if not, then adding the "--color=auto" switch should do this (i.e. `ls -ltra --color=auto`)
* You can make a new folder/directory with the `mkdir` command, so move to your home directory, type `pwd` to check that you are indeed in the correct place, and then create a directory, for example to create one called "test", simply type `mkdir test`. Now use the `ls` command to see the result.

## RTFM
This is a good time to mention that Linux comes with a fine on-line manual - invoked with the `man` command. Each application installed comes with its own page in this manual, so that you can look at the page for _pwd_ to see the full detail on the syntax like this:
## BASIC DIRECTORY MANIPULATION
`man pwd`

You might also try:


man cp
man mv
man grep
man ls
man man
* You can make a new folder/directory with the `mkdir` command, so move to your home directory, type `pwd` to check that you are indeed in the correct place, and then create a directory, for example to create one called "test", simply type `mkdir test`. Now use the `ls` command to see the result.
* You can create even more directories, nesting inside directories, and then navigate between them with the `cd` command.
* When you want to move that directory inside another directory, you use `mv` and specify the path to move.
* To delete (or remove) a directory, use `rmdir` if the directory is empty or `rm -r` if there still any files or other directories inside of it.
## BASIC FILE MANIPULATION
As you’ll see, these are excellent for the detailed syntax of a command, but many are extremely terse, and for others the amount of detail can be somewhat daunting!
* You can make new empty files with the `touch` command, so you can explore a little more of the `ls` command.
* When you want to move that file to another directory, you use `mv` and specify the path to move.
* To delete (or remove) a file, use `rm`.
## WRAP
Expand All @@ -64,12 +138,11 @@ If this is already something that you’re very familiar with, then:
* Learn about `pushd` and `popd` to navigate around multiple directories easily. Running `pushd /var/log` moves you to to the `/var/log`, but keeps track of where you were. You can `pushd` more than one directory at a time. Try it out: `pushd /var/log`, `pushd /dev`, `pushd /etc`, `pushd`, `popd`, `popd`. Note how `pushd` with no arguments switches between the last two _pushed_ directories but
[more complex navigation is also possible](https://opensource.com/article/19/8/navigating-bash-shell-pushd-popd). Finally, `cd -` also moves you the last visited directory.
* Take the time today to understand how the environment variable PS1 etc work (this article: [Bash Shell: Take Control of PS1, PS2, PS3, PS4 and PROMPT_COMMAND
](http://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/) is a good start).
* Set yourself up with a custom prompt using the information in [Bash Shell PS1: 10 Examples to Make Your Linux Prompt like Angelina Jolie](http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/)
## RESOURCES
* [Difference between help, info and man command](https://unix.stackexchange.com/questions/19451/difference-between-help-info-and-man-command)
* [GNU Texinfo](https://www.gnu.org/software/texinfo/)
* [Explore the Linux file system](https://www.digitalocean.com/community/tutorials/how-to-use-cd-pwd-and-ls-to-explore-the-file-system-on-a-linux-server)
* [Linux File System](https://www.youtube.com/watch?v=2qQTXp4rBEE)
* [Simple Terminal Commands on Ubuntu](http://www.youtube.com/watch?v=CGBsurVdLGY)
Expand Down

0 comments on commit 610ed38

Please sign in to comment.