Skip to content

Configuring the system by command

Exercise configuring-the-system-by-command-annex.pdf · PDF

A message on your phone says sent 11:20. Your friend is in New York. What does her phone show? 05:20. Same instant, different label. Somebody had to tell each phone where it is.

That is configuration: the facts a machine cannot find out alone — its name, its clock, its language, and where to look for programs. In Monitoring performance you looked at a machine. Today you change it, with the keyboard only. And you will finally understand the most common error message of your career: command not found.

What you will learn

  • Read and change the hostname, and say why /etc/hosts has to follow
  • Check the clock, the time zone and NTP synchronisation with timedatectl
  • Read the locale of a session and generate a new one
  • Explain what an environment variable is, and what export adds
  • Explain how the shell finds a command with PATH, and make your own script runnable by name
  • Make an alias and a variable permanent in ~/.bashrc
  • Why "command not found" almost never means "not installed"

The sheet on the kitchen wall

Back to the kitchen of Unit 1. The operating system is the kitchen manager, and the manager keeps a sheet on the wall: the name of the kitchen, the wall clock, the language of the labels, and the list of drawers where the tools are. Today you read and edit that sheet.

On the sheet Linux command or file Windows (PowerShell)
Name of the machine hostnamectl, /etc/hostname hostname, Rename-Computer
Clock and time zone timedatectl Get-TimeZone, Set-TimeZone
Language and formats locale, /etc/locale.gen Get-Culture
Where commands live $PATH $env:Path
Your start-up file ~/.bashrc the file in $PROFILE

The hostname

The hostname is the name a machine gives itself.

You see it in the prompt (marta@deb-lab), in every log line and on the network.

$ hostnamectl
 Static hostname: deb-lab
Operating System: Debian GNU/Linux 13 (trixie)
    Architecture: x86-64

(Other lines appear too.) The name is stored in the file /etc/hostname. hostnamectl set-hostname writes that file and tells the running kernel, so no reboot is needed:

sudo hostnamectl set-hostname deb-yoursurname   # small letters, no spaces
sudo nano /etc/hosts                            # change the old name on the 127.0.1.1 line

The terminal that is already open keeps the old name in its prompt: open a new one. If you forget /etc/hosts, every sudo complains:

sudo: unable to resolve host deb-surname: Name or service not known

It is only a warning — sudo still works — but the fix is the line 127.0.1.1 deb-surname in /etc/hosts. At the end of the exercise, put the name deb-lab back in both places: the rest of the course uses it.

Careful: the hostname is not how others find you

Changing the hostname does not make other computers find you by that name. It is what the machine calls itself. Other machines need DNS or their own /etc/hosts to find it — Unit 3.

The clock: UTC, time zones and NTP

Three ideas:

  • The kernel counts time in UTC (Coordinated Universal Time): one clock for the whole planet, no summer time.
  • The time zone is only a rule to show UTC as local time. Zones are named Region/City: Europe/Madrid.
  • NTP (Network Time Protocol) keeps the clock right by asking time servers on the Internet.
$ timedatectl
               Local time: Mon 2026-10-05 22:52:24 CEST
           Universal time: Mon 2026-10-05 20:52:24 UTC
                Time zone: Europe/Madrid (CEST, +0200)
System clock synchronized: yes
              NTP service: active

Try another zone, look, and put Madrid back:

timedatectl list-timezones                      # about 500 lines; q leaves the pager
sudo timedatectl set-timezone America/New_York
date                                            # 6 hours less than Madrid
sudo timedatectl set-timezone Europe/Madrid

Look at the Universal time line while you do it: it does not move. Only the way the time is shown changes.

Who keeps the world's time rules? Volunteers

Since 1986, the list of every time zone rule on Earth has been kept by volunteers. Arthur David Olson, a programmer at the US National Institutes of Health, started the tz database. Every time a government changes its summer time, somebody sends a correction. Since 2011 it is published by IANA, the same body that hands out Internet numbers. Every Linux, Android phone and Mac carries a copy. That is why you write Europe/Madrid and not "+1": the rule for Madrid can change, the city does not.

Why does a server care about ten minutes of error? Think of the logs from Logs and journald: with wrong clocks, the events of two machines cannot be put in order.

The locale

A locale is a set of conventions for showing things: the language of messages, the date format, the decimal comma, the currency, the alphabetical order.

locale                          # shows LANG=... and the LC_* variables

The same question, two locales:

