10 KiB
Linux
Application
- Update MINE database:
update-mime-database /usr/share/mime
- Get MINE Type of specific file:
xdg-mime query filetype <file>
- Get default application for a specific MINE type:
xdg-mime query default <minetype>
- Find list of MIME types in::
/usr/share/applications
- Music
- Download video or playlist from YouTube:
youtube-dl --extract-audio --audio-format mp3 <VideoOrPlaylistURL>
- Download video or playlist from YouTube:
- Markdown
- Grip is required
pip install grip
- Grip is required
Office
- Remove certain pages from PDF:
pdft <input.pdf> cat <pages or range> output <output.pdf>
- Single pages:
n m
- Range of pages:
n-m
- Special pages:
start end
- Single pages:
- Merge several PDF files:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=<output.pdf> <input1.pdf input2.pdf>
- PDF to PNG in high quality
pdftoppm <input.pdf> <outputname> -png
pdftoppm <input.pdf> <outputname> -png -f {page} -singlefile
pdftoppm <input.pdf> <outputname> -png -r 300
- Rotate PDF page:
pdftk <input.pdf> cat <page>-<rotationtype> output <output.pdf>
- Rotation type:
endeast
- Rotation type:
- Add Margin to PDF:
pdfcrop --margin <lMargin> <tMargin> <rMargin> <bMargin> <input> <output>
- Margin of
27
corresponds to approximately $1$cm - If one argument if provided to
--margin
it is applied to all4
sides
- Margin of
-
Compress PDF:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/<option> -dNOPAUSE -dQUIET -dBATCH -sOutputFile=<output.pdf> <input.pdf>
dPDFSETTINGS=/screen
lower quality, smaller size. (72 dpi)dPDFSETTINGS=/ebook
for better quality, but slightly larger PDFs. (150 dpi)dPDFSETTINGS=/prepress
output similar to Acrobat Distiller Prepress Optimized setting (300 dpi)dPDFSETTINGS=/printer
selects output similar to the Acrobat Distiller Print Optimized setting (300 dpi)dPDFSETTINGS=/default
selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file
- Copy file and show progress: Use
rsync
as:rsync -ah --progress <src> <dest>
- Untar Archive
.tar
:tar -C <destFolder> -xvf <myfile>.tar
.tar.gz
:tar -C <destFolder> -zxvf <myfile>.tar.gz
.tar.xz
:tar -C <destFolder> -xf <myfile>.tar.xz
- Add status
- Simple method: add option
--checkpoint=.100
to add a.
for every 100 files extracted - More complex:
pv <myfile> | tar -xz
- Simple method: add option
Pacman
- Install package and update:
pacman -Syu <package>
- Remove package and all dependencies:
pacman -Rns <package>
- List all packages:
pacman -Qe
- Get info about package:
pacman -Qi <package>
- Error
failed to commit transaction (conflicting files)
- Check if conflicting file is required by another package:
pacman -Qo <fullFilePath>
- Remove or rename file
- Check if conflicting file is required by another package:
- Clear pacman cache
pacman -Sc
orpacman -Scc
- One or more PGP signatures could not be verified:
gpg --recv-keys <key>
System
- Keyboard
- Change X11 Layout:
setxkbmap <layout>
- Define layouts in:
/usr/share/X11/xkb/symbols/<layoutname>
- Make layout visible to the menu by adding them to:
/usr/share/X11/xkb/rules/evdev.xml
- Change directly in Xorg via
/etc/X11/xorg.conf.d/00-keyboard.conf
- Change X11 Layout:
- Xresources
- Reload config file:
xrdb ~/.Xresources
- Read config and merge with currently active:
xrdb -merge ~/.Xresources
- Reload config file:
- Other
- Sudo config:
sudo visudo
- When editor not exported correctly:
sudo EDITOR=vim visudo
- When editor not exported correctly:
- Sudo config:
- Boot Hooks:
cat /proc/cmdline
- System Event Handler
- Basic systemd event options are in
/etc/systemd/logind.conf
- Get acpid key info
acpi_listen
- Create custom event
- Create listener
- Create event listener file at
/etc/acpi/events/<someName>
- Insert the following content
event=<eventName> action=/etc/acpi/handlers/<handlerName> <parms>
- Create handler script at
/etc/acpi/handlers/<handlerName>
- Restart acpid service
- Create event listener file at
- Create listener
- Basic systemd event options are in
- Sound:
- Mic test:
arecord -vv -f dat /dev/null
- Mic test:
- BIOS
- Display detected devices
fwupdmgr get-devices
- Download latest metadata
fwupdmgr refresh
- List available updates
fwupdmgr get-updates
- Install updates
fwupdmgr update
- Display detected devices
- Mount
fat
drive with user permissionsmount <device> <mountPath> -o dmask=000,fmask=111
- Show which process hold a mount:
sudo lsof | grep <mountPath>
- Bootable
- Copy image to drive
dd if=<isoPath> bs=4M of=<drive> status=progress
- Copy image to drive
Wifi
- Wpa2 Enterprise connection for ETH network. Credits to https://gist.github.com/mvetsch/9bfdee7c56140eae2baa0be711fc8ded
nmcli connection add \
type wifi \
con-name "eduroam" \
ifname "wl" \
ssid "eduroam"
wifi-sec.key-mgmt "wpa-eap" \
802-1x.eap "ttls" \
802-1x.identity "[CUT]@student-net.ethz.ch" \
802-1x.phase2-auth "mschapv2" \
802-1x.domain-suffix-match "radius-service.ethz.ch"
- EPFL
nmcli connection add \
type wifi \
con-name "eduroam-epfl" \
ifname "wl" \
ssid "eduroam" \
wifi-sec.key-mgmt "wpa-eap" \
802-1x.eap "peap" \
802-1x.identity "jegraf@student-net.ethz.ch" \
802-1x.phase2-auth "mschapv2" \
802-1x.domain-suffix-match "radius-service.ethz.ch" \
802-1x.system-ca-certs "yes" \
nmcli connection add type wifi con-name eth ifname wlp3s0 ssid "eth" -- wifi-sec.key-mgmt wpa-eap 802-1x.eap ttls 802-1x.identity [CUT]@student-net.ethz.ch 802-1x.phase2-auth mschapv2 802-1x.domain-suffix-match radius-service.ethz.ch
# activate with
nmcli connection up eduroam --ask
nmcli connection up eth --ask
- Connect to ETH VPN:
sudo openconnect https://sslvpn.ethz.ch
Mount luks encrypted lvm partition from live boot
lvm2
andcryptsetup
are required- Probe required modules
sudo modprobe dm-crypt
- Determine the disk path using
sudo fdisk -l
,lsblk
,blkid
etc. - Decrypt volume and mount it to
/dev/mapper/<someName>
usingsudo cryptsetup luksOpen <diskPath> <someName>
- Scan for the LVM volumes
sudo vgscan
- Activate volume
sudo vgchange -ay <lvmVolume>
- Find the volume
sudo lvs
- Mount the volume
sudo mount /dev/<lvmVolume> /mnt/
- Mount required volumes and pass the shell to the main system
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
Access critical stuff from inside chroot
for i in dev dev/pts sys tmp run proc
do
mount --bind /$i /mnt/<newChroot>/$i
done
chroot /mnt/<newChroot>
Network not working inside chroot
cp /etc/resolv.conf /mnt/<chroot>/resolv.conf
Forward device to internet
- Add route on device which matches the ip of the host:
ip route add default via <HostIP>
- Enable forwarding:
sysctl net.ipv4.ip_forward=1
- Add iptables rules:
iptables -t nat -A POSTROUTING -o <InternetInterface> -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i <DeviceInterface> -o <InternetInterface> -j ACCEPT
Restore Raid of LVM volumes
lvm2
is required- Required modules:
dm-mod
,raid1
- Assemble RAID
mdadm --assemble /dev/md0 /dev/<member1> /dev/<member2>
- Scan for the LVM volumes
sudo vgscan
- Activate volume
sudo vgchange -ay <lvmVolume>
- Find the volume
sudo lvs
- Mount the volume
sudo mount /dev/<lvmVolume> /mnt/
- Add raid config
mdadm --examine --scan > /etc/mdadm/mdadm.conf
User and Groups
- Change primary group
sudo usermod -g <primaryGroup> <user>
- Add group to user
sudo usermod -aG <group> <user>
- Reload user after adding to group
newgrp <group>
Block websites using hosts
file
- Enter the websites into
/etc/hosts
as follows:
0.0.0.0 <website>
::1 <website>
- Flush DNS cache by restarting
nscd
anddnsmasq
Networking
- Show ports being listened on
netstat -plntu
- Show used ports
lsof -Pn -i4
Backup
- Remote block device to local:
- Backup :
ssh -C <user@address> 'dd if=/dev/<device>' | dd of=<some_image>.img
- Restore:
dd if=<some_image>.img | ssh -C <user@address> dd of=/dev/<device>
- Backup :
SSH copy and untar after sending
pv <my.tar.gz> | ssh <address> 'tar yxpf - -C <destDirectory>'
Cleanup
- Find large file:
du -hs * | sort -h
Mount partition of disk image created with dd
-
Find partition start:
fdisk -u -l <my_img>
-
Calculate start offset:
<start> * 512
, where515
is the block size -
Mount:
mount -o loop,offset=<my_offset> <my_img> <my_mountpt>
-
Check hash for all files in folder:
sha1sum <somePath>/* | sha1sum
-
Check hash for all files in tree:
find <somePath> -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum
-
Check if content of directory has changed:
ls -alR --full-time /folder/of/stuff | sha1sum
-
mpv play mono:
--audio-channels=stereo
-
Screensaver stuff:
- Set screensaver to 10mins:
xset s 600
- Disable screensaver:
xset s 0
- Disable powermanagement:
xset -dpms
- Enable powermanagement:
xset +dpms
- Show current settings:
xset q
- Set screensaver to 10mins:
-
Sound on HDMI:
- Check name of output:
pacmd list-cards | grep output\:
- Set to HDMI:
pactl set-card-profile 0 output:hdmi-stereo
- Set back to internal:
pactl set-card-profile 0 output:analog-stereo
- Check name of output:
-
Connect iPhone
- Install
ifuse
andlibimobiledevice
- Connect iPhone, unlock and select trust
- Run
idevicepair pair
- Run
ifuse -o allow_other <mountpoint>
- The mount point should be owned by the user and not root
- Install
-
Get log from
dd
by runningsudo kill -USR1 $(pgrep ^dd$)
-
Server at: http://localhost:631
-
Wrong
TERM
on ssh (Terminal)- Copy terminfo to remote:
infocmp | ssh <remote> tic -
- Copy terminfo to remote:
-
Display formatting like
\n
,\t
in less:printf "$(< <myfile>)" | less
-
Project dos to linux: `find . -type f -print0 | xargs -0 dos2unix
-
See all files an executable touches at start:
strace -e openat <ELF>