IP Address Blocks
There are 4 classes of IPv4 networks:
A Class A network can have 16,777,214 computers on it. It has an IP address that starts with a number in the range 0 to 126. 127 is reserved for the local loopback. (Only 127.0.0.1 is ever used although this may change in the future).
A Class B network can have 65,534 computers on it. It has an IP address that starts in the range of 128 to 191.
Vim: More Copying Tips
Blocks of lines can be copied in Vim using ranges, i.e., two numbers separated by a comma indicating the start and end of the block of lines.
Some Examples
To copy line 20-25, use:
:20,25yank
To copy five lines just above the cursor:
:-4,.yank
where the period (.) indicates the current line.
To copy five lines just below the cursor:
:.,+4yank
Log File Maintenance and Cleanup
Log files sometimes take up a lot of disk space. Some applications have internal processes that run periodically to manage them and some do not. Often, this becomes a problems after a while as the logs consume all of your partition space.
You can manage these files yourself with a simple script running in a cronjob (or systemd timers if you’re so inclined) if they have a common naming convention and you have the proper access.
Vim: How to Copy & Paste
Most Vim tutorials and cheatsheets out there will cover how to copy and paste. Pasting is the easy part. Let’s talk about copying!
Copying
To copy the current line (line in which the cursor is placed), simply press double lower y (yy) or single upper case y (Y).
yy or Y: copies/yanks the current line, including the newline character at the end of the line.
To copy a specific number of lines under the cursor (beginning from the current location of the cursor) simply precede the command with the number of lines that you wish to copy, i.e., Nyy (where N is the number of lines).
Format Disk using exFat on Command Line
You may not always be working on a Linux system using a GUI, like a server or a system with very low resources. Sometimes you may need to format a disk to exFat using the Command Line. It’s not really that difficult.
The first thing you need to do is to know which device is to be formatted so before you connect the disk or USB make sure you run the lsblk command before and after doing so. This way you will be certain not to format the wrong disk by mistake and cause a data loss.
Find Your External IP Address
It’s easy to find your internal IP address my using tools like ifconfig or ip a but to find your external IP address (the one that connects you to the outside world) you must use other means. Here are 3 simple commands that you can use to do just that:
$ curl ifcfg.me72.76.yyy.xxx$ curl icanhazip.com72.76.yyy.xxx$ nslookup myip.opendns.com. resolver1.opendns.comServer: resolver1.opendns.comAddress: 208.67.222.222#53Non-authoritative answer:Name: myip.opendns.comAddress: 72.76.yyy.xxx
Vim: Underlining a Line
Of course, Vim is just a text editor but you can underline a line using a set of keystrokes that copies the string to be underlined to the next line and then replaces the string with hyphens using this set of Vim commands:
YpVr-
So if you have a line:
This Is My Page Title
just position the cursor at the start of that line and enter the abovementioned commands and it will turn it into:
Finding Duplicate Files in a Directory Tree
Sometimes I need to find all of the duplicate files in a directory tree. I have this issue all of the time when I move my music collection. Here is a nifty script to sort these things out:
#!/bin/bashfind -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 -D --all-repeated=separate
Virt-Manager Pool Running Out of Space
Once upon a time, I had an issue with virt-manager’s pool space running low. I was creating too many VMs using the default configuration. This needed to be resolved because images are being created in /var/lib/libvirt/images which was part of my root partition, which was also low. Since I am the only user on this machine, I decided to change this to default to my home directory:
- Create
~/libvirt/images - Run
$ sudo virsh pool-edit defaultas a privileged user or as therootuser. - Change the path to point to your new directory.
KVM: Importing an OVA appliance
You may or may not be aware if it, but an OVA file is just a tar archive containing an .ovf and a .vmdk files, respectively the VM configuration and disk.
$ ls *.ovaHTAOE.ova$ tar tf HTAOE.ovaHTAOE.ovfHTAOE-disk001.vmdkHTAOE.mf
So, you can simply extract the files: