Posts

Showing posts from February, 2021

Pause a program which is using too much CPU

Sometimes your battery is running low and you need to pause a program without quitting it or force-quitting it, so that you can preserve battery but not lose the job that the program is doing. To do this,  Step 1. open a terminal Step 2. type:  ps ax | grep -i  "<program name>" so for example, if it's photoshop you need to pause, replace "<program name>" with "photoshop" Step 3. Next to the results on the far left you'll see a number, usually with 5 digits. E.g. 12345. Step 4. Type:  kill -STOP 12345 where 12345 are the numbers obtained in Step 2-3. Step 5. When you want to resume the program, type kill -CONT 12345 It should then continue to operate or run as usual without problems.

Want to test Linux before committing?

Introduction for Windows users If you are a Windows user and want to test drive Linux before committing to installing it, start with Cygwin, as it's the least invasive/destructive way to get used to Linux. After that, maybe try install Linux Subsystem for Windows (LSW) from the Windows 10 app store. A lot of users will think that installing LSW is the way to go. I disagree. When you have a Linux system, you always end up having to use the command line, and hence, it is best to become proficient at that before you install. Installing LSW will by default put you on a graphical installation of Linux and hence you might get the impression (incorrectly so), that it is a graphical system. It is not. Introduction for people with Macs and how to use Brew If you are a Mac user, you have more or less no need to try Linux, as it will give you a less useful experience than your current experience. Rather learn to use the command line on your machine and its capabilities. On Mac, you have a ter

ZFS syntax (updated)

