Useful Linux commands
Tags: Linux
Last update: Mar 2018
- 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
2. 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
3. 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
4. Wipe a file with zeros:
shred -fvzun 0 file
5. Wipe a directory recursively with zeros:
srm -rvs directory
6. 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
7. Restore this prior zipped image file and write it directly to disk:
sudo gunzip -c image.gz | sudo dd of=/dev/sdX status=progress bs=1M
8. 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
9a. Mount a Linux Soft-RAID manually:
sudo mdadm --examine /dev/sdX sudo mdadm -A -R /dev/md9 /dev/sdX sudo mount /dev/md9 /openedRaidPartition
9b. And close it again:
sudo umount /openedRaidPartition sudo mdadm -S /dev/md9
10. List all loadable kernel modules:
find /lib/modules/$(uname -r) -type f -name \*.ko
11. 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
12. 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)
13. Laravel development quickstart:
git clone project.git cd project composer install composer update cp .env.example .env php artisan key:generate php artisan serve --port=8000
14. 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
15. 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
16. Rsync command which doesn’t copy everything every time while preserving times:
rsync -avP source destination #a = archive mode #v = verbose #P = show progress
17. Bash: interate through alle files within a specific folder and count its files
for i in /folderpath /folderpath ; do echo -n $i": " ; (find "$i" -type f | wc -l) ; done
Leave a Reply
Want to join the discussion?Feel free to contribute!