Unix / Linux - Getting Started
Unix/Linux - Getting Started
Section titled “Unix/Linux - Getting Started”What is a Unix-like Operating System?
Section titled “What is a Unix-like Operating System?”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.
Unix-like System Architecture
Section titled “Unix-like System Architecture”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.,
cpfor copy,mvfor move/rename,lsfor listing files,grepfor 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.,
/binfor essential binaries,/etcfor configuration,/homefor 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).
Accessing the System
Section titled “Accessing the System”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.
Logging In
Section titled “Logging In”Whether connecting locally via a terminal emulator or remotely via SSH, you’ll usually be prompted for your username and password:
login: your_usernamePassword:Login Steps:
Section titled “Login Steps:”- 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.10your_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 2024Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 1314 15 16 17 18 19 2021 22 23 24 25 26 2728 29 30 31
$Changing Your Password
Section titled “Changing Your Password”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.
$ passwdChanging 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.
Listing Directory Contents
Section titled “Listing Directory Contents”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 -ltotal 24drwxr-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.shdrwxrwxr-- 3 user group 4096 Jul 15 09:00 ProjectsExplanation of ls -l output columns:
- First character: File type (
dfor directory,-for regular file,lfor 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 -lhfor 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.
Who Are You?
Section titled “Who Are You?”To quickly check which user account you are currently logged in as, use the whoami command:
$ whoamiyour_username$This is useful if you manage multiple accounts or need to confirm your current user context.
Who Else is Logged In?
Section titled “Who Else is Logged In?”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 thanwho, including what command each user is currently running, system uptime, and load averages.
$ usersuser1 admin guest
$ whouser1 tty1 2024-07-29 09:15guest 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.12USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATuser1 tty1 - 09:15 1:50m 0.20s 0.10s -bashguest pts/0 192.168.1.10 10:30 5.00s 0.05s 0.01s vim config.txtadmin 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.
Logging Out
Section titled “Logging Out”When you finish your command-line session, you should log out to secure your account and free up system resources.
- Type the
logoutcommand at the prompt. - Alternatively, you can usually type
exit. - In many shells, pressing
Ctrl+Don 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).
Shutting Down or Rebooting the System
Section titled “Shutting Down or Rebooting the System”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:
| Command | Description |
|---|---|
shutdown -h now or poweroff | Initiates 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 reboot | Initiates an immediate clean shutdown and then restarts the machine. shutdown -r also allows scheduling. |
halt | Historically stopped system processes but might not power off the hardware; poweroff is generally preferred now. |
systemctl poweroff | On systems using the systemd init system (common on modern Linux), this command cleanly shuts down and powers off the system. |
systemctl reboot | On 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.