Introduction ZFS is an alternative filesystem. It allows RAID, deduplication and compression. You create a collection of drives as a 'pool'. That's useful if you want many drives as one big drive. Suppose you have two spare drives, sdc1 and sdd1. To make them into one big drive with deduplication and no compression, do this. Deduplication = where it doesn't make multiple copies of identical files, just marks them as copies. Creating a ZFS pool (drive collection) zpool create -f zfspool /dev/sdc1  /dev/sdd1 zfs set compression= off  zfspool zfs set dedup= on  zfspool zpool list df -h you'll see it is mounted as /zfspool A zfs snapshot  is a read-only copy of  zfs  file system or volume. They consume no extra space in the  zfs  pool and can be created instantly. They can be used to save a state of file system at particular point of time and can later be rolled back to exactly same state.  LVM is similar to ZFS but doesn't offer all these other features. (In my e

Enable appleshare over IP and stop iptables from firewalling it

 The following syntax will enable appleshare over IP. iptables -A INPUT -i eno1 -p tcp --dport 548 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -o eno1 -p tcp --sport 548 -m state --state ESTABLISHED -j ACCEPT  

using letsencrypt for ssl certificates

 letsencrypt is an easy way to make SSL certificates for your website and it's free. The only issue is you have to renew the certificates (certs) every few months. You can automate that using cron. letsencrypt --renew-by-default --domains or certbot-auto renew These items are normally in /usr/bin or /usr/local/bin so put the full path before them in the crontab to make sure you don't get a file not found error. Suppose you want the check monthly on the first of each month: sudo crontab -e * * 1 * * /usr/local/bin/certbot-auto renew The most important thing with letsencrypt is to make sure your apache config file is correct. If you give a domain name without www, make sure you put it in the config file as www. Here's an example. <VirtualHost *:80>          DocumentRoot /var/www/domain.com          Options All Indexes ExecCGI SymLinksIfOwnerMatch          ErrorDocument 404 /error.html          ServerName www.domain.com          ServerAlias www.domain.co.za          Serv

Adding integers in BASH

 Addition in Bash is notoriously tricky and it almost never works as expected; it usually appends/joins two items as if they were strings regardless of whether they are in fact integers. This example works. Create a textfile containing lines of text, e.g.  a b c d Call it " list.txt ". Save this into a bash script and run it: #!/bin/bash counter=0 for i in `cat list.txt` ;  do   echo $counter   ((counter=counter+1)) done

non-interactive password change

 type (in BASH): echo -e " new_password  \n  new_password " | (passwd --stdin $USER) note the spaces around \n are there for readability, do not put them in.

Unpack an RPM file

Sometimes you want to unpack an RPM file to just get the executable out of it, and not have it install all the other parts, libraries, etc., over your working versions. You might for example have a tool installed which, in the latest version, is slightly unstable or crash-prone, but you know that the previous version was not that unstable. And, you might also in the process have upgraded a bunch of other things and dependencies etc. and not want to undo all that. Hence, you just want to extract the executable. Alternatively, another use case may be where you want a specific sourcecode file without extracting all of them, e.g. a specific kernel header file. Suppose your package is called to-install.rpm . mkdir unpack_folder/ mv to-install.rpm unpack_folder/ cd unpack_folder/ rpm2cpio to-install.rpm | cpio -idv The contents of the RPM should now be inside your folder. 

how to start up wildfly

 Wildfly is a server app to serve java apps. It's similar to JBoss and Tomcat. sudo -u apache /usr/local/wildfly/bin/standalone.sh -c=standalone-full-ha.xml &

splitting a pdf

 Suppose you want to take a 1000-page pdf called "input.pdf" and extract page 1, and 3 onwards, removing only page 2. Type the following:  pdftk  input.pdf  cat 1 3-end  output output.pdf

rsync

 Rsync is a useful utility to compare two folders and copy the differences. It works over ssh as well as on local disks, and it can also copy changes to files rather than whole changes. If you use it to copy one folder to another, it can also carry on where it leaves off, if you interrupt it. It is therefore better than other copy utilities. The general syntax for comparing folder A to folder B and copying the differences is: rsync -avu A/ B/ --progress If folder B is on a server, let's say, www.mywebsite.com, then,  rsync -avu A/ username@www.mywebsite.com:/var/www/B/ --progress --rsh="ssh -p22" Assuming ssh answers on port 22 and your folder B is located in /var/www/ Note that it is imperative that you put a forwardslash (/) after both folder names. If you don't do that, it will copy one folder into the other. Note that you can also delete files that are not in the target. This is dangerous. Say you have folder A and B, and say folder A has items 1,2,3,4, and folder

managing ntfs drives on linux

You need the package ntfs-3g to manage ntfs drives on linux. When you attach an NTFS drive which was recently used on a windows computer, it might contain a sleep image and refuse to let you mount it writable. sudo apt-get [or yum] install ntfs-3g sudo ntfsfix /dev/sdb2 sudo ntfs-3g  /dev/sdb2 /mnt/ntfs/ -o remove_hiberfile assuming the drive is your second drive partition 2

managing HFS drives on linux

sudo apt-get install hfsprogs Next, mount or remount the HFS+ drive; commands need to be as follows: sudo mount -t hfsplus -o force, rw /dev/sdxY /media/mntpoint or sudo mount -t hfsplus -o remount, force, rw /mount/point Finally, if the drive was improperly unmounted or has otherwise become partially corrupted run fsck.hfsplus ... as msuch: sudo fsck.hfsplus -f /dev/sdXY where XY is the drive number and volume

delete files in bulk with spaces in their names

Different methods: xargs -d "\n" -I {} rm \"{}\" find . -name "*.txt" -print0 | xargs -0 rm find . -name "*.txt" -delete find . -name "*.txt" -exec rm {} +

find files based on modification date

  find /path/to/dir -newermt "date" find /path/to/dir -newermt "Feb 07" find /path/to/dir -newermt "yyyy-mm-dd" ## List all files modified on given date find /path/to/dir -newermt yyyy-mm-dd ! -newermt yyyy-mm-dd -ls # Assuming you want to find perl files: ### print all *.pl ### find /path/to/dir -newermt "yyyy-mm-dd" -print -type f -iname "*.pl"

finding an email address inside an mbox file

Assuming the mbox has been saved into a file called thefile.txt: grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" thefile.txt

Enable appleshare and sample iptables syntax

 Install netatalk if it is not installed already:  apt-get install netatalk [Debian-based] or  yum install netatalk [Redhat-based] service netatalk start The following syntax will enable appleshare over IP (linux only) iptables -A INPUT -i eno1 -p tcp --dport 548 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -o eno1 -p tcp --sport 548 -m state --state ESTABLISHED -j ACCEPT  

Find and delete when found

On the terminal, if you want to delete a lot of items at once without dragging them to the trashcan icon, type: find [source path] -name "*[whatever word you want to find]*" -delete Beware  this is not the same as dragging to the trash, it's permanent and non-recoverable. I'd suggest running this  first  to make sure it will delete the right things: find [source path] -name "*[whatever word you want to find]*" -print

bulk convert files from microsoft word to text

Find the soffice binary. In linux it will probably be /usr/local/bin/soffice.  This example is for apple.  ./Applications/LibreOffice.app/Contents/MacOS/soffice --convert-to txt --outdir ~john/Desktop/wordfiles/ ~john/Desktop/wordfiles/*doc The above will convert all wordfiles in the folder "wordfiles" on the desktop, to text files.

The purpose of this blog

The purpose of this blog is to post fixes for common linux or unix command line problems including the command line on Mac OS X.