Day 2 - Basic navigation
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)
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
cdon its own takes you back to your “home directory”
- Understand what
- Use the
lscommand to list the contents of directories, and try several of the “switches” - in particular
ls -ltrto show the most recently altered file last
- Use the
mkdircommand to create a new directory (folder)
testin your home folder ( e.g
- Login to your server using ssh
/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
[email protected]:/etc$or simply
cdmoves to different areas - so
cd /var/logwill take you into the
/var/logfolder - do this and then check with
pwd- and look to see if your prompt changes to reflect your location.
- You can move “up” the structure by typing
cd ..( “cee dee dot dot “) try this out by first
cd ..and then
cd ..again - watching your prompt carefully, or typing pwd each time, to clarify your present working directory.
- A “relative” location is based on your present working directory - e.g. if you first
cd /varthen pwd will confirm that you are “in”
/var, and you can move to
/var/login two ways - either by providing the full path with
cd /var/logor simply the “relative” path with the command
- A simple
cdwill always return you to your own defined “home directory”, also referred to as
~(the “tilde” character) [NB: this differs from DOS/Windows]
- What files are in a folder? The
ls(list) command will give you a list of the files, and sub folders. Like many Linux commands, there are options (known as “switches”) to alter the meaning of the command or the output format. Try a simple
ls -l -tand then try
ls -l -t -r -a
- By convention, files with a starting character of “.” are considered hidden and the
ls, and many other commands, will ignore them. The
-aswitch 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/logthe “
-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 -ltraand 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
mkdircommand, so move to your home directory, type
pwdto 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
lscommand to see the result.
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:
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!
Being able to move confidently around the directory structure at the command line is important, so don’t think you can skip it! However, these skills are something that you’ll be constantly using over the twenty days of the course, so don’t despair if this doesn’t immediately “click”.
If this is already something that you’re very familiar with, then:
- Learn about
popdto navigate around multiple directories easily. Running
pushd /var/logmoves you to to the
/var/log, but keeps track of where you were. You can
pushdmore than one directory at a time. Try it out:
popd. Note how
pushdwith no arguments switches between the last two pushed directories but more complex navigation is also possible. 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 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
- Explore the Linux file system
- Linux File System
- Simple Terminal Commands on Ubuntu
- Solaris Unix Commands
Some rights reserved. Check the license terms here