ubuntu


Ubuntu Linux: How to Resize and add Label to a many picture files 1

Lets say you have a ton of pictures or photos that you want to resize and add a semi-transparent label at the bottom of this bulk of files and even rename them using a pattern based on a unique number.

You can either do this manually or by using imagemagick. If you chose the second way follow these steps:

First of all install it, from bash/terminal call the following:

sudo apt-get install imagemagick

When that command is successfully completed, navigate to the location that the pictures are and once you are there:

In order to resize all pictures then issue the following command (in this example we make all pictures at most 1200px long or 1200px tall and keep the aspect ratio) :

mogrify -resize 1200 *

NOTE: It will affect the original files! So if you want to keep them make sure to copy them elsewhere BEFORE issuing the above command.

After the above is done, you can issue the following set of commands to:

  1. Get each file and find it’s dimensions (which later will be used for the label creation)
  2. Rename all pictures following the number based pattern
  3. Add a semitransparent label containing custom text at the bottom
counter=0; for i in *;
do let counter=counter+1;
width=`identify -format %w "$i"`;
convert -background '#0008' -fill white -gravity center -size ${width}x30 caption:" Some Arbitrary Text " "$i" +swap -gravity south -composite NewFileName.`printf %03d $counter`.jpeg;
done

This command will preserve the original files.
All together with printing the file that is being processed as debuging information:

mogrify -resize 1200 *; counter=0; for i in *; do let counter=counter+1; echo $i; width=`identify -format %w "$i"`; convert -background '#0008' -fill white -gravity center -size ${width}x30 caption:" Some Arbitrary Text " "$i" +swap -gravity south -composite NewFileName.`printf %03d $counter`.jpeg; done

Sample/Result Photos:

 


How to setup DNS service for DHCP-enabled KVM guests

So you’ve set up KVM on your machine and you have installed a few guests to run on top, now it’s the time to access them.

Since KVM can run without a GUI, you might want to control these guests from the command line. But, how can you do it if you do not know the IP of the guests?

You can either connect to the guest using virt-viewer:

virt-viewer -c qemu:///system $MACHINE &

which requires more bandwidth since it will open up a VNC session.

Or, use ssh to connect using the guest’s name, like this:

ssh $MACHINE

which doesn’t require that you know the IP beforehand.

To achieve this, access guest machines using their hostname only, you can do the following: Edit /etc/resolv.conf and add the line nameserver 192.168.122.1 right after the search entries .

Your file should look something like this afterwards:
domain in.bytefreaks.net
search in.bytefreaks.net
nameserver 192.168.122.1
nameserver 194.44.13.20
nameserver 194.44.13.58
nameserver 194.44.13.11

Then you are ready to go! No restarts needed no extra steps.

NOTES:

  • After restarting (and some times periodically), the /etc/resolv.conf file will return to its original form because it is updating each time you restart the host machine from data it gets via the network DHCP server.
  • For this tutorial to work as is, your host machine needs to have the virtual IP 192.168.122.1 (the default IP of your host in libvirt — NOT THE IP of eth0, it’s a totally different thing). If you have a different libvirt IP use that one in the /etc/resolv.conf file.
  • Use your host’s IP as your first nameserver in /etc/resolv.conf to achieve name resolution for your guests.


Ubuntu Linux: Enable CPU Frequency Scaling / Change CPU Frequency 1

First: Install gnome-applets in order to get cpufreq-selector application.

sudo apt-get install gnome-applets

*NOTES: gnome-applets installs a LOT of stuff and will take more than 300MB of free space.

 

Second: Check if your CPU supports frequency scaling

sudo cpufreq-selector

*NOTES: It will take a few seconds or more to finish. If it doesn’t return any output proceed to the next step. If you get this message “No cpufreq support” then do not follow the next steps as you will not find neither the files mentioned below nor work out this way for you.

 

Three: Find out the available frequencies that your system can scale to and the available governors (modes of operation for frequency scaling).

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

*NOTES: You will get output that resembles these: 3000000 2300000 1800000 800000 and conservative ondemand userspace powersave performance.

 

Four and final step: Configure your system one core at a time.

sudo cpufreq-selector -c CORE_NUMBER -f FREQUENCY_IN_MHz -g GOVERNOR_MODE

*NOTES: CORE_NUMBER: An integer value that defines the core you want to edit. FREQUENCY_IN_MHz: A frequency from the scaling_available_frequencies file. GOVERNOR_MODE: A mode name from the scaling_available_governors file.