$ LC_ALL=es_ES.UTF-8 locale currency_symbol decimal_point
€
,
$ LC_ALL=en_GB.UTF-8 locale currency_symbol decimal_point
£
.

A locale must be generated before you can use it. On Debian, the list lives in /etc/locale.gen:

sudo nano /etc/locale.gen       # delete the "# " before ca_ES.UTF-8 UTF-8 and es_ES.UTF-8 UTF-8
sudo locale-gen
locale -a                       # now lists ca_ES.utf8 and es_ES.utf8
LC_TIME=ca_ES.UTF-8 date        # dilluns, 5 d’octubre de 2026, ...

Careful to uncomment the UTF-8 lines, not their older neighbours.

Careful: the locale does not translate your files

Changing the locale changes how programs show dates, numbers and messages. File names and file contents stay exactly the same.

Environment variables

An environment variable is a named note that a process carries and hands to the programs it starts: HOME, USER, LANG, PATH...

Picture the bash process with a small sheet of notes. When it starts a child program, the child receives a copy of the sheet.

flowchart LR
    subgraph BASH ["bash (your terminal)"]
        V1["COURSE=SI<br><i>shell variable only</i>"]
        V2["export COURSE<br><b>now on the sheet</b>"]
    end
    BASH -->|"starts, hands a COPY<br>of the exported notes"| CHILD["<b>child process</b><br>bash -c, python3, a script"]
    CHILD -.->|"can never change<br>the parent's sheet"| BASH
  • NAME=value makes a shell variable: only this shell sees it.
  • export NAME puts it on the sheet that children receive.
  • A child can never change the parent's sheet. Closing the terminal throws the sheet away.

Test it — the single quotes matter, so that the child shell, not yours, reads the variable:

echo $USER $HOME $SHELL
COURSE=SI
bash -c 'echo $COURSE'     # empty line: the child did not get it
export COURSE
bash -c 'echo $COURSE'     # SI

Two classic mistakes: spaces around = (COURSE = SI runs a command called COURSE), and double quotes in the test (then your shell fills in the value and the test proves nothing).

PATH: how the shell finds a command

You type ls. There is no file called ls in your folder. How does bash find it?

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

PATH is a list of directories separated by :. The shell looks in them in order and runs the first match.

In the kitchen: the chef asks for "the whisk"; the manager has a list of drawers and opens them in order. If the whisk is in a drawer that is not on the list, the answer is "there is no whisk" — command not found — even though it exists.

echo $PATH | tr ':' '\n'   # one directory per line: 5 for a normal user on Debian 13
type ls                    # ls is aliased to `ls --color=auto'
type cd                    # cd is a shell builtin: not a file at all
which python3              # the directory where the python3 file lives

Your own command

mkdir ~/bin
nano ~/bin/hello
#!/bin/bash
echo "Hello from $(hostname), it is $(date +%H:%M)"
chmod +x ~/bin/hello
hello                            # bash: hello: command not found
~/bin/hello                      # works: you gave the full path
export PATH="$HOME/bin:$PATH"    # add your drawer at the front of the list
hello                            # works now, in this terminal

Two ways to break it

  • Without chmod +x the message is Permission denied — a different problem.
  • PATH=$HOME/bin without :$PATH replaces the whole list, and every command disappears. Cure: close the terminal and open a new one.

Careful: the current folder is not in PATH

The Windows Command Prompt (cmd) searches the current folder first; Linux does not, on purpose: a file called ls left in a shared folder would run instead of the real one. That is why a script in your folder is started as ./script.

So "command not found" almost never means the program is missing. It means: it is not in any drawer of my list. Your first question is always: where is the file, and is that directory in PATH?

Making it permanent: .bashrc and aliases

Open a new terminal and type hello. Not found again. Everything you did lived in one shell and died with it. To keep it, write it in a file that bash reads when it starts:

File Read when
~/.bashrc Every new terminal window (interactive shell). Aliases and prompt go here.
~/.profile Once, when you log in. On Debian it already adds ~/bin to PATH — but only if the directory existed at login.
/etc/profile, /etc/environment The same, for every user. Needs sudo.

So your hello will work on its own after the next login: ~/bin exists now.

An alias is a short name for a long command: alias ll='ls -la'.

nano ~/.bashrc        # no sudo! add at the end:
#   alias ll='ls -la'
#   export EDITOR=nano
source ~/.bashrc      # re-read it in this terminal
type ll               # ll is aliased to `ls -la'
echo $EDITOR          # nano

