List of Contents:
- Useful Commands
- Useful Networking Commands
- Improve Performance
- Mount Swap Partition
- Arch Linux Installation
- Building Custom Arch ISO
- How to submit a package to AUR?
- Irssi
- Xmonad
Opens a new TTY on given root directory.
You can create UI dialogs with it on command-line easily. For example;
usernameDialog () {
username=$(dialog --stdout \
--title "Creating Users" \
--backtitle "Happy Hacking Linux" \
--ok-label "Done" \
--nocancel \
--inputbox "Choose your username" 8 50)
}Lists fonts available in the system.
fc-list | grep MonacoAdds line numbers to beginning of each line.
cat foobar.txt | nlLists processes by their energy consume.
Approve all confirmations
yes | pacman -S yoloChecks size of a folder.
du -sh /Disk usage analyzer with CLI UI with ncurses.
Data extraction tool for ALPM (Arch Linux Package Management).
To list packages by their size;
expac "%n %m" -l'\n' -Q $(pacman -Qq) | sort -rhk 2 | lessyes | pacman -S yolo
List network interfaces in the system:
ip link showManage routing tables:
ip r
Kill a process partially matching given pattern;
pkill -f pattern
Uncomment matching line:
sed -i -e '/^#en_US/s/^#//' /etc/locale.Slugify a string:
sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-zSelect particular columns and print out;
lsblk | awk '{print $1,$4}'
# sda 8GBReturns file info. It's especially useful on images;
file logo.png
# PNG image data, 16 x 16, 8-bit/color RGBA, non-interlacedGet unix timestamp:
date +%s
Get date & time nicely formatted;
date '+%d %h %H:%M'
# 22 Jun 01:42
On command-line:
tmux a -t [name]Open a sessiontmux lsList available sessions
On session:
C-z $Rename sessionC-z dDetach session
Windows
S-[left]Select the next windowS-[right]Select the previous windowC-[left]Move window to leftC-[right]Move window to rightC-z cOpen new windowC-z xClose current windowC-z C-zOpen last windowC-z :swap-window -t -1Move current window to leftC-z ,Rename windowC-z nNext windowC-z pPrevious window
Status Bar
C-z bToggle status bar
Other
C-z :source-file ~/.tmux.confReload config
Interactive process viewer. Useful keybindings:
/Search\Filter,Choose the sorting criteriakSend kill signal to selected processuFilter results by usertOpen/close tree mode-or+Collapse/uncollapse process treesHTurn off displaying threads
Sorts processes by disk writes, and show how much and how frequently programs are writing to the disk.
htop for network. lists processes by their network traffic.
Use systemctl command to control the services. Example;
systemctl restart slim.serviceSome useful systemctl commands:
- start
- stop
- restart
- reload
- status
- is-enabled
- enable
- disable
- mask
- unmask
- list-units
Restart systemd scanning for new or changed units;
systemctl daemon-reloadToggle a service with one-liner:
if [[ "`systemctl is-active NetworkManager`" != "active" ]]; then sudo systemctl start NetworkManager; else sudo systemctl stop NetworkManager; fi
See which units are failing;
systemctl list-units --state=failedSee logs of a specific unit;
sudo journalctl -xu dhcpcd@enp0s3.service --since todayAnalysize the boot time:
$ systemd-analyzeList the started unit files, sorted by the time each of them took to start up:
$ systemd-analyze blameSee boot units as chain:
$ systemd-analyze critical-chainIt's used for splitting the output of a program so we can both display it and also save it.
For example, add a new entry to hosts file;
echo "127.0.0.1 foobar" | sudo tee -a /etc/hosts
List files by extension;
find . -type f -name *.strings
Using -or:
find . -type f \( -name "*.strings" -or -name "*.txt" \)
Executing a command per file;
find . -type f -name *.strings -exec sed -i '' -e "s/foo/bar/" {} \;
Lists contents of a directory in tree-like format.
tree
Show hidden files:
tree -a
Show only directories:
tree -d
Creates a window and lets you see the keyboard events. Useful when you modify keybindings.
Sets the keyboard layout:
setxkbmap tr -variant alt -option lv3:ralt
Find process id of a running program:
pidof nginx
It might return multiple pids (e.g nginx have worker processes). Specify -s parameter to get only one pid:
pidof -s nginx
route | grep '^default' | grep -o '[^ ]*$'ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'cat /sys/class/net/eth0/statistics/rx_bytes
cat /sys/class/net/eth0/statistics/rx_packets
cat /sys/class/net/eth0/statistics/tx_packets
cat /sys/class/net/eth0/statistics/tx_bytes
ping -q -w 1 -c 1 $gateway> /dev/null && echo 1 || echo 0
ip r | grep default | cut -d ' ' -f 3
Create a Swap partition using partitioning tools like cfdisk or parted. Then format the partition as swap;
$ mkswap /dev/sdXY
Enable it;
$ swapon /dev/sdXYGet UUID of the partition:
$ sudo blkid /dev/sdXYAnd add following line into /etc/fstab
UUID=? none swap sw 0 0
List swap devices and their sizes:
$ swapon -sSee which swap devices are being used:
$ cat /proc/swapsSee total, used and free swap space:
$ cat /proc/meminfo | grep Swap
Or:
$ cat /proc/swaps
The swappiness sysctl parameter represents the kernel's preference (or avoidance) of swap space. Swappiness can have a value between 0 and 100, the default value is 60. A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. Using a low value on sufficient memory is known to improve responsiveness on many systems. To check the current swappiness value:
$ cat /proc/sys/vm/swappinessTo temporarily set the swappiness value:
$ sysctl vm.swappiness=10To set the swappiness value permanently, edit a sysctl configuration file:
echo "vm.swappiness=10" > /etc/sysctl.d/99-sysctl.conf- Auto-connect to a network:
/server ADD -auto -network NetworkName irc.host.com 6667 - Auto-join to channels:
/channel ADD -auto #channel NetworkName password - Switch to a window:
M-[number]use letters when for windows beyond 9:M-[q|w|e|r|t|y] - Close window:
/wc - Save config:
/save - Load a script:
/script load awm - Set theme:
/set theme weed
- After making a change hit
xmonad --recompileto check errors, thenmod+rto reload the config.
Download ISO and create a bootable USB stick;
In Linux:
dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress && syncIn OSX:
sudo dd if=path/to/arch.iso of=/dev/rdiskX bs=1mAfter booting the USB, follow these steps;
- Create Partitions
- Make sure boot (/mnt/boot) & root (/mnt) mounted.
- Run
pacstrapto install the base:pacstrap /mnt - Update FS Tab:
genfstab -U /mnt >> /mnt/etc/fstab - Switch to the new root:
arch-chroot /mnt - Install GRUB
- Localize:
- Select timezone
- Generate /etc/adjtime:
hwclock --systohc - Uncomment en_US lines in /etc/locale.gen:
sed -i -e '/^#en_US/s/^#//' /etc/locale.gen - Generate locales with
locale-gen echo "LANG=en_US.UTF-8" >> /etc/locale.confecho "FONT=Lat2-Terminus16" >> /etc/vconsole.conf
- Create users
- Done
- Command-line tools: parted, fdisk, cfdisk (with UI)
- List disks and partitions by
fdisk -lorlsblk - The simple and popular layout is boot & root;
parted /dev/sda --script mklabel msdos \
mkpart primary ext4 1MiB 512MiB \
set 1 boot on \
mkpart primary ext4 512MiB 100%- Don't forget formatting them as ext4:
yes | mkfs.ext4 /dev/sda1
This bash function I wrote for happy-hacker-linux installer shows the steps of creating a user.
createUser () {
useradd -m -s /usr/bin/zsh $1
echo "$1:$2" | chpasswd
echo "$1 ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo $1 > /etc/hostname
echo "127.0.1.1 $1.localdomain $1" >> /etc/hosts
}View your time info:
timedatectlList all regions:
find /usr/share/zoneinfo/. -maxdepth 1 -type d | cut -d "/" -f6 | sed '/^$/d'Or, select your timezone interactively:
tzselectThen set your timezone:
timedatectl set-timezone Asia/MakassarPrint current date formatted:
date '+%d %h %H:%M'
Set current date:
date --set="23 June 1988 10:00:00"
Or time:
date --set="10:00:00"
$ pacman -S devtools git make --needed
$ mkarchroot /tmp/chroot base
$ git clone git://projects.archlinux.org/archiso.git
$ make -C archiso/archiso DESTDIR=/tmp/chroot install
$ arch-chroot /tmp/chrootmknod /dev/loop0 b 7 0
echo 'Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/x86_64' >> /etc/pacman.d/mirrorlist
pacman -S devtools libisoburn squashfs-tools
And install necessary packages.
cp -r /usr/share/archiso/configs/baseline /tmp
cd /tmp/baseline
./build.sh
exit
Now, you will be out of your chroot, with the built ISO at the file path of:
/tmp/chroot/tmp/baseline/out/<iso>