Script: Compilation of useful Linux commands
Compare binary files within the console and highlight those areas which differ. Vim and Colordiff have to be installed before.
diff -y <(xxd file.one) <(xxd file.two) | colordiff
Using a harddisk device for storing encrypted data:
sudo cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 -y /dev/sdX sudo cryptsetup luksOpen /dev/sdX usb-backup sudo mkfs.btrfs -L backupharddisk /dev/mapper/backup sudo mount /dev/mapper/backup /usb-backup
Mirroring with rsync from /source to /destination. Compression is great when backing up over the Internet.
rsync --compress --compress-level=9 --human-readable -av --progress --delete --log-file=/path/to/log.file /source /destination
Wipe a file with zeros:
shred -fvzun 0 file
Wipe a directory recursively with zeros:
srm -rvs directory
Backup of harddisks into compressed image file. Due to its multithreading capability pigz is much faster than gzip during compression:
sudo dd if=/dev/sdX status=progress bs=1M | pigz > harddisk.img.gz
Restore a zipped image file and write it directly to disk:
sudo gunzip -c image.gz | sudo dd of=/dev/sdX status=progress bs=1M
Recover a Linux Soft-RAID md/5:
sudo mdadm --assemble --scan sudo cryptsetup luksOpen /dev/md/5 temp sudo mount /dev/mapper/temp /your_path
Mount a Linux Soft-RAID manually:
sudo mdadm --examine /dev/sdX sudo mdadm -A -R /dev/md9 /dev/sdX sudo mount /dev/md9 /openedRaidPartition
And close it again:
sudo umount /openedRaidPartition sudo mdadm -S /dev/md9
List all loadable kernel modules:
find /lib/modules/$(uname -r) -type f -name \*.ko
Forced loading of vboxdrv for instance:
sudo modprobe --force-vermagic vboxdrv
Template for configuring a fresh manjaro xfce installation:
#update system sudo pacman -Syyu #install zshell sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" sudo pacman -S powerline-fonts #install virtualbox sudo pacman -S virtualbox #copy fonts which you need into /usr/share/fonts and run sudo fc-cache #fixing the Manjaro Linux XFCE text shadow problem on the desktop xfconf-query -c xfce4-desktop -p /desktop-icons/center-text -n -t bool -s false
Nice to have Manjaro packages:
gufw (firewall gui) chromium (browser) synapse (launcher) psensor (temperature) ether (pendrive tool) file-roller p7zip zip unzip unrar tilda (background terminal)
Laravel development:
git clone project.git cd project composer install composer update cp .env.example .env php artisan key:generate php artisan serve --port=8000
Restricting sFTP:
Add to /etc/ssh/sshd_config:
Subsystem sftp internal-sftp Match Group sftpusers ChrootDirectory %h ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no
Adding user and change configuration:
useradd newuser usermod -s /bin/false newuser chown root:root /home/newuser chmod 755 /home/newuser mkdir /home/newuser/writablefolder chown newuser:newuser /home/newuser/writeablefolder chmod 755 /home/newuser/writeablefolder groupadd sftpusers usermod -G sftpusers newuser service sshd restart service vsftpd restart
Replacing a broken harddisk (/dev/sda) with two partitions with RAID1 (md0 + md1):
#after having replaced the harddisk; copying MBR partition table sfdisk -d /dev/sdb | sfdisk /dev/sda #adding partitions to existing RAID-array md0 and md1: sudo mdadm /dev/md0 -a /dev/sda1 sudo mdadm /dev/md1 -a /dev/sda2 #reinstalling grub on both disks again, leave options empty, select two disks (/dev/sda + /dev/sdb) sudo dpkg-reconfigure grub-pc
Rsync command which doesn’t copy everything every time while preserving times:
rsync -avP source destination #a = archive mode #v = verbose #P = show progress