Skip to content

Unix / Linux - Getting Started

A Unix-like operating system (OS) acts as an intermediary between the computer hardware and the user. It manages system resources and provides an environment for applications to run.

The core of the OS, responsible for managing hardware resources (CPU, memory, devices) and fundamental tasks, is called the kernel.

Users typically interact with the kernel indirectly through a program called the shell. The shell is a command-line interpreter: it takes commands you type, interprets them, and instructs the kernel or other programs to perform actions. Popular modern shells include Bash (Bourne Again SHell) and Zsh (Z Shell).

  • Unix originated around 1969 at AT&T Bell Labs, developed by Ken Thompson, Dennis Ritchie, and others. Its design principles heavily influenced subsequent operating systems.
  • Today, numerous Unix-like systems exist. Examples include commercial Unix versions (like Solaris, AIX), open-source BSD variants (FreeBSD, OpenBSD), and notably, Linux. Linux is technically just the kernel, but distributions like Ubuntu, Fedora, and Debian bundle it with utilities and applications to create a complete OS. macOS is also a certified Unix system.
  • These systems are inherently multi-user, allowing multiple people to use the computer simultaneously, each with their own environment and permissions.
  • They are also multi-tasking, enabling users and the system to run multiple programs concurrently.

A simplified view of a typical Unix-like system architecture involves several layers:

  • Hardware: The physical components of the computer (CPU, memory, disks, network interfaces, etc.).
  • Kernel: The core of the OS. It directly interacts with the hardware, manages system resources (memory management, process scheduling, file system access), and provides essential services through system calls.
  • Shell: The command-line interface (CLI) allowing users to interact with the system. It reads commands, interprets them, and executes programs. Common shells are Bash (often the default on Linux) and Zsh (default on newer macOS).
  • Commands and Utilities: A vast collection of standard programs that perform specific tasks (e.g., cp for copy, mv for move/rename, ls for listing files, grep for searching text). These utilities are fundamental tools for system administration and daily use. Many more are available through package managers.
  • Files and Directories: Data and programs are organized into files. Files are grouped into directories (folders). Directories can contain other directories, forming a hierarchical tree structure known as the filesystem. This standardized structure (often following the Filesystem Hierarchy Standard - FHS) helps organize the system (e.g., /bin for essential binaries, /etc for configuration, /home for user directories).

Think of it like building with blocks: The hardware is the base, the kernel is the essential foundation managing the base, the shell is your tool to tell the system what blocks to place where, and the commands/utilities are the specific blocks you use to build applications or manage the structure (filesystem).

If you have a Unix-like system installed (like Linux or macOS), starting the computer initiates the boot process (involving firmware like BIOS/UEFI, a bootloader like GRUB, and an init system like systemd or launchd) which eventually leads to a login prompt, either graphical or text-based.

For remote access, you’ll typically use the SSH (Secure Shell) protocol to connect securely to the server’s command line from your local machine using an SSH client.

Whether connecting locally via a terminal emulator or remotely via SSH, you’ll usually be prompted for your username and password:

login: your_username
Password:
  • Ensure you have a username (user ID) and password. If not, contact your system administrator.
  • Type your username at the login: prompt and press Enter. Usernames are often case-sensitive.
  • Type your password at the Password: prompt and press Enter. For security, your password characters will typically not be displayed as you type. Passwords are almost always case-sensitive.
  • Upon successful authentication, you’ll usually see some system messages (like the last login time/location) followed by the shell prompt. This prompt indicates the shell is ready to accept your commands. It often ends with a $ for regular users or # for the root (administrator) user.
Last login: Mon Jul 29 10:15:00 2024 from 192.168.1.10
your_username@hostname:~$

At the prompt, you can type commands. For example, to display a calendar for the current month, use the cal command:

$ cal
July 2024
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
$

Regularly changing your password and using strong, unique passwords is crucial for security. Most Unix-like systems provide the passwd command for this:

Step 1: Type passwd at the command prompt and press Enter.

