Skip to content

Latest commit

 

History

History
79 lines (54 loc) · 7.4 KB

02.md

File metadata and controls

79 lines (54 loc) · 7.4 KB

Day 2 - Basic navigation

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)

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 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 ~ 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)

STEP-BY-STEP

  • 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 - so cd /var/log will take you into the /var/log folder - 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'ing to /var/log/ then 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 /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 with cd /var/log or simply the "relative" path with the command cd 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 simple ls, then ls -l -t and 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 -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:

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!

WRAP

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”.

EXTENSION

If this is already something that you’re very familiar with, then:

RESOURCES

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).