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!
- Use the provided resources to check out the basic commands and concepts
- Login to your server via SSH and move about 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 ~
andcd ..
do - Use the
ls
command to list the contents of directories, and try several of the “switches” - in particularls -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
)
- 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 "/etc: $"
cd
moves to different areas - socd /var/log
will take you into the/var/log
folder - do this and then check withpwd
- 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 firstcd
'ing to/var/log/
thencd ..
and thencd ..
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 /var
then pwd will confirm that you are "in"/var
, and you can move to/var/log
in two ways - either by providing the full path withcd /var/log
or simply the "relative" path with the commandcd log
- A simple
cd
will 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 simplels
, thenls -l -t
and then tryls -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-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, usels -ltra
, rather thanls -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, typepwd
to check that you are indeed in the correct place, and then create a directory, for example to create one called "test", simply typemkdir test
. Now use thels
command 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:
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!
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
pushd
andpopd
to navigate around multiple directories easily. Runningpushd /var/log
moves you to to the/var/log
, but keeps track of where you were. You canpushd
more than one directory at a time. Try it out:pushd /var/log
,pushd /dev
,pushd /etc
,pushd
,popd
,popd
. Note howpushd
with 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
Copyright 2012-2021 @snori74 (Steve Brorens). Can be reused under the terms of the Creative Commons Attribution 4.0 International Licence (CC BY 4.0).