Common Tasks - marco1475/linux-htpc GitHub Wiki

Scrolling Through Console Output

Shift + PgUp or PgDn will scroll through the console log.

User Permissions

Read    4
Write   2
Execute 1
  • The ls command lists 7 metadata fields:

      <info> <hardlinks> <owner> <group> <size> <modified> <name>
    
    • info includes the file type (- for normal file, d for directory, p for named pipe, and l for symbolic link), and permission triples for owner, group, and others.

Installing a Package

pacman -S <package_name>

Uninstalling a Package

pacman -Rs <package_name>

Updating the System

pacman -Syu
pacdiff
  • You will need to install the pacman-contrib package to get pacdiff.
  • If the kernel gets updated, don't forget to restart, otherwise you'll get weird errors.

vimdiff Commands

Action Shortcut
next change ]c
previous change [c
diff obtain do
diff put dp
fold open zo
fold close zc
rescan files :diffupdate
switch window Ctrl-W + Ctrl-W
  • diff obtain and diff put are relative to the current split window, i.e. obtain copies from the other window to the current window and put copies from the current window to the other window.

Determining the Size on Disk

  • List of file and directory sizes in human-readable format:

      du -ah <directory>
    
  • Total size of a directory:

      du -sh <directory>
    

systemd Services

  • Start and stop:

      systemctl start <service_name>.service
      systemctl stop <service_name>.service
    
  • Add and remove from boot sequence:

      systemctl enable <service_name>.service
      systemctl disable <service_name>.service
    
  • Reload changed configuration files:

      systemctl daemon-reload
    
  • See log of a given service:

      journalctl -u service-name.service -b
    
    • -b limits the log to the current boot session.

Adding User to a New Group

usermod -aG <group> <user>

Adding a New Group

groupadd <group>

Determining the Kernel Version

uname -r

Determining if a Kernel Module is Loaded

lsmod | grep <module_name>

Writing vs. Appending to a File

  • > writes to (i.e. overwrites) a file
  • >> appends to a file

Connecting Using SSH

ssh -p port user@server-address

Copying using SCP

scp -P port <local/file> [email protected]:/remote/file

Connecting to an IRC channel using irssi:

/connect chat.freenode.net
/msg NickServ idenfity marco1475 \<password\>
/join #archlinux

Sourcing ~/.bashrc fron an interactive console

  • Non-interactive consoles (most Linux-ones) source ~/.bashrc.

  • Interactive consoles (e.g. macOS' Terminal) source ~/.bash_profile.

  • To solve this problem make ~/.bash_profile source ~/.bashrc:

      if [ -f ~/.bashrc ]; then
          . ~/.bashrc;
      fi
    

Securely wiping a disk

dd if=/dev/urandom of=/dev/sdX bs=512
  • Find out the bs value by running fdisk -l /dev/sdX and look for the "physical sector size".

  • To check on the progress of dd, run the following command in a separate terminal:

      kill -USR1 $(pgrep dd)
    

Fixing RAID Array Errors

  • If /sys/block/md0/md/mismatch_cnt contains anything other than 0 you need to repair your RAID array.

  • Instead of setting /sys/block/md0/md/sync_action to check, set it to repair:

      echo repair > /sys/block/md0/md/sync_action
    
    • You will have to do this as root, just sudo won't do.
    • You can monitor the repair (or check) progress by using cat /proc/mdstat.

Getting the Unique Identifiers

  • UUIDs:

      lsblk -no name,uuid
      ls -l /dev/disk/by-uuid/
    
  • PARTUUIDs:

      lsblk -no name,partuuid
      ls -l /dev/disk/by-partuuid/
    

Opening and Closing an Encrypted Partition (with LUKS)

cryptsetup open --type luks /dev/sdaX <dev-mapper-name>
cryptsetup close <dev-mapper-name>
  • The partition appears under /dev/mapper/<dev-mapper-name>

Updating systemd-boot

  • systemd-boot assumes the EFI System Partition is mounted on /boot, which is not true in our case (it's on /esp and /boot is mount-bound to /boot).

  • You have to pass --path to the update call:

      bootctl --path=/esp update
    

Reading Boot Messages

  • The logs can be accessed through:

      journalctl -b
    
  • Boot messages are cleared because:

    1. The kernel parameters at boot have the quiet flag set.
      • To fix this, remove the quiet flag from /esp/loader/entries/arch.conf's options line.
    2. Late KMS boot messages override the previous output.
      • There is no way to fix this.
    3. getty@tty1 service does not pass the --noclear flag to agetty.
      • Arch sets this flag by default.
    4. systemd clears the screen before showing the login prompt.
      • To fix this, create /etc/systemd/system/[email protected]/noclear.conf to override only TTYVTDisallocate for agetty on TTY1 and leave the global service file /usr/lib/systemd/system/[email protected] untouched.

          [Service]
          TTYVTDisallocate=no
        

Installing AUR Packages

  1. Create a directory for the AUR build and change directories:

     mkdir ~/aur && cd ~/aur
    
  2. Download the PKGBUILD tarball from the Arch User Repository:

     wget <url>
    
  3. Extract the tarball to the AUR build directory created in step 1:

     tar -xvf <package_name>.tar.gz
    
  4. Change directory to the extracted package, verify the PKGBUILD and all .install files for malicious code, and build the package:

     cd <package_name>
     makepkg -sri    # Run this as normal user, not root!
    
⚠️ **GitHub.com Fallback** ⚠️