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 Monaco
Adds line numbers to beginning of each line.
cat foobar.txt | nl
Lists processes by their energy consume.
Approve all confirmations
yes | pacman -S yolo
Checks 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 | less
yes | pacman -S yolo
List network interfaces in the system:
ip link show
Manage 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-z
Select particular columns and print out;
lsblk | awk '{print $1,$4}'
# sda 8GB
Returns file info. It's especially useful on images;
file logo.png
# PNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced
Get 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 ls
List available sessions
On session:
C-z $
Rename sessionC-z d
Detach session
Windows
S-[left]
Select the next windowS-[right]
Select the previous windowC-[left]
Move window to leftC-[right]
Move window to rightC-z c
Open new windowC-z x
Close current windowC-z C-z
Open last windowC-z :swap-window -t -1
Move current window to leftC-z ,
Rename windowC-z n
Next windowC-z p
Previous window
Status Bar
C-z b
Toggle status bar
Other
C-z :source-file ~/.tmux.conf
Reload config
Interactive process viewer. Useful keybindings:
/
Search\
Filter,
Choose the sorting criteriak
Send kill signal to selected processu
Filter results by usert
Open/close tree mode-
or+
Collapse/uncollapse process treesH
Turn 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.service
Some 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-reload
Toggle 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=failed
See logs of a specific unit;
sudo journalctl -xu [email protected] --since today
Analysize the boot time:
$ systemd-analyze
List the started unit files, sorted by the time each of them took to start up:
$ systemd-analyze blame
See boot units as chain:
$ systemd-analyze critical-chain
It'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/sdXY
Get UUID of the partition:
$ sudo blkid /dev/sdXY
And add following line into /etc/fstab
UUID=? none swap sw 0 0
List swap devices and their sizes:
$ swapon -s
See which swap devices are being used:
$ cat /proc/swaps
See 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/swappiness
To temporarily set the swappiness value:
$ sysctl vm.swappiness=10
To 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 --recompile
to check errors, thenmod+r
to 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 && sync
In OSX:
sudo dd if=path/to/arch.iso of=/dev/rdiskX bs=1m
After booting the USB, follow these steps;
- Create Partitions
- Make sure boot (/mnt/boot) & root (/mnt) mounted.
- Run
pacstrap
to 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.conf
echo "FONT=Lat2-Terminus16" >> /etc/vconsole.conf
- Create users
- Done
- Command-line tools: parted, fdisk, cfdisk (with UI)
- List disks and partitions by
fdisk -l
orlsblk
- 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:
timedatectl
List all regions:
find /usr/share/zoneinfo/. -maxdepth 1 -type d | cut -d "/" -f6 | sed '/^$/d'
Or, select your timezone interactively:
tzselect
Then set your timezone:
timedatectl set-timezone Asia/Makassar
Print 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/chroot
mknod /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>