DEV Community

Trix Cyrus
Trix Cyrus

Posted on

Essential Arch Linux Commands: Advanced Mastery(Part-2)[Must Read]

Author: Trix Cyrus

[Try My], Waymap Pentesting tool: Click Here
[Follow] TrixSec Github: Click Here
[Join] TrixSec Telegram: Click Here



In Part 1, we covered the basics of Arch Linux commands, focusing on pacman, system management, and AUR tools. In this follow-up, we’ll explore more advanced commands and techniques to help you master Arch Linux like a pro.


1. Pacman Power Features

Arch’s package manager, pacman, has some powerful but lesser-known features that can save you time and effort.

1.1 Backup and Restore Packages

  • Backup installed packages: Save a list of currently installed packages for reinstallation later:
  pacman -Qqen > pkglist.txt
Enter fullscreen mode Exit fullscreen mode
  • Restore packages: Use the backup list to reinstall packages on a fresh system:
  sudo pacman -S $(<pkglist.txt)
Enter fullscreen mode Exit fullscreen mode

1.2 Downgrade a Package

Sometimes an update can break functionality. Downgrade a package by specifying a version:

sudo pacman -U /var/cache/pacman/pkg/package_name-version.pkg.tar.zst
Enter fullscreen mode Exit fullscreen mode

1.3 View Detailed Package Information

Get detailed information about a package (dependencies, conflicts, etc.):

pacman -Qi package_name
Enter fullscreen mode Exit fullscreen mode

1.4 List Orphans

List packages installed as dependencies but no longer required:

sudo pacman -Qdt
Enter fullscreen mode Exit fullscreen mode

1.5 Remove Orphans

Clear out unnecessary packages:

sudo pacman -Rns $(pacman -Qdtq)
Enter fullscreen mode Exit fullscreen mode

2. System Maintenance Commands

Keeping your Arch Linux system clean and optimized requires regular maintenance.

2.1 Cleaning the Package Cache

The package cache can grow over time. Clear old or unused packages to free up space:

  • Remove all old versions except the latest two:
  sudo paccache -r
Enter fullscreen mode Exit fullscreen mode
  • Clear the entire cache:
  sudo pacman -Scc
Enter fullscreen mode Exit fullscreen mode

2.2 Kernel Management

Arch Linux often keeps multiple kernel versions for safety. To manage them:

  • List installed kernels:
  pacman -Q | grep linux
Enter fullscreen mode Exit fullscreen mode
  • Remove an old kernel:
  sudo pacman -R linux-old-kernel-name
Enter fullscreen mode Exit fullscreen mode

2.3 Check for Outdated Configurations

Use the find command to locate old configuration files:

find /etc -name "*.pacnew" -or -name "*.pacsave"
Enter fullscreen mode Exit fullscreen mode

Merge or remove them as needed.


3. User Management

Arch Linux provides fine-grained control over user accounts.

3.1 Add a New User

Create a new user and assign them a home directory:

sudo useradd -m -G wheel username
Enter fullscreen mode Exit fullscreen mode

3.2 Set User Password

sudo passwd username
Enter fullscreen mode Exit fullscreen mode

3.3 Grant Sudo Privileges

Edit the sudoers file to give the new user administrative rights:

sudo visudo
Enter fullscreen mode Exit fullscreen mode

Uncomment the line:

%wheel ALL=(ALL:ALL) ALL
Enter fullscreen mode Exit fullscreen mode

3.4 Delete a User

Remove a user and their home directory:

sudo userdel -r username
Enter fullscreen mode Exit fullscreen mode

4. Disk and Filesystem Management

Mastering disk management is crucial for efficient Arch Linux use.

4.1 View Disk Partitions

Use lsblk or fdisk to check your partitions:

lsblk
Enter fullscreen mode Exit fullscreen mode

4.2 Resize a Partition

Unmount the partition before resizing:

sudo umount /dev/sdX1
sudo resize2fs /dev/sdX1
Enter fullscreen mode Exit fullscreen mode

4.3 Mount Partitions Automatically

Edit the fstab file to mount partitions at boot:

sudo nano /etc/fstab
Enter fullscreen mode Exit fullscreen mode

Add a line like:

/dev/sda1 /mnt/data ext4 defaults 0 2
Enter fullscreen mode Exit fullscreen mode

5. Networking Commands

Managing networks effectively is essential for system administration.

5.1 Check Network Status

View active network interfaces and IP addresses:

ip a
Enter fullscreen mode Exit fullscreen mode

5.2 Connect to Wi-Fi

For command-line Wi-Fi management, use iwctl (if using iwd):

sudo iwctl
# Then inside iwctl
station wlan0 connect SSID
Enter fullscreen mode Exit fullscreen mode

5.3 Test Network Connectivity

  • Ping a website:
  ping -c 4 google.com
Enter fullscreen mode Exit fullscreen mode
  • Trace the network route:
  traceroute google.com
Enter fullscreen mode Exit fullscreen mode

6. Advanced File Operations

6.1 Recursive File Searches

Find files by name:

find /path/to/search -name "filename"
Enter fullscreen mode Exit fullscreen mode

6.2 Archiving and Compression

  • Create a compressed archive:
  tar -czvf archive.tar.gz /path/to/directory
Enter fullscreen mode Exit fullscreen mode
  • Extract an archive:
  tar -xzvf archive.tar.gz
Enter fullscreen mode Exit fullscreen mode

6.3 File Permissions

  • Change ownership:
  sudo chown user:group file
Enter fullscreen mode Exit fullscreen mode
  • Change permissions:
  chmod 755 file
Enter fullscreen mode Exit fullscreen mode

7. Performance Monitoring

Keep your system running smoothly by monitoring its performance.

7.1 View Resource Usage

  • Top processes:
  htop
Enter fullscreen mode Exit fullscreen mode
  • CPU usage:
  mpstat
Enter fullscreen mode Exit fullscreen mode
  • Disk I/O:
  iostat
Enter fullscreen mode Exit fullscreen mode

7.2 Monitor Logs

Check system logs for troubleshooting:

sudo journalctl -xe
Enter fullscreen mode Exit fullscreen mode

8. System Recovery Commands

8.1 Boot Repair

Use chroot from a live USB to fix boot issues:

mount /dev/sda1 /mnt
arch-chroot /mnt
Enter fullscreen mode Exit fullscreen mode

8.2 Restore Pacman Keys

If your keyring is corrupted:

sudo pacman-key --init
sudo pacman-key --populate archlinux
Enter fullscreen mode Exit fullscreen mode

8.3 Recover Lost GRUB

Reinstall GRUB if it’s missing:

grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
Enter fullscreen mode Exit fullscreen mode

Conclusion

These advanced commands and techniques give you the tools to manage, maintain, and troubleshoot your Arch Linux system with confidence. Mastery comes with practice, so don’t hesitate to experiment and explore. Remember, the Arch Wiki is your ultimate companion for all things Arch Linux.

What other commands do you use on Arch Linux? Share your tips in the comments below!


~Trixsec

Top comments (0)