Unix Tips
Contents
iTerm 2
- To set the window title to the current directory:
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
NordVPN
Setup
- Install OpenVPN:
sudo dnf install openvpn
- Go to
/etc/openvpn
sudo wget https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip
sudo unzip ovpn.zip
sudo rm *.zip
Connecting to NordVPN
- Go to https://nordvpn.com/servers/ and select "Recommend Server"
cd /etc/openvpn/ovpn_udp
sudo openvpn <recommended_server>.udp.ovpn
- If you're on a network that doesn't allow UDP connections, you can try the same thing in
/etc/openvpn/ovpn_tcp
and<recommended_server>.tcp.ovpn
- If you're on a network that doesn't allow UDP connections, you can try the same thing in
RTorrent
- Add torrent:
<backspace>
- To add torrent in inactive mode:
<return>
- To changed the directory of an inactive torrent:
- Select the torrent
Ctrl-S
- To stop a download:
Ctrl-k
- To remove a torrent:
Ctrl-d
- To quit:
Ctrl-q
- To select torrents:
up/down
- To set the priority of a torrent:
+
/-
ImageMagick
Create a PNG image with some text
convert -background none -font <font_name>.ttf -fill black -pointsize 150 -size "256x256" -gravity center label:"<text>" <output_file_name>.png
Change image formats:
convert file.<input extension> file.<output extension>
Tmux
- Change the leader key to
M-o
because emacs usesC-b
:unbind C-b set-option -g prefix M-o bind-key M-o send-prefix
- Disable the clock in the tmux status bar:
set -g status-right ''
- Alternatively, set the clock to a simple day and date:
set -g status-right ' %F %l:%M %p '
(note the space padding to aid legibility) - Set window title:
M-o ,
- Window management
- Create window:
M-o c
- Next window:
M-o n
- Previous window:
M-o p
- Last used window:
M-o l
- Choose window from list:
M-o w
- Force quit the current window:
M-o &
- Create window:
- Helpful keybindings
- Reorder windows:
bind-key -n C-S-Left swap-window -t -1 bind-key -n C-S-Right swap-window -t +1
- Switch windows
bind-key -n S-Left previous-window bind-key -n S-Right next-window
- Then you can use
C-S-<left>/<right>
to reorder windows andShift-Left/Right
to jump between windows- KDE Konsole defines these keys for switching between tabs, so you'll have to go into
Settings -> Configure Shortcuts
and unbind the Next Tab and Previous Tab shortcuts
- KDE Konsole defines these keys for switching between tabs, so you'll have to go into
- Reorder windows:
- Scrollback
- To scroll in tmux, enter scroll mode:
M-o [
- To leave scroll mode:
q
- To increase the amount of scrollback tmux buffers:
set-option -g history-limit <number of lines>
- To scroll in tmux, enter scroll mode:
- tmux expects your bash startup to be in
~/.bash_profile
- Renumber windows:
set-option -g renumber-windows on
- Change the active window highlight
set-option -g window-status-format "#I:#W" set-option -g window-status-current-style "fg=green bg=black"
- To prevent tmux from renaming windows automatically:
set-option -g allow-rename off
- To reload the config without restarting tmux:
M-o :source-file ~/.tmux.conf~
- tmux plugin manager
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
- Add the following to the bottom of
~/.tmux.conf
set -g @plugin 'tmux-plugins/tpm' run -b '~/.tmux/plugins/tpm/tpm'
- Copy/Paste
- Go into scrollback mode
M-o [
- Hit
Ctrl-<SPC>
to enter select mode - Use arrow keys to select
- Hit
Alt-W
to copy - Hit
M-o ]
to paste - To integrate tmux with the system clipboard, install the tmux yank plugin
- Add
set -g @plugin 'tmux-plugins/tmux-yank'
to~/.tmux.conf
- Install the plugin with
M-o Shift-I
- To use:
M-o Y
copies the current command line- In select mode
y
copies the selection to the system clipboard
- Add
- Go into scrollback mode
- Clear scrollback:
M-o :clear-history
- Split panes:
- Horizontal split:
M-o "
- Vertical split:
M-o %
- Switch panes:
M-o <arrow key>
- To convert a window into a pane in the current window:
M-o :join-pane -t <target window number>
- To convert a pane back into a window:
M-o !
- Change layouts:
M-o <space>
- Horizontal split:
Shell
List only directories
ls -d */
find . -maxdepth 1 -type d
Get the current time in milliseconds
date +3N
- On MacOS, there is on
%N
option, so we just hack it by adding three zeroes to the time in seconds:date +%s000
Get the nth line of a file
cat <file> | sed -n "<line num>p"
- Example: to print the 10th line of a file:
cat foo.txt | sed -n "10p"
Aliases
- Date and time:
alias d="date '+M %p'"
— writes the current time in an easy-to-read format
Local Web Server
python3 -m http.server
Manual IP Address Configuration
- Temporarily
- Set the IP address:
ifconfig <interface> address <address> ifconfig eth1 address 172.16.64.2
- Set the subnet mask:
ifconfig <interface> netmask <subnet_mask> ifconfig eth1 netmask 255.255.192.0
- Set the IP address:
- Permanently
- Edit
/etc/network/interfaces
auto <interface> iface <interface> inet static address <ip_address> netmask <netmask>
- Example:
auto eth1 iface eth1 inet static address 172.16.64.2 netmask 255.255.192.0
- Edit
Configure Passwordless Logins
- Add your SSH public key to
~/.ssh/authorized_keys
on the target server
DC Calculator
- Viewing the stack
p
prints the value at the top of the stack without altering the stackn
pops the value at the top of the stack and prints it without printing a newlineP
pops the value at the top of the stack and prints it with a newlinef
prints the entire stack without altering it
- Arithmetic
k
pops the first value off the stack and uses it to set the precision+
pops two values off the stack, adds them and pushes the result on to the stack-
pops two values off the stack and subtracts the first from the second and pushes the result onto the stack*
pops two values off the stack, multiplies them, and pushes the result onto the stack/
pops two values off the stack, divides the second by the first and pushes the result onto the stack
- Stack control
r
swaps the two values at the top of the stackd
duplicates the value at the top of the stack and prints itc
clears the stack
List all installed packages on Fedora
dnf list installed
Select a random value
<list command> | shuf -n 1
- Example: Choose a random file:
ls -1 | shuf -n 1
MPV
- Usage:
mpv <video filename>
- Controls
<left>
/<right>
: Skip backwards/forwards by 5 secondsShift-<left>
/Shift-<right>
: Skip backwards/forwards by 1 second<up>
/<down>
: Skip back/forward by 1 minuteCtrl-<left>
/Ctrl-<right>
: Switch to previous/next subtitle language<SPC>
: Pause/unpauseq
: quitf
: fullscreen9
/0
: Lower/raise volumev
: Toggle subtitle visbility#
: Change audio track
- To specify a subtitle file:
--sub-file=<filename>
- To adjust subtitle delay:
Ctrl-Shift-<left>
: Displays previous subtitle and adjusts subtitle delayCtrl-Shift-<right>
: Displays next subtitle and adjusts subtitle delay
- To adjust subtitle delay:
- To rescale videos
--autofit=<width>[x<height>]
: Sets the width (and height) to a particular value while maintaining aspect ratio; if both width and height are specified, it uses the minimum of width and height meet the aspect ratio requirement--autofit-larger=<width>[x<height>]
: Likeautofit
, but only rescales the video if it would be larger than the specified dimensions
- Playlists:
- Create a file with video filenames separated by newlines
- Pass the playlist file to
mpv
with the--playlist
argument
rsync
- To sync all files of a particular type:
rsync -t <user>@<host>:/path/to/directory/*glob* .
- To recursively sync all files in a directory:
rsync -rt ./* <user>@<host>:/path/to/directory
Hostname
- To set the hostname:
sudo hostnamectl set-hostname <new_hostname>
GNU Find
- To exec a program on every found file:
find . -iname <glob> -exec <program> {} +
find . -iname <glob> -exec <program> {} \;
- The first form passes all found files to the program as command line args
- The second form invokes the program repeatedly, once per file
- To exclude directories/paths from
find
:find . \(-path <path 1> -or -path <path 2> -or ... \) -prune -or -iname <glob> -print
- If using the
-exec
, replace-print
with-exec
- To exclude particular file types:
\( -iname "<glob>" ! -iname "<exclude_glob>" \)
- Example: To find all
.js
files but exclude tests:find . \( -iname "*.js" ! -iname "*.test.js" \) -print
GNU Grep
- To eliminate "binary file matches" messages:
-I
- To just list files instead of each matching line:
-l
Synaptics touchapd customization:
- To set up two-finger click correctly:
synclient RightButtonAreaLeft=0 RightButtonAreaTop=0 ClickFinger2=3
Automatically set up power management:
- Install PowerTop:
sudo dnf install powertop
- Create the following systemd init file:
[Unit] Description=PowerTop Auto Tune [Service] Type=idle Environment="TERM=dumb" ExecStart="/usr/sbin/powertop --auto-tune" [Install] WantedBy=multi-user.target
cURL
- Download a file:
curl -o <file_name> <URL>
- To make cURL silent, add the
-s
flag - To add headers, use the
-H
flag:-H "header_name: header_value"
- If you need to specify multiple headers, use multiple instances of the
-H
flag - If the file is mangled, try adding
--compressed
- You can also go into Chrome's devtools and select "Copy As cURL"
RPM Fusion repo:
- To install RPM Fusion:
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
Clipboard
- Copy contents of file into clipboard:
- MacOS:
pbcopy < <file>
- Linux:
cat <file> | xsel -ib
- MacOS:
- Paste contents of clipboard into file:
- MacOS:
pbpaste > <file>
- Linux:
xsel -ob > <file>
- MacOS:
WeeChat setup with weechat.el
- Set up weechat
sudo apt install weechat
- Launch weechat:
weechat
- Configure basic settings
- Configure IRC server:
/server add freenode chat.freenode.net
- Configure SASL username:
/set irc.server.freenode.sasl_username quanticle
- Configure SASL password:
/set irc.server.freenode.sasl_password <password>
- Configure channels to autojoin:
/set irc.server.freenode.autojoin <comma separated list of channels>
- Configure IRC server:
- Configure weechat relay
- Configure relay password:
/set relay.network.password <password>
- Create an SSL key for the relay:
mkdir -p ~/.weechat/ssl
cd ~/.weechat/ssl
openssl genrsa 2048 > relay.key
openssl req -new -x509 -nodes -days 365 -key relay.key > relay.cert
cat relay.key relay.cert > relay.pem
- Tell weechat to use the new SSL cert:
/relay sslcertkey
- Set up the weechat relay port:
/relay add ssl.weechat 9899
- Configure relay password:
- Disable weechat colors:
/set weechat.color.chat_nick_colors gray
- Set up logging:
/set logger.level.irc.freenode 3
- Set up highlight monitoring
/script install highmon.pl
/set plugins.var.perl.highmon.away_only on
- Set up emacs:
- Install weechat.el:
M-x package-install RET weechat
- Copy in cert file:
scp <weechat_server>:/home/quanticle/.weechat/ssl/relay.cert ~/.emacs.d/relay.cert
- In
~/.emacs.d/init.el
:(require 'weechat) (require 'gnutls) (add-to-list 'gnutls-trustfiles (expand-file-name "~/.emacs.d/relay.cert")) (set-face-attribute weechat-nick-self-face nil :foreground 'unspecified :weight 'unspecified)
- Install weechat.el:
- To use weechat.el:
M-x weechat-connect RET
- Disable timestamps in weechat message buffer:
/set weechat.look.buffer_time_format ""
Clojure setup
- Install
rlwrap
- Install the latest OpenJDK JRE
- Install Clojure:
curl -O https://download.clojure.org/install/linux-install-1.10.1.502.sh chmod +x ./linux-install-1.10.1.502.sh sudo ./linux-install-1.10.1.502.sh
- Test to see if Clojure is installed by running:
clojure
to get the REPL