Linux: Shell Script for Removing Duplicate Files

So when it comes to removing files, this little script is the berries – it finds your duplicate files and proceeds to build a shell script to remove them all, called rem-duplicates.sh.

In here you will find all the lines to remove the duplicates commented out with a “#” – you then uncomment the ones to be removed, save and run the script. Simples!

#!/bin/bash
OUTF=rem-duplicates.sh;
echo "#! /bin/sh" > $OUTF;
find "$@" -type f -printf "%s\n" | sort -n | uniq -d | xargs -I@@ -n1 find "$@" -type f -size @@c -exec md5sum {} \; |
sort --key=1,32 | uniq -w 32 -d --all-repeated=separate | sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF;
chmod a+x $OUTF;
ls -l $OUTF

All credit here: Unix shell script for removing duplicate files.

Linux: Add a New HDD to a VM Without Rebooting

Add a New HDD to a VM Without Rebooting

This article describes how to add a new HDD to a VM without rebooting – handy if you need consistency of service and don’t have a redundant solution.

 

Solution:

Add a hard disk as usual through the VM settings. Check dmesg to see if the kernel has detected it automatically, if not:

echo "- - -" > /sys/class/scsi_host/host0/scan
fdisk -l

You should see something like:

Disk identifier: 0x00004fff

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    30076927    15037440   83  Linux
/dev/sda2        30078974    31455231      688129    5  Extended
/dev/sda5        30078976    31455231      688128   82  Linux swap / Solaris

Disk /dev/sdc: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 cylinders, total 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

/dev/sdc is the disk you just added, all you need to do is “fdisk /dev/sdc” to partition it and “mkfs.ext3 /dev/sdc1” to format the partition.

Job done.

Linux: Broken sudoers file in Ubuntu

I’ve done this twice now, sometimes lessons need repeating. If you are going to edit /etc/sudoers in Ubuntu then set a root password or you risk locking yourself out.

If you edit the sudoers file and the syntax is incorrect then the system can no longer read the sudoers file. Now you can’t fix the file because

sudo vi /etc/sudoers

returns an error.

You need to reboot, holding shift before the grub menu, and choose recovery mode. Now go to the command line as root, mount the filesystem as read/write and give yourself permission to edit the sudoers file:

mount -n -o remount,rw /
chmod u+x /etc/sudoers

Now:

vi /etc/sudoers

and fix that mistake.

Really though .. if you had set a secure root password you could have avoided the pain with

su -
Exit mobile version
%%footer%%