Arch Linux Cheat Sheet: Essential Commands for Beginners
Arch Linux is a powerful, lightweight Linux distribution that gives users complete control over their systems. However, it’s not the most beginner-friendly OS, and many users can feel overwhelmed when starting.
To make your Arch Linux journey smoother, here’s a cheat sheet of essential commands that will help you manage and navigate your system confidently.
1. System Basics in Arch Linux
In this section, we will cover basic commands that help you gather information about your system, check its health, and manage its power settings. These commands are essential when you’re starting with Arch Linux and need to monitor or troubleshoot your system.
Checking the System Info
When you want to know more about your Arch Linux system’s hardware and software details, the following commands come in handy:
uname -a
This command provides general information about your system, including the kernel version, system architecture, and other important data.
Linux TecMint 6.10.9-arch1-2 #1 SMP PREEMPT_DYNAMIC Tue, 10 Sep 2024 14:37:32 +0000 x86_64 GNU/Linux
The lscpu
command gives you detailed information about your system’s CPU, including the number of cores, CPU architecture, model name, clock speed, and more.
lscpu
Example Output:
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Vendor ID: GenuineIntel BIOS Vendor ID: QEMU Model name: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz BIOS Model name: pc-q35-6.2 CPU @ 2.0GHz
To displays memory usage, including RAM and swap space, in a human-readable format, use free command.
free -h
Example Output:
total used free shared buff/cache available Mem: 5.7Gi 862Mi 4.6Gi 7.4Mi 463Mi 4.8Gi Swap: 511Mi 0B 511Mi
Updating the System
Keeping your Arch Linux system up to date is crucial for security and performance. The pacman
package manager is used for installing, updating, and managing packages.
To update your entire system:
sudo pacman -Syu
The -S
stands for sync, -y
means refresh the databases, and -u
upgrades all packages that have updates available.
Shutdown, Reboot, and Log Out
These are basic power management commands that allow you to shut down, reboot, or log out from your Arch Linux system.
sudo poweroff sudo reboot logout
2. File Management in Arch Linux
File management in Linux is an essential part of everyday use, as it involves organizing, accessing, and manipulating files and directories. Arch Linux, like other Linux distributions, provides a powerful set of commands for file management that give you full control over your system’s data.
Navigating the File System
When you first start using Arch Linux, understanding how to navigate through the file system is crucial.
The cd command allows you to navigate between directories. For example, cd /home/username/Documents
will take you to the Documents folder within your home directory.
To go back to the home directory, use cd ~
.
cd /path/to/directory
The ls command lists all files and directories within the current directory. You can add options to modify the output. For instance, ls -l
provides detailed information about the files, such as permissions, ownership, and modification date, while ls -a
shows hidden files.
ls ls -l ls -la
Creating and Managing Files
In addition to navigating, you’ll frequently need to create, rename, or delete files and directories.
The touch command creates an empty file. If the file already exists, it updates the file’s timestamp.
touch filename.txt
The mkdir command creates a new directory. For example, mkdir new_folder
create a folder called new_folder
in the current directory.
mkdir new_folder
The mv command allows you to move a file to a different directory or rename a file. For example, mv oldname.txt newname.txt
renames a file. To move a file to another directory, use mv file.txt /path/to/destination/
.
mv oldname.txt newname.txt mv file.txt /path/to/destination/
The cp command copies files or directories. For example, cp file.txt /path/to/destination/
copies the file to a new location. To copy entire directories, use the -r
option (recursive copy).
cp file.txt /path/to/destination/ cp -r folder /path/to/destination/
The rm command is used to delete files. If you want to delete a directory and its contents, use rm -r
. Be careful when using this command as it permanently deletes files.
rm filename.txt rm -r foldername
Viewing Contents of Files
You will often need to view the content of files, here are a few commands to help you do that:
The cat command displays the entire content of a file on the terminal. For example, cat file.txt
will show the content of file.txt
.
cat file.txt
The less
command is useful for viewing large files, which allows you to scroll through the content one page at a time. You can exit by pressing q
.
less file.txt
The head command displays the first 10 lines of a file by default. You can specify a different number of lines using the -n
option.
head file.txt head -n 20 file.txt
The tail command shows the last 10 lines of a file by default. Use the -n
option to change the number of lines.
tail file.txt tail -n 20 file.txt
3. User Management in Arch Linux
In Arch Linux, managing users and their permissions is an important aspect of maintaining system security and organization. The following commands will help you create, manage, and interact with users on your system.
Adding and Managing Users
To add a new user to the system, you can use the useradd command, which will create the user and their home directory.
sudo useradd -m username
After creating a user, you need to set a password for them using the passwd
command.
sudo passwd username
If you want to remove a user from your system, you can use the userdel command, which will delete the user account, but it won’t remove the user’s home directory unless you specify it.
sudo userdel username
Switching Users
The su
(substitute user) command allows you to switch to a different user account. When used without any options, it switches to the root user. You can also specify the username to switch to a different account.
su - username
The -
option ensures you switch to the user’s environment (their home directory, environment variables, etc.).
Checking Logged-In Users
You can use the who command to see a list of users currently logged into the system. This command shows information such as the username, terminal, login time, and the originating IP address.
who
4. Installing and Managing Software in Arch Linux
One of the most important aspects of using any Linux distribution is installing and managing software. On Arch Linux, the primary tool for managing software packages is Pacman (the package manager), which simplifies the process of installing, updating, and removing packages.
Using Pacman: The Default Package Manager
To install a package from the official Arch repositories, use:
sudo pacman -S packagename
If you no longer need a package, you can remove it with:
sudo pacman -R packagename
To keep your system up to date, you should regularly update your packages.
sudo pacman -Syu
If you’re not sure about the exact name of a package or want to look for available software, use:
pacman -Ss keyword
To see a list of all packages currently installed on your system, run:
pacman -Q
To view detailed information about a package (such as description, size, dependencies), use.
pacman -Qi packagename
Using AUR Helpers: yay
In addition to Pacman, Arch Linux users often use an AUR helper like yay
to install packages from the Arch User Repository (AUR). The AUR is a community-driven repository that contains user-submitted packages that are not available in the official Arch repositories.
To install software from the AUR using yay, use:
yay -S packagename
To update both official repository packages and AUR packages, run.
yay -Syu
Manual Installation (Building from Source)
In some cases, you may want to build a package from a source rather than installing it from a repository. You can download the source code, compile it, and install it manually. This method is often used when a package is not available in the official repositories or AUR.
- First, download the source code.
- Then, follow the instructions in the package’s README to compile and install it.
5. Networking in Arch Linux
Networking in Linux allows your system to communicate with other devices, whether it’s for internet access or connecting to other machines on a local network. Here are some essential networking commands you’ll use in Arch Linux.
Checking Network Status
To see the current status of your network interfaces (like Ethernet or Wi-Fi), you can use the ip command:
ip addr
This shows detailed information about the network interfaces, including IP addresses assigned to them, network masks, and other networking parameters. It’s useful for checking if your network interfaces are up and running.
Pinging to Test Network Connectivity
The ping command is used to check whether your system can reach another machine or server over the network. You can ping a remote server like Google’s DNS server to check your internet connection:
ping -c 4 google.com
The -c 4
option sends 4 packets, and the command will show the response time. If you see replies, it means your network connection is working.
Managing Wi-Fi Connections
To manage Wi-Fi connections, Arch Linux uses NetworkManager (or nmcli, its command-line interface). You can connect to a Wi-Fi network with the following command:
nmcli dev wifi connect "SSID" password "your_password"
Replace “SSID
” with your Wi-Fi network name and “your_password
” with the network’s password. This command connects your system to a specific Wi-Fi network.
Viewing Network Connections
To check all active network connections (including Ethernet and Wi-Fi), you can use netstat command:
netstat -tuln
Checking Network Interfaces and Routes
The ip route
command is useful for viewing the routing table, which shows how packets are directed through the network:
ip route
This will display the default gateway and other routes your system uses to connect to networks. It’s particularly helpful for troubleshooting network issues.
6. Disk Management in Arch Linux
Disk management in Linux refers to tasks related to organizing, maintaining, and troubleshooting your hard drives, SSDs, and other storage devices. This section covers essential commands for checking disk usage, managing disk partitions, and mounting or unmounting devices.
Checking Disk Usage
The df command displays the disk space usage for all mounted file systems. The -h
flag makes the output human-readable, meaning it will show sizes in KB, MB, GB, etc.
df -h
The du command (disk usage) shows the total space used by a directory and its contents. The -s
flag provides only the total, and the -h
flag makes the output human-readable.
du -sh /path/to/directory
Mounting and Unmounting Drives
The mount
command mounts a partition (e.g., /dev/sdX1
) to a directory (e.g., /mnt
). You need to replace /dev/sdX1
with the correct device name for your system. You can find device names by using the lsblk or fdisk -l command.
sudo mount /dev/sdX1 /mnt
After you are done using the drive or partition, it’s important to unmount it properly to prevent data loss. Use the umount
command followed by the mount point or device name to unmount a device.
sudo umount /mnt
Partitioning and Formatting Disks
To list all available disks, you can use lsblk
command, which will shows all the available block devices on your system, including hard drives, SSDs, and partitions.
lsblk
Now use tools like fdisk (for MBR partitioning) or gdisk (for GPT partitioning) to create partitions:
sudo fdisk /dev/sdX
Once you’ve created a partition, you need to format it to a file system (e.g., ext4, NTFS):
sudo mkfs.ext4 /dev/sdX1
This command formats the first partition on the disk (/dev/sdX1
) with the ext4 file system. You can replace ext4 with another file system type (e.g., ntfs, btrfs) if necessary.
Checking Disk Health
It’s important to regularly check the health of your disks to avoid data loss. You can use tools like smartctl to check the status of your hard drives or SSDs.
sudo smartctl -a /dev/sdX
This command retrieves detailed information about the disk’s health and performance, including temperature, wear level, and error rates.
Creating and Managing Swap Space
To create a swap file, you can use the following commands, which will create a swap file of 1GB (count=1024), set the correct permissions, format it as swap space, and enable it.
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile
Add the swap file to /etc/fstab
so that it’s mounted automatically at boot:
sudo nano /etc/fstab
Add this line to the end of the file:
/swapfile none swap sw 0 0
Removing Partitions or Disks
If you no longer need a disk or partition, you can delete it using the following command, which will ask you to type d
to delete a partition and follow the on-screen instructions.
sudo fdisk /dev/sdX
If you created a swap file and no longer need it:
sudo swapoff /swapfile sudo rm /swapfile
7. Process Management in Arch Linux
In any operating system, processes are the programs or tasks that are running on your computer. Managing these processes is essential for ensuring that your system runs smoothly and efficiently.
Viewing Running Processes
The ps command displays a snapshot of all running processes on your system, including their process ID (PID), the user running them, CPU and memory usage, and the command that started each process.
ps aux
The top command provides a dynamic, real-time view of the processes currently running. It updates every few seconds, showing the most CPU-intensive processes at the top. You can interact with top to sort processes, change the display, or kill processes directly.
top
The htop is a more advanced and user-friendly version of top, which provides a colorful, interactive display and allows you to easily sort processes by CPU, memory, or other criteria.
If htop is not installed, you can install it using the following command:
sudo pacman -S htop
Once installed, you can run:
htop
Killing Processes
To stop a process, you need to know its Process ID (PID). Once you have the PID (which you can get using ps aux
or top
), you can kill it using:
kill PID
If a process doesn’t respond to the kill command, you can use the -9
option to forcefully terminate it. This sends a signal to the process, forcing it to stop immediately.
kill -9 PID
If you want to find the PID of a specific process by name, you can use pgrep
:
pgrep processname
You can adjust the priority of a running process to control how much CPU time it gets. The nice
command allows you to launch a process with a specific priority (lower values get more CPU time), while renice
allows you to change the priority of an already running process.
nice -n 10 command sudo renice -n 10 -p PID
8. Permissions and Ownership in Arch Linux
In Linux, file permissions and ownership are essential for controlling who can access and modify files and directories. These settings help maintain system security and ensure that only authorized users can perform specific actions on files.
File Permissions
Permissions define what actions a user or group can perform on a file or directory and there are three basic types of permissions:
Read (r)
– Allows the user to view the content of the file.Write (w)
– Allows the user to modify or delete the file.Execute (x)
– Allows the user to run the file if it is a program or script.
These permissions are set for three categories:
- Owner (user) – The person who created the file.
- Group – A group of users who have similar permissions for the file.
- Others – All users who are not the owner or part of the group.
Permissions are displayed in the form of a 10-character string, such as -rwxr-xr--
. and here’s a breakdown:
- The first character represents the file type (e.g.,
-
for a regular file,d
for a directory). - The next three characters represent the owner’s permissions.
- The next three characters represent the group’s permissions.
- The final three characters represent the permissions for others.
Changing File Permissions with chmod
To change the permissions of a file, the chmod
command is used. You can specify the permissions numerically or symbolically.
Numeric Mode: The permissions are represented by numbers:
r = 4 w = 2 x = 1
For example, to give the owner read and write permissions (6), and the group and others read-only permissions (4), you would use:
chmod 644 filename
Symbolic Mode: This allows you to modify permissions using letters:
+
to add permissions.-
to remove permissions.=
to set permissions exactly.
For example, to add execute permission to the owner of the file:
chmod u+x filename
Changing Ownership with chown
The chown command is used to change the ownership of a file or directory.
The syntax is:
sudo chown username:groupname filename
For example, to change the owner of a file to john
and the group to admin
:
sudo chown john:admin filename
You can also change the ownership of a directory and all its contents recursively:
sudo chown -R john:admin directory_name
Changing Group Ownership with chgrp
To change only the group ownership of a file, you can use the chgrp
command:
sudo chgrp groupname filename
9. System Logs and Monitoring
System logs and monitoring are crucial for tracking the health and performance of your Arch Linux system. They help you identify errors, performance bottlenecks, and unusual activity, allowing you to troubleshoot and maintain a stable system.
Viewing Logs
The journalctl is the primary tool for viewing logs on Arch Linux, which provides access to all system logs managed by systemd, including boot logs, system logs, and logs from various services.
journalctl
By default, this command shows logs from the current boot session, but you can use filters to view logs from specific services or time periods.
journalctl -u servicename
View logs from a specific time.
journalctl --since "2024-12-01" --until "2024-12-02"
This will display logs from December 1st to 2nd.
10. Troubleshooting Arch Linux
Troubleshooting is an essential skill for any Linux user, especially when using Arch Linux, which is a rolling release distribution that may occasionally experience issues due to updates or package conflicts.
Rescue Mode
If your system isn’t booting correctly, you can enter rescue mode to troubleshoot and fix issues. Rescue mode provides a shell environment with minimal services running, allowing you to fix problems such as missing files, misconfigured settings, or broken packages.
systemctl rescue
Fixing Broken Packages
Over time, the package cache can grow large and may cause conflicts or issues with installing updates. To clean the package cache, you can run:
sudo pacman -Sc
If a specific package is causing problems, you can reinstall it to fix any corruption or missing files:
sudo pacman -S packagename
Viewing Logs
To view system logs, you can use journalctl command, which will displays the system logs from the journal, including all services and kernel messages. You can scroll through this to find errors or warnings related to your issue.
journalctl
To view logs for a specific service:
journalctl -u servicename
Repairing the Filesystem
To check and repair your filesystem, use the fsck command:
sudo fsck /dev/sdX
Replace /dev/sdX
with the correct device name for your root or affected partition. This will scan and repair any filesystem errors.
Package Dependency Issues
Sometimes, Arch users encounter issues with package dependencies, especially when installing or updating packages.
In these cases, you can use the following command to fix dependencies.
sudo pacman -Syyu
Force reinstall dependencies.
sudo pacman -S $(pacman -Qdtq)
This command reinstalls any orphaned or broken dependencies that might be causing issues.
11. Advanced Tips for Beginners
As a beginner on Arch Linux, you may not yet be familiar with all the powerful features the system has to offer. While it’s important to start with the basics, here are some advanced tips that will help you boost your efficiency, personalize your experience, and make your system more robust as you gain confidence with Arch Linux.
Using Aliases for Convenience
Aliases allow you to create shortcuts for long or frequently used commands, which can save you a lot of time. For example, instead of typing ls -la
every time you want to list files in long format, you can create a simple alias.
You can add these aliases to your .bashrc file, which is executed each time you start a new terminal session.
nano ~/.bashrc
Add an alias, like this:
alias ll="ls -la"
After saving the file, reload it.
source ~/.bashrc
Backup and Restore with Tar
Arch Linux allows you to handle file backups easily using the tar command. Whether you want to back up a configuration file, a directory, or even your entire home directory, tar is a simple yet powerful tool for creating compressed archives.
To back up a directory, use:
tar -cvzf backup.tar.gz /path/to/directory
To restore the backup:
tar -xvzf backup.tar.gz
Learning More Through Man Pages
As you get comfortable with Arch Linux, you’ll want to learn more about the commands you use. The manual (man) pages are a great way to dive deeper into any command and explore its full functionality.
For example, if you want to learn more about pacman, the Arch Linux package manager, you can type:
man pacman
This will show you the detailed documentation for pacman, including all available options and usage examples. Man pages are available for almost all commands and programs in Linux, making them an invaluable resource.
Conclusion
Arch Linux may seem challenging initially, but mastering these essential commands will make your experience more enjoyable and productive. Keep this cheat sheet handy, and remember to explore further by reading official Arch Linux documentation or joining forums like the Arch Wiki.