Linux Commands

File operations

Disk copying

dd if=/dev/sdX of=/dev/sdY bs=128M # copy all sectors of sdX to sdY (sdY>=sdX)

Disk cleanup

dd if=/dev/zero of=/dev/sdX bs=128M # zero out all sectors of sdX

Mirror dir contents

rsync -av --delete /from/source/dir/ /to/dest/dir/  

CAUTION the trailing slash in both cases is essential

Remove -v if you don't want to see files as they are copied

Remove --delete if you don't want to delete extra files from destination

Testing

Disk testing

lsblk # list of disks/partitions

badblocks -o badblocks.log -s /dev/sdX # read only (will catch only major errors)
badblocks -o badblocks.log -s -n /dev/sdX # read/write usually non-destructive
badblocks -o badblocks.log -t random -s -w /dev/sdX # read/write DESTRUCTIVE!

Find things that run every now and then (except services)

One long command to see what runs from rc.local, /etc/crontab & /etc/cron.(hourly|daily|weekly|monthly)
clear;function err(){ echo "---"$1"---"|grep --color .;};function clr(){ sed -e 's/\s/ /g' -e 's/  */ /g'|grep -v '^ *#\|^ *$\|^[A-Z][A-Z]*=' ;};err 'crontab';cat /etc/crontab|clr|grep -v '/etc/cron.[a-z][a-z )]*';err '/etc/cron.*'; find /etc/cron.* -not -type d|grep -v '/etc/cron.\(d/\|deny$\)\|/\(upstart\|passwd\|update-notifier.*\|libvirt-bin\|ntp\|fstrim\|.placeholder\|logrotate\|aptitude\|standard\|man-db\|apt-xapian-index\|0anacron\|mlocate\|apt\|popularity-contest\|dpkg\|apport\|bsdmainutils\|makewhatis.cron\|0hourly\)$'; err rc.local;cat /etc/rc.local|clr|grep -v '\(cd \|exit\|touch\)'; err "systemctl list-timers"; systemctl list-timers 2>/dev/null

You can use `dpkg -S /path/to/file` or `rpm -qf /path/to/file` to see if a file belongs to a system package

`dlocate -S /path/to/file$` is a fast alternative to `pdkg -S`

Function clr is used in pipes to strips some uninteresting lines from the output of commands (it strips empty lines,comments & VARIABLE= definitions). Function err just preaty prints $1

Moving zip files between Linux and Windows

How to zip files in linux and download them to your PC

# On linux
7za a /tmp/foobar.7z '/gluster/brick1/brick/archived/users/users/k.vogiatzi/some_dir_you_wish_to_get'

# On your PC (WSL)
scp linux:/tmp/foobar.7z /mnt/c/some/dir/in/your/pc/ && ssh linux rm /tmp/foobar.7z

Unziping windows files on linux

To unzip στο Linux για σωστά ελληνικά απαιτεί την παράμετρο -O CP737

π.χ.:

unzip -O CP737 CLIENTS.zip
Topic revision: r8 - 08 Jun 2024, NickDemou
Copyright © enLogic