Thursday, August 31, 2017

Bulk Resize Images in Ubuntu

ImageMagick Installation
sudo apt-get update
sudo apt-get install imagemagick -y
 Resize to either height or width, keeps proportions using ImageMagick
cd /path/to/output
find </path/to/images> -iname '*.jpg' -o -iname '*.png' -exec convert \{} -resize WIDTHxHEIGHT\> \{} \;

Thursday, August 24, 2017

Thursday, August 17, 2017

Clone HDD Remotely

If your intent is to backup a remote computer's HDD A via SSH to a single file that's on your local computer's HDD, you could do one of the following.

Find the hard drive to backup. Notice that the hard drive is only the letters and not the number since the number is the partitions.
df -h
Run from remote computer
sudo dd if=/dev/sda | gzip -1 - | ssh user@local dd of=image.gz
Run from local computer
sudo ssh user@remote "dd if=/dev/sda | gzip -1 -" | dd of=image.gz

Methods for monitoring?

  1. Login via ssh in another terminal and ls -l the file to see what it's size is.
  2. You can use pv to monitor the progress of a large dd operation, for instance, for the remote example above, you can do:
    $ dd if=/dev/sda | gzip -1 - | pv | ssh user@local dd of=image.gz
    
  3. Send a "SIGUSR1" signal to dd and it will print stats. Something like:
    $ pkill -USR1 dd
    

Recursive Search

Here is the best way to find a pattern within a file recursively:

cd </starting/path
grep -r -i <pattern> ./*

cd <path to start search>
find ./ -type f ! -type d|xargs grep <pattern>

Delete Windows.old from Windows Server



Q: How can I delete the windows.old from an upgraded Windows Server 2012R2?

A: For a client OS that's upgraded, the Disk Cleanup utility can be used to delete the very large windows.old folder containing the old OS. This isn't available on a server OS without installing the Desktop Experience feature.

Command line tools to take ownership and delete the folder . Make sure to “run as administrator” with the cmd [powershell will not work]:
takeown /F c:\Windows.old\* /R /A /D Y
cacls c:\Windows.old\*.* /T /grant administrators:F
rmdir /S /Q c:\Windows.old

! - If you run into problems such as access denied or path file not found, try [remember command terminal must be run as administrator]
cacls c:\Windows.old\*.* /reset /T /C /L /Q

!!!! - When all else fails, use cygwin and remove it with the following:
Open Cygwin as an administrator
cd /cygdrive/c rm -rf Windows.old