The terminal is not just a place to run commands one by one. Sysadmins and developers who spend long hours working in the terminal usually rely on a number of additional tools to make their work more efficient, ranging from managing multiple sessions simultaneously, writing scripts to automate repetitive tasks, to scheduling jobs to run automatically without supervision. This chapter introduces terminal multiplexers, shell scripting basics, as well as synchronization and scheduling utilities that are useful for daily tasks. Note that most tools in this chapter are not installed by default on Ubuntu 26.04 LTS or Fedora Workstation 44, so installation steps will be explained first in each section.
39.1 Terminal Multiplexer
A terminal multiplexer is a tool that allows us to run multiple sessions inside a single terminal window, ensuring that jobs keep running even if the terminal window is closed or the connection drops. This capability is invaluable for sysadmins who manage servers over SSH, as running processes will not terminate simply because the network connection disconnects unexpectedly.
39.1.1 tmux: Managing Multiple Terminal Sessions
tmux is the most popular terminal multiplexer, but it is not installed by default on Ubuntu or Fedora. Install it first with:
sudo apt install tmuxOn Fedora, use:
sudo dnf install tmuxtmux divides the screen into three conceptual layers: sessions, windows, and panes.
- A Session is an entire workspace environment that keeps running in the background.
- A Window is a tab inside a session.
- A Pane is a screen division inside a window.
To start tmux, run:
tmuxWe can name sessions for easier identification, especially when running multiple sessions simultaneously for different purposes:
tmux new -s kerjatmux works using a prefix key, which is the key combination Ctrl+b pressed before any other shortcut. Here are some basic tmux shortcuts:
| Shortcut | Function |
|---|---|
Ctrl+b c | Create a new window |
Ctrl+b n | Switch to the next window |
Ctrl+b p | Switch to the previous window |
Ctrl+b % | Split pane vertically |
Ctrl+b " | Split pane horizontally |
Ctrl+b d | Detach from the session |
To reattach to a detached session, use:
tmux attach -t kerjaIn practice, the most common sysadmin habit is opening tmux before running time-consuming tasks via SSH, such as large software installations, compilation, or transferring large files. If the SSH connection drops mid-way, the process continues to run inside the server's tmux session. We simply log in again and run tmux attach to resume monitoring the process, as if the connection was never lost.
Note that trying to create a new session with an existing name will fail with the error duplicate session: kerja. Check the list of active sessions using tmux ls before creating a new session, or attach directly to the existing session using tmux attach -t kerja if that was the intention.
To view the list of active sessions, use tmux ls. If you want to permanently save configurations such as status bar colors or change the prefix key, save the configuration in the ~/.tmux.conf file; this file is automatically read every time tmux launches.
39.1.2 screen: An Alternative to tmux
screen is an older multiplexer and serves as an alternative to tmux. Although it lacks some of tmux's features, screen is still widely used because it is lightweight and has been available in the Unix ecosystem for a long time; some legacy servers even include screen by default where tmux might not be installed, making it a valuable backup option to master. Just like tmux, screen needs to be installed first:
sudo apt install screenOn Fedora, use:
sudo dnf install screenOnce installed, launch it with:
screenscreen uses the prefix key Ctrl+a. To detach a session, press Ctrl+a then d, and to reattach, use screen -r. Similar to tmux, permanent configurations for screen can be saved in the ~/.screenrc file.
39.2 Basic Shell Scripting: Introduction
Shell scripting is a method of writing a sequence of commands into a file so they can be executed together, enabling the automation of repetitive tasks.
39.2.1 Shebang #!/bin/bash
The first line of a script is usually a shebang, which informs the system which shell should execute the script.
#!/bin/bashThanks to this shebang, the script will always be executed using Bash, even if launched from another shell such as Zsh.
In the field, the error message bad interpreter: /bin/bash^M: no such file or directory frequently appears when a script is written or edited in a Windows editor that saves line endings in CRLF format instead of Unix-native LF. Fix it by running dos2unix script_name.sh (install the package first if it is not available), or configure your text editor to use Unix line endings (LF).
39.2.2 Variables, Input, and Output
Variables store values that can be reused. Note that there must be no spaces around the equals sign.
nama="Budi"
echo "Halo, $nama"To prompt for user input, use the read command.
read nama
echo "Selamat datang, $nama"39.2.3 if-then-else Conditionals
Conditionals allow scripts to make decisions based on specific conditions.
if [ "$nama" = "Budi" ]; then
echo "Halo Budi"
else
echo "Halo pengunjung"
fi39.2.4 Simple Loops
Loops are used to repeat commands multiple times, for example using for.
for i in 1 2 3 4 5; do
echo "Angka $i"
done39.2.5 Creating a Useful Simple Script
For example, the following script prints the date and lists files in the active directory. Save it in a file, grant execution permissions, and run it.
#!/bin/bash
echo "Tanggal: $(date)"
echo "Isi direktori:"
ls -lAfter saving the file as info.sh, grant execution permissions and run it:
chmod +x info.sh
./info.shIf the message -bash: ./info.sh: Permission denied appears when attempting to run it, execute permissions have not been granted yet; run chmod +x info.sh first. If the error message is -bash: ./info.sh: No such file or directory even though the file clearly exists, the cause is likely an incorrect shebang pointing to a non-existent interpreter or Windows line endings as discussed earlier.
39.3 Other Useful Utilities
39.3.1 rsync: File Synchronization
rsync is a tool for copying and synchronizing files, both between local directories and between remote computers. Its main advantage is that it only transfers the modified parts of files. If it is not available on the system yet, install it with sudo apt install rsync on Ubuntu, or sudo dnf install rsync on Fedora.
rsync -av dokumen/ backup/This command copies the contents of the dokumen/ directory into backup/ in archive mode (-a) while displaying verbose progress (-v).
Note that trailing slashes on source paths significantly affect synchronization behavior. The command rsync -av dokumen/ backup/ (with a trailing slash after dokumen) copies all contents of the dokumen/ directory into backup/. Conversely, rsync -av dokumen backup/ (without a trailing slash) will recreate the dokumen directory itself inside backup/, resulting in backup/dokumen/. Such minor syntax differences often produce unintended sync results, so make it a habit to double-check trailing slashes before running the command.
The --delete option makes rsync remove files at the destination that no longer exist at the source, ensuring the destination directory stays completely identical to the source. Since this option is destructive and permanently deletes destination files, test it first with --dry-run (simulating execution without making actual changes) before executing the actual command, for example: rsync -av --delete --dry-run dokumen/ backup/.
39.3.2 cron: Automated Task Scheduling
cron is a task scheduler that automatically executes commands at specified times. Each user's schedule is stored in a crontab.
On Ubuntu, the cron package is usually installed by default. However, on Fedora Workstation 44, cron is not installed by default in recent releases, so running crontab -e will fail with a "command not found" error if it has not been installed yet. Install the cronie package (Fedora's cron implementation) first, then enable its service:
sudo dnf install cronie
sudo systemctl enable --now crondIf running crontab -e on Ubuntu does not work either, install and enable it similarly:
sudo apt install cron
sudo systemctl enable --now cronOnce cron is active, edit the crontab using:
crontab -eCrontab syntax consists of five time-and-date fields followed by the command to execute.
* * * * * perintahThe five columns respectively represent minute, hour, day of the month, month, and day of the week. For example, the following line runs a backup every day at 02:00.
0 2 * * * rsync -a /home/pengguna/dokumen/ /home/pengguna/backup/Note that commands executed by cron run with a much more minimal environment compared to an interactive shell, including a more restricted $PATH variable. A script that runs smoothly when executed directly from the terminal might fail under cron without clear error messages. To prevent this, use absolute paths for every command and file in the crontab, for example /usr/bin/rsync instead of just rsync, and redirect output to a log file to inspect results:
0 2 * * * /usr/bin/rsync -a /home/pengguna/dokumen/ /home/pengguna/backup/ >> /home/pengguna/backup.log 2>&1The command above appends (>>) both standard output and error messages (2>&1) into backup.log, allowing us to inspect log contents after the scheduled time passes to verify the job ran as expected. To list active schedules, use crontab -l.
As an additional note, Fedora increasingly encourages shifting task scheduling to systemd timers (a .timer unit paired with a .service unit, as discussed in Chapter 30) as a modern replacement for cron. For simple daily tasks, cron remains much easier to use since it only requires a single command line, making it a great choice for beginners.
Mastering terminal productivity tools makes work faster and more organized. Through tmux, we can manage multiple sessions simultaneously, shell scripting allows us to automate repetitive tasks, and rsync together with cron enable us to synchronize and schedule tasks automatically. In the next chapter, we will move on to storage and hardware management to better understand the underlying systems behind Linux.

