# systemd & cron — Linux Command Line Fundamentals

Source: https://www.skillbyai.com/en/linux/linux-systemd-cron

> Control services with systemctl and schedule recurring jobs with cron and crontab.

## systemctl — manage services

`systemd` runs background services on most modern distros; `systemctl` is how you control them.

```bash
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl status nginx
```

Output:

```
● nginx.service - A high performance web server
   Active: active (running) since Thu 2026-09-04 09:00:00 IST
```

## cron — schedule recurring jobs

**cron** runs commands on a schedule you define, using five time fields: minute, hour, day-of-month, month, day-of-week.

## crontab -e

`crontab -e` opens your personal crontab for editing.

```bash
# run backup.sh every day at 2:30 AM
30 2 * * * /home/alice/backup.sh
```

**Quiz:** Which tool is used to run a script automatically every night at a fixed time?

- [ ] systemctl
- [x] cron
- [ ] scp
- [ ] grep

*Answer:* cron. cron is Linux's built-in job scheduler for recurring tasks.

## Final quiz 1 of 8

Final quiz

**Quiz:** Which command shows your current directory?

- [ ] ls
- [ ] cd
- [x] pwd
- [ ] whoami

*Answer:* pwd. pwd prints the working directory.

## Final quiz 2 of 8

Final quiz

**Quiz:** What does chmod 755 file set?

- [ ] rw-r--r--
- [ ] rwxrwxrwx
- [ ] r--r--r--
- [x] rwxr-xr-x

*Answer:* rwxr-xr-x. 7 = rwx, 5 = r-x.

## Final quiz 3 of 8

Final quiz

**Quiz:** Which command follows a log file live?

- [x] tail -f
- [ ] cat
- [ ] head
- [ ] wc

*Answer:* tail -f. tail -f streams new lines as they are written.

## Final quiz 4 of 8

Final quiz

**Quiz:** What does `command > /dev/null 2>&1` do?

- [ ] Appends output to a file
- [x] Discards stdout and stderr
- [ ] Runs in background
- [ ] Shows only errors

*Answer:* Discards stdout and stderr. /dev/null swallows everything redirected to it.

## Final quiz 5 of 8

Final quiz

**Quiz:** Which signal cannot be caught or ignored?

- [ ] SIGTERM
- [ ] SIGINT
- [x] SIGKILL
- [ ] SIGHUP

*Answer:* SIGKILL. SIGKILL always terminates the process.

## Final quiz 6 of 8

Final quiz

**Quiz:** How do you install a package on Ubuntu?

- [ ] dnf get name
- [ ] pacman -Q name
- [ ] brew add name
- [x] sudo apt install name

*Answer:* sudo apt install name. apt is the Debian and Ubuntu package manager.

## Final quiz 7 of 8

Final quiz

**Quiz:** What does PATH do?

- [x] Lists directories searched for commands
- [ ] Stores your home directory
- [ ] Lists open files
- [ ] Sets the prompt

*Answer:* Lists directories searched for commands. The shell searches PATH entries in order.

## Final quiz 8 of 8

Final quiz

**Quiz:** Which tool schedules a recurring job?

- [ ] scp
- [x] cron
- [ ] grep
- [ ] tar

*Answer:* cron. crontab entries define time fields and commands.