Step 2: The system will prompt you for your current password for verification.

Step 3: You’ll be asked to enter your new password. Choose a strong password (mix of upper/lowercase letters, numbers, symbols). Avoid dictionary words or personal information.

Step 4: You’ll need to re-enter the new password for confirmation.

$ passwd
Changing password for your_username.
(current) UNIX password:
New password:
Retype new password:
passwd: password updated successfully
$

Note: As with login, password entry is usually hidden for security. Consider using a password manager to generate and store strong, unique passwords.

As mentioned, data is organized in files and directories. The ls (list) command is fundamental for viewing the contents of a directory.

Using ls with the -l (long format) option provides detailed information:

$ ls -l
total 24
drwxr-xr-x 2 user group 4096 Jul 29 10:30 Documents
-rw-r--r-- 1 user group 8752 Jul 29 10:25 report.txt
-rwxr-xr-- 1 user group 5120 Jul 20 15:00 process_data.sh
drwxrwxr-- 3 user group 4096 Jul 15 09:00 Projects

Explanation of ls -l output columns:

  • First character: File type (d for directory, - for regular file, l for symbolic link, etc.).
  • Permissions: Nine characters representing read (r), write (w), execute (x) permissions for the owner, group, and others.
  • Number of links: Hard link count.
  • Owner: The username of the file’s owner.
  • Group: The group associated with the file.
  • Size: File size in bytes (use ls -lh for human-readable sizes like KB, MB).
  • Modification time: Date and time the file was last modified.
  • Name: The name of the file or directory.

To see hidden files (names starting with a dot .), use the -a option: ls -la or ls -lha.

To quickly check which user account you are currently logged in as, use the whoami command:

$ whoami
your_username
$

This is useful if you manage multiple accounts or need to confirm your current user context.

On multi-user systems, you might want to see who else is currently logged in. Several commands provide this information with varying levels of detail:

  • users: Lists usernames of logged-in users, separated by spaces.
  • who: Shows who is logged on, their terminal line, login time, and potentially the origin host.
  • w: Provides more detail than who, including what command each user is currently running, system uptime, and load averages.
$ users
user1 admin guest
$ who
user1 tty1 2024-07-29 09:15
guest pts/0 2024-07-29 10:30 (192.168.1.10)
admin pts/1 2024-07-29 11:00 (client.example.com)
$ w
11:05:30 up 1:50, 3 users, load average: 0.10, 0.15, 0.12
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user1 tty1 - 09:15 1:50m 0.20s 0.10s -bash
guest pts/0 192.168.1.10 10:30 5.00s 0.05s 0.01s vim config.txt
admin pts/1 client.example.com 11:00 0.00s 0.15s 0.02s w
$

These commands are helpful for system monitoring and understanding system activity.

When you finish your command-line session, you should log out to secure your account and free up system resources.

  • Type the logout command at the prompt.
  • Alternatively, you can usually type exit.
  • In many shells, pressing Ctrl+D on an empty command line also signals the end of input and logs you out.

The system will typically close your session and disconnect you (if connected remotely).

Properly shutting down or rebooting a Unix-like system is important to ensure data integrity. These actions usually require administrator (root) privileges.

Common commands include:

CommandDescription
shutdown -h now or poweroffInitiates an immediate clean shutdown and powers off the machine. shutdown allows scheduling (e.g., shutdown -h +10 for shutdown in 10 minutes).
shutdown -r now or rebootInitiates an immediate clean shutdown and then restarts the machine. shutdown -r also allows scheduling.
haltHistorically stopped system processes but might not power off the hardware; poweroff is generally preferred now.
systemctl poweroffOn systems using the systemd init system (common on modern Linux), this command cleanly shuts down and powers off the system.
systemctl rebootOn systemd systems, this command cleanly shuts down and reboots the system.

Always use these commands instead of just cutting the power, especially on servers, to prevent data corruption or filesystem issues. You typically need to use sudo before these commands (e.g., sudo poweroff) if you are not logged in as the root user.