Careful: .bashrc is read when a shell starts

"I edited .bashrc and nothing happened" — open a new terminal or run source ~/.bashrc. And never open it with sudo nano: the file would become root's. If it happened, sudo chown $USER: ~/.bashrc gives it back.

The same on Windows

hostname
Get-TimeZone
Get-Culture
$env:Path -split ';'
$env:COURSE = "SI"
notepad $PROFILE
Task Bash PowerShell
Rename the machine hostnamectl set-hostname ws-marta Rename-Computer -NewName "WS-MARTA" (as administrator, needs a restart)
Time zone of Madrid timedatectl set-timezone Europe/Madrid Set-TimeZone -Id "Romance Standard Time"
See the locale locale Get-Culture
See PATH echo $PATH $env:Path
Set a variable export COURSE=SI $env:COURSE = "SI"
Make an alias alias ll='ls -la' Set-Alias ll Get-ChildItem

Three differences: environment variables are written $env:NAME; the PATH separator is ; and not :; the start-up file is the one whose path is stored in $PROFILE (it may not exist yet).

Key takeaways

  • The hostname lives in /etc/hostname; hostnamectl set-hostname changes it live, and /etc/hosts must follow.
  • The kernel keeps UTC; the time zone (Europe/Madrid, from the tz database) only changes how it is shown; NTP keeps it right.
  • A locale is a set of conventions (dates, decimals, currency, language), generated with locale-gen.
  • An environment variable is a note handed to child processes; export is what puts it on the sheet.
  • PATH is the ordered list of directories where the shell looks for commands: "command not found" usually means "not in PATH".
  • Changes in a terminal die with it; ~/.bashrc (every terminal) and ~/.profile (login) make them permanent. An alias is a short name for a command.

Quick check

1. Where is the hostname of a Debian machine stored?
  • In /etc/hostname
  • In /etc/hosts
  • In ~/.bashrc
  • In /etc/passwd

The hostname lives in /etc/hostname, and hostnamectl set-hostname writes it. /etc/hosts is a different file that maps names to addresses — it must be updated too, or sudo warns that it cannot resolve the host.

2. You set the time zone to America/New_York. What happens to the clock the kernel keeps in UTC?
  • Nothing: only the way the time is shown changes
  • It goes back six hours
  • It stops until an NTP server answers
  • It is reset to midnight

The kernel counts in UTC. The time zone is only a rule to show UTC as local time, which is why the Universal time line of timedatectl does not move.

3. Typing backup gives command not found, but /opt/tools/backup works. What is the cause?
  • The directory /opt/tools is not in PATH
  • The file is not executable
  • The file is empty
  • The command needs sudo to be found

If the full path works, the file exists and is executable. The shell only searches the directories listed in PATH, and /opt/tools is not one of them — the whisk is in a drawer that is not on the list.

4. You type COLOUR=blue and start a script from that terminal. The script prints $COLOUR empty. Why?
  • The variable was not exported
  • Variables need capital letters only
  • Scripts cannot read any variables
  • The value needs double quotes

COLOUR=blue creates a shell variable that only your shell sees. export COLOUR puts it in the environment, the copy that child processes like the script receive.

5. In which file do you write an alias so that every new terminal has it?
  • ~/.bashrc
  • /etc/hostname
  • /etc/locale.gen
  • ~/.bash_history

Bash reads ~/.bashrc every time an interactive shell starts. After editing it, open a new terminal or run source ~/.bashrc.

6. What does changing the locale from en_GB.UTF-8 to es_ES.UTF-8 change?
  • How programs show dates, numbers and currency
  • The language of the text inside your files
  • The names of the files in your home folder
  • The time zone of the machine

A locale is a set of display conventions: es_ES shows € and a decimal comma, en_GB shows £ and a decimal point. Files are not translated, and the time zone is a separate setting.

7. Pau runs export PATH=$HOME/bin in his terminal. Select the two that are true.
  • Commands like ls stop being found in that terminal
  • Opening a new terminal gives him a working PATH again
  • His own scripts in ~/bin stop working
  • The change is saved for every future login

Without :$PATH at the end, the new value replaces the whole list, so only ~/bin is searched. The change lives only in that shell, so a new terminal starts with the normal PATH. The correct line is export PATH="$HOME/bin:$PATH".

Next: put the unit so far on one page you can trust under pressure — Sysadmin cheat sheet.