A few more shell commands
8th July 2015Here are some Linux commands that I encountered in a feature article in the current issue of Linux User & Developer that I had not met before:
cd -
This returns you to the previous directory where you were before with having to go back through the folder hierarchy to get there and is handy if you are jumping around a file system and any other means is far from speedy.
lsb_release -a
It can be useful to uncover what version of a distro you have from the command line and the above works for distros as diverse as Linux Mint, Debian, Fedora (it automatically installs in Fedora 22 if it is not installed already, a more advanced approach than showing you the command like in Linux Mint or Ubuntu), openSUSE and Manjaro. These days, the version may not change too often, but it still is good to uncover what you have.
yum install fedora-upgrade
This one can be run either with sudo or in a root session started with su
and it is specific to Fedora. The command performs an upgrade of the Fedora distro itself, and I wonder if the functionality has been ported to the dnf
command that has taken over from yum. My experiences with that in Fedora 22 so far suggest that it should be the case, though I need to check that further with the VirtualBox VM that I have created.
Controlling clearance of /tmp on Linux systems
19th June 2015While some may view the behaviour in a less favourable, I always have liked the way that Linux can clear its /tmp
directory every time the system is restarted. The setting for this is in /etc/default/rcS
and the associated line looks something like:
TMPTIME=0
The value of 0 means that the directory is flushed completely every time the system is restarted, but there are other options. A setting of -1 makes the directory behave like any other one on the system, where any file deletions are manual affairs. Using other positive integer values like 7 will specify the number of days that a file can stay in /tmp
before it is removed.
What brought me to this topic was the observation that my main Linux Mint system was accumulating files in /tmp
and the cause was the commenting out of the TMPTIME=0
line in /etc/default/rcS
. This is not the case on Ubuntu, and using that is how I got accustomed to automatic file removal from /tmp
in the first place.
All of this discussion so far has pertained to PC's where systems are turned off or restarted regularly. Things are different for servers of course and I have seen tools like tmpreaper
and tmpwatch
being given a mention. As if to prove that there is more than one way to do anything on Linux, shell scripting and cron
remain an ever present fallback.
Restoring GRUB for dual booting of Linux and Windows
11th April 2015Once you end up with Windows overwriting your master boot record (MBR), you have lost the ability to use GRUB. Therefore, it would be handy to get it back if you want to start up Linux again. Though the loss of GRUB from the MBR was a deliberate act of mine, I knew that I'd have to restore GRUB to get Linux working again. So, I have been addressing the situation with a Live DVD for the likes of Ubuntu or Linux Mint. Once one of those had loaded its copy of the distribution, issuing the following command in a terminal session gets things back again:
sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda
When there were error messages, I tried this one to see if I could get additional information:
sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda --recheck
Also, it is possible to mount a partition on the boot drive and use that in the command to restore GRUB. Here is the required combination:
sudo mount /dev/sda1 /mnt
sudo grub-install --root-directory=/mnt /dev/sda
Either of these will get GRUB working without a hitch, and they are far more snappy than downloading Boot-Repair and using that; I was doing that for a while until a feature on triple booting appeared in an issue of Linux User & Developer that reminded me of the more readily available option. Once, there was a need to manually add an entry for Windows 7 to the GRUB menu too and, with that instated, I was able to dual-boot Ubuntu and Windows using GRUB to select which one was to start for me. Since then, I have been able to dual boot Linux Mint and Windows 8.1, with GRUB finding the latter all by itself. Since your experiences too may show this variation, it's worth bearing in mind.
Turning off Apport crash reporting on Ubuntu
6th April 2015Last week, I kept getting a multitude of messages from Ubuntu's crash reporting tool, Apport. So many would appear at once on reaching the desktop session during system start-up that I actually downloaded an installation ISO disk image intending to perform a fresh installation to rid myself of the problem. In the end, it never came to that because another remedy produced the result that I needed.
Emptying /etc/crash was a start, but it did not do what I needed, and I disabled Apport altogether. This meant editing its configuration file, which is named apport and is found in /etc/default/. The following command should open it up in Gedit on supplying your password:
gksudo gedit /etc/default/apport
With the file opened, look for the line with enabled=1
and change this to enabled=0
. Once that is done, restart Apport as follows:
sudo restart apport
This will need your account password before working, with any messages appearing afterwards. While I would not have done this for a real system problem, my Ubuntu GNOME installation was working smoothly, so it was the remedy I needed. The tool lets Ubuntu developers get information about application crashes, but it sends me to the Ubuntu Launchpad bug reporting website, which requires login details. This is enough to stop me continuing, making me wonder if developers could get what they need without this extra manual step. This would provide them with additional information and give us a more stable operating system in return.
Toggling the appearance or non-appearance of the Firefox session exit dialogue box
22nd March 2015One thing that I notice with Firefox installations in both Ubuntu and Linux Mint is that a dialogue box appears when closing down the web browser asking whether to save the open session or if you want to have a fresh session the next time that you start it up. Initially, I was always in the latter camp, but there are times when I took advantage of that session saving feature for retaining any extra tabs containing websites to which I intend to return or editor sessions for any blog posts that I am still writing; sometimes, composing the latter can take a while.
To see where this setting is located, you need to open a new tab and type about:config in the browser's address bar. This leads to advanced browser settings, so you need to click OK, answering a warning message, before proceeding. Then, start looking for browser.showQuitWarning
using the Search bar; it acts like a dynamic filter on screen entries until you get what you need. On Ubuntu and Linux Mint, the value is set to true but false is the default elsewhere; unlike Opera, Firefox generally does not save sessions by fault unless you tell it to that (at least, that has been my experience anyway). Setting true to false or vice versa will control the appearance or non-appearance of the dialogue box at browser session closure time.
Turning off Advanced Content Filtering in CKEditor
3rd February 2015On one of my websites, I use Textpattern with CKEditor for editing of articles on there. This was working well until I upgraded CKEditor to a version with a number of 4.1 or newer because it started to change the HTML in my articles when I did not want it to do so, especially when it broke the appearance of the things. A search on Google revealed an unhelpful forum exchange that produced no solution to the issue so I decided to share one on here when I found it.
What I needed to do was switch off what is known as Advanced Content Filtering. It can be tuned but I felt that would take too much time so I implemented something like what you see below in the config.js with the ckeditor folder:
CKEDITOR.editorConfig = function( config ) {
config.allowedContent = true;
};
All settings go with the outer function wrapper and setting the config.allowedContent property to true within there sorted my problem as I wanted. Now, any HTML remains untouched and I am happy with the outcome. It might be better for features like Advanced Content Filtering to be switched off by default and turned on by those with the time and need for it, much like the one of the principles adopted by the WordPress project. Still, having any off switch is better than none at all.
Migrating a virtual machine from VirtualBox to VMware Player on Linux
1st February 2015The progress of Windows 10 is something that I have been watching. Early signs have been promising, and the most recent live event certainly contained its share of excitement. The subsequent build that was released was another step in the journey, though the new Start Menu appears more of a work in progress than it did in previous builds. Keeping up with these advances sometimes steps ahead of VirtualBox support for them, and I discovered that again in the last few days. VMware Player seems unaffected, so I thought that I'd try a migration of the VirtualBox VM with Windows 10 onto there. In the past, I did something similar with a 32-bit instance of Windows 7 that subsequently got upgraded all the way up to 8.1, but that may not have been as slick as the latest effort, so I thought that I would share it here.
The first step was to export the virtual machine as an OVF appliance, and I used File > Export Appliance... only to make a foolish choice regarding the version of OVF. The one that I picked was 2.0 only to subsequently discover that 1.0 was the better option. The equivalent command line would look like the following (there are two dashes before the ovf10 option below):
VboxManage export [name of VM] -o [name of file].ova --ovf10
VMware has a tool for extracting virtual machines from OVF files that will generate a set of files that will work with Player and other similar products of theirs. It goes under the unsurprising name of OVF Tool and usefully works from a command line session. When I first tried it with an OVF 2.0 files, I got the following error, and it stopped doing anything as a result:
Line 2: Incorrect namespace http://schemas.dmtf.org/ovf/envelope/2 found.
The only solution was to create a version 1.0 file and use a command like the following:
ovftool --lax [name of file].ova [directory location of VM files]/[name of file].vmx
The --lax option is needed to ensure successful execution, even with an OVF 1.0 file as the input. Once I had done this on my Ubuntu GNOME system, the virtual machine could be opened up on VMware Player and I could use the latest build of Windows 10 at full screen, something that was not possible with VirtualBox. This may be how I survey the various builds of the operating that appear before its final edition is launched later this year.
Sorting a stalled Windows Update service
30th January 2015Following a recent family death, I have ended up with the laptop belonging to the deceased and, since it has been offline most of its life, I set to getting it updated. The McAfee security suite was straightforward enough but trying Windows Update produced errors suggesting that it was not working and that a system restart was needed. Doing that did nothing, so a little further investigation was needed.
The solution turned out to be stopping the Windows Update service and clearing a certain folder before starting it again. To stop the service, I typed in services.msc
into the search box on the Start Menu and clicked on the entry that appeared, which was called Services. Then I sought out the Windows Update entry, selected it and clicked on the Stop link on the left-hand side. After that, I used Windows Explorer to navigate C:\Windows\SoftwareDistribution
and deleted everything in there. The, I went back to the Services window and started Windows Update again. That sorted the problem and the system began to be updated as needed.
All of this was on Windows 7, hence the mention of the Start Menu, and the machine is a Toshiba Satellite C660 from 2011 with an AMD E-300 APU, 4 GB of RAM and a 320 GB hard drive. Those specs may not be the most impressive, but it feels spritely enough and is far better than the lethargic Toshiba Equium A200-1VO that I acquired in 2008, though the HP Pavilion dm4 that I bought in November 2011 probably will travel more often than either of these if truth be told. After all, it now has 8 GB of RAM and a 1 TB Samsung SSHD along with its Core i3 CPU, so it should serve me for a while yet.
Upgrading a 2012 Google Nexus 7 to Android 5.0
19th November 2014Today, I was lured into upgrading my 2012 Google (ASUS) Nexus 7 to the final version of Android 5.0 (also known as Lollipop) by an icon in the device's top panel. Initially, it felt as it was working OK but a certain sluggish could not be overlooked and there have been complaints about this with some questioning the sense of what Google has done. However, there would have been remarks about grandfathering the device if they had not left us to have the latest release of Android, so there was no victory either way. We humans are fickle creatures, and there is an example of exactly that in a well observed double-ended short story by the Irish writer Maura Laverty.
While my impressions of how the upgrade had lumbered the tablet had me wondering about replacing the thing with either an Apple iPad Mini 2 or a Google (HTC) Nexus 9, a much less expensive option came to mind: doing a full factory reset of the device using its recovery mode. Though that may sound drastic, much of what I had on there was in the cloud anyway, so there was nothing to lose. So these are the instructions from Google themselves and I will leave you to use them at your own risk:
- If your tablet is on, turn it off.
- Press and hold the Volume Down button, then press and hold the Power button at the same time until the tablet turns on. You'll see the word "Start" with an arrow around it.
- Press the Volume Down button twice to highlight "Recovery mode".
- Press the Power button to start Recovery mode. You'll see an image of an Android robot with a red exclamation mark and the words "No command."
- While holding down the Power button, press the Volume Up button.
- Use the volume buttons to scroll to "wipe data/factory reset," then press the Power button to select it.
- Scroll down to "Yes - erase all user data," then press the Power button to select it.
Note: If your tablet becomes unresponsive at any point during these steps, you can restart it by holding down the Power button for several seconds.
Once that was completed and the tablet restarted, the set-up routine began and took around an hour to reinstate the various apps that had been lost by the rest. Much of that was down to the time taken for re-installation rather than that taken by the actual downloads themselves over a wired broadband connection. The wait was worth it because the Nexus 7 feels more responsive again. While there are times when little lags are noticeable, they are nothing next to the slowdown that I had witnessed before the rest. It might have been a better option than attempting to return to Android 4.4.4 using a factory image, which was another option that I was considering. So long as there is no deterioration in speed, the effort expended to do a reset will have been worthwhile.
Smarter file renaming using PowerShell
14th November 2014It appears that the Rename-Item commandlet in PowerShell is a very useful tool when it comes to smarter renaming of files. Even text substitution is a possibility, and what follows is an example that takes the output of the Dir
command for listing the files in a directory and replaces hyphens with underscores in each one.
Dir | Rename-Item –NewName { $_.name –replace “-“,”_” }
The result is that something like the-file.txt becomes the_file.txt. This behaviour is reminiscent of the rename
command found on Linux and UNIX systems, where regular expressions can be used, like in the following example that has the same result as the above:
rename 's/-/_/g' *
In both cases, you do need to be careful as to what files are in a directory for this, though the wildcard syntax on Linux or UNIX will be more familiar to anyone who has worked with files via almost any command line. Another thing to watch in the UNIX world is that *
parses the whole directory structure, and that could be something that is not wanted for much of the time.
All of this is a far cry from the capabilities of the ren
or rename command used in the days of MS-DOS and what has become the legacy Windows command line. Apart from simple renaming, any attempt at tweaking a filename through substitution ended up with the extra string getting appended to filenames when I tried it. Thus, the PowerShell option looks better in comparison.