This is my notebook for some small tips and tricks when using Arch Linux.
Why Arch Linux?
It is fresh and simple in package dependency.
It has a powerful Arch User Repository and makes it easy for you to make/modify your package.
It has a detailed Arch Wiki comprising useful experiences and recommendations.
It gets you to learn the basic knowledge required to be a Linux user/administrator/programmer.
Refer to manual
Use man [SECTION] <NAME>
to show a manual.
Use whatis <NAME>
to find out which sections are available in manual.
Use apropos <KEYWORD>
to search for manuals whose name or description contains certain keyword.
Use man man-pages
to see the definition of each seciton.
Use help -m <BUILTIN>
to show help for a shell builtin in manual page format.
The “SEE ALSO” section in a manual sometimes can be very helpful.
You can also use man hier
to get to know the Linux filesystem hierarchy.
Find available commands
Shell builtin compgen
can list possible completions for your input.
NTFS partitions auto mounting
Use
gnome-disks
, select partition and click the settings button below, click and then modify mount options in the popup menu.Install
ntfs-config
and enable auto mounting.
Disable Nvidia graphics
Install bbswitch
.
And create /etc/modprobe.d/nouveau_blacklist.conf
as follow, or else bbswitch
will find Nvidia graphics in use by nouveau
.
1 | blacklist nouveau |
You can verify bbswitch
status by cat /proc/acpi/bbswitch
and view its log by dmesg | grep bbswitch
.
Note that the nouveau
kernel module is shipped in linux
. And once in a specific packaging of linux
, nvidiafb
is also shipped and need to be blacklisted.
Also note that if your install bumblebee
, it will ship the blacklist file for you.
Hardware video acceleration
See Arch Wiki.
If mkv
playback doesn’t work well in VLC, remove libvdpau-va-gl
.
Shrink pacman cache
From Arch Wiki:
paccache -r
deletes all the cached versions of each package except for the most recent 3 (without confirmation).
paccache -ruk0
removes all the cached versions of uninstalled packages.
See paccache -h
for dry run and other parameters.
Better diff
alias diff='git diff --no-index'
works great with the only requirement of git
.
Make programs use proxy
There are several ways to make a program proxied. Part of the following comes from Arch Wiki.
Environment variables
Some programs respect proxy set via environment variables.
1
2
3
4
5export http_proxy=http://10.203.0.1:5187/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"It is sometimes advised that you export these environment variables again, with their names upper cased.
Proxychains
Install proxychains-ng. Proxychains hooks some C library functions so that programs gets proxied. However the Java VM cannot be proxied this way.
1
proxychains <YOUR_PROGRAM>
Java
From the documentation of Java:
HTTP
http.proxyHost: the host name of the proxy server
http.proxyPort: the port number, the default value being 80.
http.nonProxyHosts: a list of hosts that should be reached directly, bypassing the proxy. This is a list of patterns separated by ‘|’. The patterns may start or end with a ‘*’ for wildcards. Any host matching one of these patterns will be reached through a direct connection instead of through a proxy.
HTTPS
- https.proxyHost
https.proxyPort
FTP
ftp.proxyHost (Typo in official documentation)
ftp.proxyPort
ftp.nonProxyHosts
SOCKS
socksProxyHost for the host name of the SOCKS proxy server
socksProxyPort for the port number, the default value being 1080
socksProxyVersion for the version of the SOCKS protocol, the default being 5, and alternatively 4 can be specified.
Note: socksProxyVersion and more properties are documented at another documentation of Java.
Sample usage:
1
java -Dhttp.proxyHost=webcache.example.com -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts='localhost|host.example.com'
Or you can utilize
_JAVA_OPTIONS
:1
export _JAVA_OPTIONS="-DsocksProxyHost=localhost -DsocksProxyPort=10801"
Note that you can tunnel http(s) request to local socks client using Polipo, for example polipo socksParentProxy=localhost:10800
.
Touchpad settings and horizontal two-finger scrolling doesn’t work
GNOME dropped support for synaptics driver due to luck of maintenance in version 3.20.
Remove xf86-input-synaptics
and xf86-input-evdev
, install xf86-input-libinput
, then reboot.
GNOME proxy setting
You can utilize GNOME’s proxy setting in “Settings > Network” even if you use (Disabled in recent GNOME, see below). Both HTTP and SOCKS proxy are supported.netctl
instead of NetworkManager
You can also modify proxy setting with dconf-editor
, Set system.proxy.mode
to manual
, then set your proxy in system.proxy.{ftp,http,https,socks}
.
Note that the proxy setting will also be read and set to corresponding environment variables by gnome-terminal
, and no option is offered to turn this behavior off. To avoid setting proxy environment variables, reset the environment variables in your .bashrc
.
1 | # Unset global proxy set by gnome-terminal |
GNOME online account
You can log in your Google account and all the things will be configured and synchronized automatically to your laptop. It can be a huge boost for your work flow.
If you need a proxy to access Google, configure it as in the GNOME proxy setting section.
Save ssh key passphrase to keyring
As in Arch Wiki, use /usr/lib/seahorse/ssh-askpass
.
As of gnome-keyring
46.1-1, SSH_AUTH_SOCK
is not exported by default anymore, so you will need to add the following lines to your .bashrc
.
1 | export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/gcr/ssh" |
Nautilus hangs occasionally
In my case it often happened when I started to search something. Turned out that it is caused by my putting too many files under indexed directories.
To fix the hang up, launch tracker-preferences
, go to “Locations” tab, and turn off “Recurse” for directories you may store a large amount of files. Then execute tracker reset --hard
to reset tracker index and configurations. This resolved my issue so far.
DNS and resolvconf
DNS is managed by resolvconf
in Arch Linux. In order to supply your own DNS, edit /etc/resolvconf.conf
.
There are two options you may normally want to specify:
1 | name_servers=<DNS1> #Prepended into DNS list |
After modification, you may want to execute resolvconf -u
to update resolv.conf
.
Note that dhcpd
also setup DNS for interfaces via resolvconf
, in /run/resolvconf/interface/<INTERFACE>
. You can override its behavior by executing dhcpcd -S domain_name_servers=<DNS>
, or inside dhcpcd.conf
.
Create software AP (Access Point), a.k.a. virtual WiFi
Install AUR package create_ap
; you may want to remove the wifi.service
it automatically creates when installed and use your own.
Check the Capabilities section in iw list
along with /usr/share/doc/hostapd/hostapd.conf
to determine ht_capab
.
Note that in ZJU, ZJUWLAN occupies channel 1 and 6, so you’d better specify another channel.
Sample systemd service:
File: <YOUR_SSID>@.service
1 | [Unit] |
However on my own machine, I cannot share a secure (with password) network.
Analyze network issue
Use mtr
(My traceroute), a tool combining much of the functionality of ping and traceroute into one interface.
See who’s using a file, filesystem or port
Use fuser
, with fuser -v <FILE>
for a file, fuser -vm <FILE>
for filesystem of that file, and fuser -vn <tcp|udp> <port>
for port.
Raise inotify limit for IntelliJ IDEA
Write the following line to /etc/sysctl.d/99-custom.conf
1 | fs.inotify.max_user_watches = 524288 |
Sysrq
Write the following line to /etc/sysctl.d/99-custom.conf
to enable all the sysrq operations.
1 | kernel.sysrq = 1 |
Reboot to make changes take effect, or execute echo 1 >/proc/sys/kernel/sysrq
.
Hold Alt
, and press the following key sequence.
SysRq
R
unRawE
tErminateI
kIllS
SyncU
UnmountB
reBoot
Note that the key C
can make your kernel panic immediately.
Watch FS buffer status
1 | watch grep -e Dirty: -e Writeback: /proc/meminfo |
You can execute sync
to flush the buffer immediately.
Map Alt Gr (Right Alt) to Alt in GNOME Shell
Open GNOME “Settings > Keyboard” and set “Alternate Characters Key” to another key, e.g. “Right Super” which doesn’t exist on ThinkPad keyboards.
Map Alt Gr (Right Alt) to Alt in tty
From Arch Wiki
1 | cd /usr/share/kbd/keymaps/i386/qwerty |
Edit us-with-two-alt-keys.map
,replace include "linux-with-alt-and-altgr"
with include "linux-with-two-alt-keys"
.
1 | gzip us-with-two-alt-keys.map |
Edit /etc/vconsole.conf
, replace KEYMAP=us
with KEYMAP=us-with-two-alt-keys
.
Reboot.
Better bash.bashrc
Originally from Arch Wiki, but now the page is deleted. Anyway you can still access its Chinese version.
1 | # /etc/bash.bashrc |
Bash completion
To enabling cyclic completion on tab, add the following line to your .bashrc
:
1 | bind '"\t": menu-complete' |
To get more completion with specific commands, install package bash-completion
.
Bash command not found hook
Install package pkgfile
.
Execute previous commands in bash
Ctrl+R
(I-search backward in emacs) can let you quickly execute command in your history.
!!
is substituted to be the last command in your history, but be careful when using it, for example echo !!
will lead to unexpected behavior if !!
is substituted to be something && poweroff
, then poweroff
will be executed. To avoid such cases, always wrap it with quotes, like echo "!!"
.
Input tab or newline character in bash
Ctrl+V
in bash works as Ctrl+Q
in emacs, which will insert the next character literally.
Edit current command in editor
Press Ctrl+X
then Ctrl+E
, and then you’ll be able to edit the current command in your editor before execution.
Access clipboard in bash
Install package xsel
. Add alias xsel='xsel -b'
to your .bashrc
, and then you can use it like xsel <input_file
or xsel >output_file
.
Default font
To specify your preference on default fonts, create /etc/fonts/local.conf
, and edit it like the following example:
1 |
|
Now you have appropriate fonts for sans-serif
, serif
and monospace
as default.
For more information, see Arch Wiki.
Emoji font
Install noto-fonts-emoji
(or noto-fonts-emoji-blob
).
Install local font
From Arch Wiki:
Drop your font files into ~/.local/share/fonts/
(~/.fonts/
is deprecated), cd
into that directory, and execute the following command.
1 | echo -n "Updating font cache... " |
CJK font not showing in some PDF viewers
Install poppler-data
.
Handle filesystem package update
Use diff
and your editor to manually merge your passwd
, shadow
, group
and gshadow
with the *.pacnew
one(s), then execute pwconv
and groupconv
for updating the shadow ones (*-
).
Sync time with NTP
1 | sudo pacman -S ntp |
For more information, see Arch Wiki.
Analyze boot time
1 | systemd-analyze blame |
For more information, see man systemd-analyze
.
Sometimes man-db.service may slow down the booting drastically, see this thread, this issue, and this issue.
Sometimes journald can slow down the booting for having too many journal files, see this Arch Wiki to set an limit on old journal files and clean them up.
System backup using tar
Install AUR package system-tar-and-restore
.
Example: /etc/backup.conf
1 | # Configuration file for backup.sh script. |
To start a backup, execute backup.sh
as root.
Rename files with number
1 | find -name '*.png' | sort -n -r | gawk '{ printf "mv %s %03d.png\n", $0, NR }' | bash |
100 files, reversely:
1 | find -name '*.png' | sort -n -r | gawk '{ printf "mv %s %03d.png\n", $0, 100 - NR }' | bash |
Starting with 100:
1 | find -name '*.png' | sort -n -r | gawk '{ printf "mv %s %03d.png\n", $0, 100 + NR }' | bash |
Shell calculator
From an AskUbuntu question.
Add the following lines to your .bashrc
.
1 | =() { |
For example, = "e^(i*pi)+asin(1)/90"
gives 0
.
Use English-named XDG user directories
As in Arch Wiki, execute LC_ALL='en_US.UTF-8' xdg-user-dirs-update
.
GNOME 3 start up applications
As of GNOME 3.12, gnome-session-properties
is removed. Instead, launch gnome-tweaks
and go to the corresponding tab. If you cannot add a start up application (the add button not responding), try launching gnome-tweaks
from your terminal.
To truly manage your start up applications, go to ~/.config/autostart/
and edit the desktop files there.
Pomodoro for GNOME 3
Install AUR package gnome-shell-pomodoro
.
Clipboard management tool for GNOME 3
Install AUR package gpaste
, restart GNOME shell and enable the extension GPaste.
View video codec information
Use ffprobe
.
Clip video
From StackOverflow:
If you want to support video players without edit list support (or actually drop the unused frames), you need to do a re-encode, which is the default if copy
is not specified.
Normally, you can use the following command to clip a video:
1 | ffmpeg -i <INPUT_FILE> [-ss <START_TIME>] [-to <STOP_TIME>] [-async 1] <OUTPUT_FILE> |
Convert video to animated GIF
Adapted From dtbaker and a SuperUser question.
1 | mkdir frames |
If you need to compress your GIF file, use gifsicle
or do it online; for cropping, you also can use this site with option “Crop with Gifsicle” (ImageMagick output seems corrupted).
Convert SVG to PNG (or others)
1 | inkscape --export-png=<OUTPUT_FILE> --export-width=<WIDTH> --export-height=<HEIGHT> |
--export-dpi
is also available.
See man inkscape
for more formats.
Convert PDF to PNG
From StackOverflow.
1 | convert -density 300 <YOUR_FILE.pdf> <YOUR_FILE.png> |
Where the -density
parameter is your desired DPI.
Note that the -density
parameter must come before the input file, or it won’t take effect.
Bitmap operation
Resize:
1 | mogrify -interpolate bicubic -resize 50% *.png |
Crop:
1 | mogrify -crop 1080x1845+0+75 *.png |
Merge PDFs
1 | pdfunite <SOURCE_PDF_FILES> <OUTPUT_PDF_FILE> |
Convert GB* encoded mp3 tag to Unicode
Install package easytag
.
Note that EasyTag may become the handler for MIME type inode/directory
, instead of your own file manager, say, Nautilus. You can delete the default association for Easytag and inode/directory in ~/.local/share/applications/mimeapps.list
, which is managed by gvfs-mime
. See also the MIME type section.
Play FLAC with CUE
Use deadbeaf
. Rhythmbox cannot handle CUE due to its library design.
Install deadbeef-mpris2-plugin
if you want MPRIS2 support (Controlling media playback in GNOME shell and other places).
Install deadbeef-gnome-mmkeys-git
if you want media key support (Needs to be enabled in this plugin’s configuration after installation).
Edit FLAC metadata
Use metaflac
from the flac
package.
Test FLAC integrity
Use flac --test <YOUR_FLAC_FILE>
.
Edit sheet music
Use musescore
.
Edit video
Use openshot
.
Edit subtitle
Use aegisub
.
Burn ASS subtitle into video
Use ffmpeg -i <INPUT_VIDEO> -vf 'ass=<SUBTITLE_ASS>' <OUTPUT_VIDEO>
.
Synchronize directories
Use freefilesync
.
Use adb-sync
from the adb-sync-git
for Android.
MIME type handling
In GNOME, there are two components managing the default application for a MIME type.
The first one, which is system-wide, can be queried or set via xdg-mime
.
The second one, which is a per-user setting, can be queried or set via gvfs-mime
, or manually editing ~/.local/share/applications/mimeapps.list
.
The second one takes precedence, and I guess gvfs-mime
is implemented partially for GNOME Open with dialog.
Google URL in Google Chrome
Open ~/.config/google-chrome/Default/Preferences
, edit last_known_google_url
and last_prompted_google_url
.
If Chrome keeps reverting the url, visiting https://www.google.com/ncr may help.
Screenshot
Shortcut keys for screenshot is listed in the search category of its setting.
Screen to file:
PrtSc
Window to file:
Alt
+PrtSc
Area to file:
Shift
+PrtSc
To clipboard instead:
Ctrl
+ aboveRecord:
Shift + Ctrl + Alt + R
To open a dialog for settings before screenshot, execute gnome-screenshot -i
.
Resize window for screenshot
Enable the Screenshot window sizer
extension in gnome-tweaks
, then you can use Ctrl+Atl+S
to cycle through a list of 16:9 window sizes.
Save screenshot to clipboard when PrtSc
Swap the values of org.gnome.settings-daemon.plugins.media-keys.{,area-,window-}screenshot{,-clip}
.
Remapping ThinkPad keys
On my ThinkPad X1 Carbon, the usual location for Menu key is a PrtSc key, and Fn
+ F9
–F12
doesn’t map to media keys. xmodmap
didn’t work, and modification to xkb
database gets overwritten when xkeyboard-config
updates. So here is the way to achieve this this with udev hwdb.
Create file /etc/udev/hwdb.d/90-thinkpad.hwdb
:
1 | evdev:atkbd:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*:pvrThinkPad* |
And run sudo systemd-hwdb update && sudo udevadm trigger
. Enjoy the remapped keys!
Alternatively for ThinkPad TrackPoint Keyboard II, create 90-thinkpad-trackpoint-keyboard-ii.hwdb
:
1 | evdev:input:b0003v17EFp60EE* |
Media keys not working when Chrome is running
Set chrome://flags/#hardware-media-key-handling
to “Disabled” to avoid the conflict between GNOME and Chrome. You may need to reboot for GNOME to properly handle media keys again.
Control ThinkPad battery charging
tp_smapi has been out of date for a long time, and it did not support my T450. Newer models of ThinkPad should use tpacpi-bat instead.
For simplicity, there is a tp-battery-mode package. Install it, enable and start the service, and you are done.
Recover lost free space on Ext2/3/4 partitions
Ext2/3/4 filesystem keeps 5% of its blocks reserved and usable only by root, which ensures that a normal user cannot fill the whole disk and cause the system to fail.
However on data partitions such as /home
, this might be a waste of space. To get around this limitation, run sudo tune2fs -m 0 /dev/sdXX
, which can be done online.
Draw graphs
LibreOffice Draw, and use its connectors instead of bare wires. Shift for regular shape and Ctrl + Mouse move for cloning can also be handy.
Render GFM
Bash script from jaburn’s gist.
1 |
|
Generate mosaic image
See this question.
Minecraft with Forge crashes on splash screen
Sometimes Minecraft with Forge can crash with a message like the following one:
1 | [xcb] Unknown request in queue while dequeuing |
Disabling the Forge splash screen by setting enabled=false
in .minecraft/config/splash.properties
can workaround this problem.
Cannot start graphical application under su or sudo on XWayland
Execute xhost +local:
to allow local connections to X server.
Better Rhythmbox UI design
Install and enable Alternative Toolbar.
Emacs shows white menu bar in dark theme
Install gnome-themes-extra
, then launch gnome-tweaks
, go to the “Appearance” tab and select “Adwaita-dark” for “Legacy Applications”.
Video playback tearing in full screen
Install GNOME extension Disable unredirect fullscreen windows.
Automatically change wallpapers
Install variety
, and https://unsplash.com/collections/3863203/desktop-wallpapers
can be a good image source.
You may also want to enable “Auto-rotate the image according to EXIF data” under “Wallpaper” and filter for image size under “Filtering”. The built-in indicator doesn’t work on GNOME 3 so you may also disable it.
Additional tools
ack
:grep
replacement.cloc
: Count lines of code.dos2unix
: Convert End-of-line and some encoding to Unix flavor.dosfstools
:mkfs.fat
, etc.easytag
: MP3 tag editing and conversion.gpaste
: Clipboard managergsmartcontrol
: Graphical SMART viewer.haveged
: Boost low entropy.htop
:top
replacement.iotop
:top
on I/O.jq
: Manipulate JSON in command line.lsof
: List opened files.mtr
:traceroute
+ping
, automatically.nload
: Display current network usage.ntfs-3g
: NTFS writing support, and others.pastebinit
: Various pastebin services.pdfgrep
:grep
on PDF.powertop
: Show power consumption.profile-cleaner
: Optimize browser profile SQLite database, and more.proxychains
: Proxify other programs.pv
: View progress fordd
, etc.rlwrap
: Wrap programs with readline style input.tig
: Git repository browser.translate-shell
: Command-line translator using Google Translate or others.trash-cli
: Trash bin in command line.tree
:ls
recursively in tree format.vipe
: Run editor in middle of a pipeline.vlc
: Versatile and stable video player.