186 Linux basics [1d]

Updated . Posted . Visible to the public.

Our workstations and servers run Linux. This lesson covers the command-line tools you need every day, from file and process handling to SSH and shell scripts.

Important

Work on this lesson in advisor mode.

Learning goals

  • You can look around a Linux system from the shell: files and directories, running processes, disk usage, open network ports, installed packages.
  • You can explain file ownership and the nine permission flags, and change them.
  • You can make a script executable and run it directly, in bash and in Ruby, using a shebang line.
  • You can connect to a server with SSH and copy files to and from it, and you can explain why you log in as the deploy user and what that user may and may not touch.
  • You can edit a file in a terminal editor (e.g. vim or nano) and have made it your $EDITOR.
  • You use the shell efficiently: history search, tab completion, pipes, and job control to suspend and resume programs.
  • You can configure your shell and tools through their dotfiles, e.g. ~/.bashrc, ~/.ssh/config, ~/.gitconfig.
  • You can find out how any command works, e.g. with man, tldr or --help.

Resources

Read what's new to you, skim what's familiar, skip what you already master. Stop when you can meet the learning goals.

Your agent can also generate an overview, a tutorial or an explanation for anything here, tailored to what you already know. Just ask.

Pick one introduction

For specific goals

Exercises

Basic commands

Experiment and do something useful with the following commands. You might need to use tldr or Google the command.

Configuration files

Understand what you can do with the following configuration files:

  • ~/.bashrc
  • ~/.ssh/config
  • ~/.gitconfig

Note that changes to your ~/.bashrc don't affect already opened shells.

Terminal editor

To edit files from within a terminal, you'll need a CLI editor.

# Example with vim

# open the configuration file
vim ~/.bashrc

# navigate to the end of the file,
# press "i" to switch to insert mode
# then type out the line you want to add
export EDITOR=vim

# persist your changes
:wq

Note

While you could set $EDITOR locally to a graphical to a editor like gedit, this is not possible for remote shells to our servers. Getting accustomed to a CLI editor will pay off in the long term.

Terminal shortcuts

Understand what the following shortcuts do in a terminal:

File ownership

Understand access rights and ownership of files:

  • What does "ownership" mean for files?
  • Each file has 9 flags, 3 read, 3 write, and 3 executable flags. What do they mean?
  • Write a simple bash script that prints a message. How can you execute it?
  • Write the same script in Ruby. What do you have to do to just call it from the command line without using the ruby command directly? Learn about the "shebang".
Profile picture of Henning Koch
Henning Koch
Last edit
Paul Demel
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra Curriculum (2015-07-08 17:52)