apropos and whatis commands

As you know, each Unix/Linux distro comes with a massive set of man pages – helpful manuals for using pretty much every standard command found in your OS.

Quite often you don’t know the command though, but know what it should do. In such a scenario, apropos and whatis commands may come in handy.

Man pages database

There’s a special database (index) of man pages on your system, which indexes man pages and keeps a list of short 1-line descriptions of each command documented in a man page. This is how such a database looks in text form on a Ubuntu 16.04 Linux system:

...
ldap.conf (5) - LDAP configuration file/environment variables
adduser.conf (5) - configuration file for adduser(8) and addgroup(8) .
mailcap.order (5) - the mailcap ordering specifications
interfaces (5) - network interface configuration for ifup and ifdown
Compose (5) - X client mappings for multi-key input sequences
PAM (7) - Pluggable Authentication Modules for Linux
[ (1) - check file types and compare values
access.conf (5) - the login access control table file
accessdb (8) - dumps the content of a man-db database in a human readable format
add-apt-repository (1) - Adds a repository into the /etc/apt/sources.list or /etc/apt/sources.lis...
add-shell (8) - add shells to the list of valid login shells
addgroup (8) - add a user or group to the system
addpart (8) - tell the kernel about the existence of a partition
adduser (8) - add a user or group to the system
agetty (8) - alternative Linux getty
apropos (1) - search the manual page names and descriptions
apt (8) - command-line interface
...

Left side of the output lists command names, right side of the outout shows a brief command description. apropos and whatis commands work with these fields and allow you to search them.

Using whatis command

This command is useful when you want to confirm what a particular Unix command does. It searches man pages, but focuses specifically on the command names, rather than their descriptions.

For instance, if I know ls command, I would use whatis like this to find out more:

root@vps1:~# whatis ls
ls (1) - list directory contents

if I want to find similar commands, I can use the wildcard (in this example: all commands starting with ls combination):

root@vps1:~# whatis -w 'ls*'
ls (1) - list directory contents
lsattr (1) - list file attributes on a Linux second extended file system
lsb_release (1) - print distribution-specific information
lsblk (8) - list block devices
lscpu (1) - display information about the CPU architecture
lsinitramfs (8) - list content of an initramfs image
lsipc (1) - show information on IPC facilities currently employed in the system
lslocks (8) - list local system locks
lslogins (1) - display information about known users in the system
lsmod (8) - Show the status of modules in the Linux Kernel
lsof (8) - list open files
lspgpot (1) - extracts the ownertrust values from PGP keyrings and list them in GnuPG ow..

Using apropos command

apropos is useful when you don’t remember the command but may have a few keywords describing its functionality.

Using ls command from the previous examples, we can find it using “directory” keyword. Of coruse, searching for “directory” will find all the commands which have anything to do with directories, as shown below:

root@vps1:~# apropos directory
basename (1) - strip directory and suffix from filenames
bindtextdomain (3) - set directory containing message catalogs
chroot (8) - run command or interactive shell with special root directory
dbus-cleanup-sockets (1) - clean up leftover sockets in a directory
depmod.d (5) - Configuration directory for depmod
dir (1) - list directory contents
find (1) - search for files in a directory hierarchy
grub-macbless (8) - bless a mac file/directory
grub-mknetdir (1) - prepare a GRUB netboot directory.
helpztags (1) - generate the help tags file for directory
ls (1) - list directory contents
mklost+found (8) - create a lost+found directory on a mounted Linux second extended file system
mktemp (1) - create a temporary file or directory
modprobe.d (5) - Configuration directory for modprobe
mountpoint (1) - see if a directory or file is a mountpoint
pam_mkhomedir (8) - PAM module to create users home directory
pwd (1) - print name of current/working directory
pwdx (1) - report current working directory of a process
run-parts (8) - run scripts or programs in a directory
vdir (1) - list directory contents

See Also




VirtualBox 6.0 Beta 2

It’s great to see that Oracle VirtualBox is still being actively developed, not just maintained.

I have downloaded the latest beta of the upcoming VirtualBox 6.0 release, and it feels like a nice refresh of interface and functionality.

VirtualBox 6.0 Screenshots

See Also




How To: ls colorized output in MacOS

I’m pretty used to how ls command shows pretty colorized output on most modern Linux distros, but somehow its default behaviour in MacOS is still plain white – no different colours.

I decided to look for command line option to change that, and sure enough – ls command in MacOS has -G option for colorizing output.

So, instead of running this:

$ ls /etc

you’ll run this:

$ ls -G /etc

Check out the different it makes below!

Plain ls /etc in MacOS

2018-11-10_17-26-52.png

Colorized ls -G /etc in MacOS

2018-11-10_17-27-33.png

Make colorized alias for ls command

If you like this enough, I suggestt you make an alias for ls -G:

$ alias ls='ls -G'

what this does is you can run ls, but your bash shell will be recognizing it as alias name and running ls -G instead. Any additional command line options will work, of course:

2018-11-10_17-33-46.png

Add ls alias to .bash_profile

To make this permanent, add ls alias to your .bash_profile:

$ echo "alias ls='ls -G'" >> $HOME/.bash_profile

What this will do is any new Terminal windows you open on your Mac will have the ls command alias preconfigured, so you’ll always have the output colorized.

See Also




VMware Tools or Open VM Tools?

This post talks about VMware Tools and Open VM Tools – packages that help you improve performance and integration of your Unix-like virtual machines in VMware environments.

What are VMware Tools?

VMware Tools are a set of virtual machine enhancements providing tighter integration, smoother operation and much better performance for VMs running in VMware environment. VMware Tools are available for all the platforms supported by VMware, so there’s a separate installer for Windows, Linux and Solaris.

Usually you have to install VMware Tools using virtual CD drive mapped into each virtual machine – you find and run the installer, it installs and configures tools, you reboot and enjoy VMware Tools benefits.

Benefits of Using VMware Tools

  • tools are updated in line with vSphere upgrades (so when your virtualization hosts are upgraded, you get fully optimised tools available)
  • VMware Tools version is usually the same (if you upgrade in line with vSphere upgradesS)
  • VMware Tools version is reported in the vSphere Client and using vSphere CLI

What are Open VM Tools?

Open VM Tools ‘s actually an open-source version of VMware Tools, made specifically for Linux operating systems. As a result, open-vm-tools are bundled with most modern Linux distros or available from the standard repositories.

Open VM Tools are distributed with the following packages:

  • open-vm-tools
  • open-vm-tools-desktop
  • open-vm-tools-devel
  • open-vm-tools-debuginfo

Benefits of Using Open VM Tools

  • most reliable integrartion with the vendor OS (RedHat, for example)
  • no dependencies between vSphere version and Open VM Tools version
  • no need to wait for vSphere upgrade to install Open VM Tools updates
  • no need to have vSphere access for mounting virtual CD with VMware Tools

VMware Tools or Open VM Tools?

Speaking as a Linux sysadmin and not a vSphere administrator, I would prefer open-vm-tools: installing and troubleshooting them is fully done inside Linux VM, which means you can automate Open VM Tools deployment using native tools.

The same can be done for VMware Tools as well, but would require someone with vSphere access to assist.

See Also




Raspberry Pi OS

While you probably know that Raspbian is the official OS for Raspberry Pi systems, it’s not the only operating system you can use.

In fact, most of Raspberry Pi beginners start with NOOBSNew Out Of Box Software, which is an installer you can download or buy on an SD/microSD card from most of Raspberry Pi vendors.

In addition to this, there’s now a Raspberry Pi Desktop – special distribution that allows you to try Raspbian OS inside a virtual machine or using live USB environment.

See Also




mkdir cannot create directory

2018-11-05_19-00-09.png

New Linux users often get puzzled by the “mkdir: cannot create directory” errors when taking first steps and trying to learn basics of working with files and directories. In this short post I’ll show the two most common types of this mkdir error and also explain how to fix things so that you no longer get these errors.

mkdir: cannot create directory – File exists

This should be self explanatory after a few weeks of using commands like mkdir, but the first time you see this it can be confusing.

File exists? How can it be when you’re just trying to create a directory? And why does it say “File exists” when you’re trying to create a directory, not a file?

This error suggests that the directory name you’re using (/tmp/try in my example shown on the screenshot) is already taken – there is a file or a directory with the same name, so another one can’t be created. You can use the wonderful ls command to check what’s going on:

greys@vps1:~$ ls -ald /tmp/try
drwxr-xr-x 2 greys root 4096 Nov 5 18:55 /tmp/try

Sure enough, we have a directory called /tmp/try already!

The reason it says “File exists” is because pretty much everything in Unix is a file. Even a directory!

Possible solutions to mkdir: cannot create directory – file exists scenario

Rename (move) existing directory

Use the mv command to move /tmp/try into some new location (or giving it new name). Here’s how to rename /tmp/try into /tmp/oldtry:

greys@vps1:~$ mv /tmp/try /tmp/oldtry

Let’s rerun the mkdir command now:

greys@vps1:~$ mkdir /tmp/try

…and since there are no errors this time, we probably have just created the /tmp/try directory, as desired. Let’s check both /tmp/try and the /tmp/oldtry with ls:

greys@vps1:~$ ls -ald /tmp/try /tmp/oldtry
drwxr-xr-x 2 greys root 4096 Nov 5 18:55 /tmp/oldtry
drwxrwxr-x 2 greys greys 4096 Nov 5 19:08 /tmp/try

Remove existing file

Another option you always have is to simply remove the file that’s blocking your mkdir command.

First, let’s create an empty file called /tmp/newtry and confirm it’s a file and not a directory usng ls command:

greys@vps1:~$ touch /tmp/newtry
greys@vps1:~$ ls -lad /tmp/newtry
-rw-rw-r-- 1 greys greys 0 Nov 5 20:50 /tmp/newtry

Now, if we try mkdir with the same name, it will fail:

greys@vps1:~$ mkdir /tmp/newtry
mkdir: cannot create directory ‘/tmp/newtry’: File exists

So, to fix the issue, we remove the file and try mkdir again:

greys@vps1:~$ rm /tmp/newtry
greys@vps1:~$ mkdir /tmp/newtry

This time there were no errors, and ls command can show you that indeed you have a directory called /tmp/newtry now:

greys@vps1:~$ ls -lad /tmp/newtry
drwxrwxr-x 2 greys greys 4096 Nov 5 20:50 /tmp/newtry

mkdir: cannot create directory – Permission denied

This is another very common error when creating directories using mkdir command.

The reason for this error is that the user you’re running the mkdir as, doesn’t have permissions to create new directory in the location you specified.

You should use ls command on the higher level directory to confirm permissions.

Let’s proceed with an example:

greys@vps1:/tmp$ mkdir try2018
greys@vps1:/tmp$ mkdir try2018/anotherone
greys@vps1:/tmp$ ls -ald try2018
drwxrwxr-x 3 greys greys 4096 Nov 5 21:04 try2018

All of these commands succeeded because I first created new directory called try2018, then another subdirectory inside of it. ls command confirmed that I have 775 permissions on the try2018 directory, meaning I have read, write and execture permissions.

Now, let’s remove the write permissions for everyone for directory try2018:

greys@vps1:/tmp$ chmod a-w try2018
greys@vps1:/tmp$ ls -ald try2018
dr-xr-xr-x 3 greys greys 4096 Nov 5 21:04 try2018

If I try creating a subdirectory now, I will get the mkdir: cannot create directory – permissions denied error:

greys@vps1:/tmp$ mkdir try2018/yetanotherone
mkdir: cannot create directory ‘try2018/yetanotherone’: Permission denied

To fix the issue, let’s add write permissions again:

greys@vps1:/tmp$ chmod a+w try2018
greys@vps1:/tmp$ mkdir try2018/yetanotherone

As you can see, try2018/yetanotherone directory was successfully created:

greys@vps1:/tmp$ ls -ald try2018/yetanotherone
drwxrwxr-x 2 greys greys 4096 Nov 5 21:05 try2018/yetanotherone

That’s it for today! Hope you liked this tutorial, be sure to explore more basic Unix tutorials on my blog.

See Also




Unix Tutorial Digest – November 3rd, 2018

Monthly digest of Unix/Linux topics

This monthly issue arrives a week later, but brings more news as the result: lots of OS releases in October!

Please get in touch if you want to suggest a useful link for the next digest.

Unix and Linux News

Software News

  • Won’t mention software news this months as there are so many OS releases that they steal the show

Interesting and Useful

Unix Tutorial articles




screenFetch in CentOS

screenfetch-centos-unixtutorialMany of you liked the screenFetch command I have introduced a few weeks back. It’s a great utility native to most Debian based distros.

However, there’s a slight problem with CentOS and RedHat distros: they don’t have it in their standard repositories.

Turns out, it’s very easy to get it installed using git:

greys@centos:~ $ git clone https://github.com/KittyKatt/screenFetch.git
Cloning into ‘screenFetch’…
remote: Enumerating objects: 3873, done.
remote: Total 3873 (delta 0), reused 0 (delta 0), pack-reused 3873
Receiving objects: 100% (3873/3873), 3.98 MiB | 3.06 MiB/s, done.
Resolving deltas: 100% (2234/2234), done.
greys@centos:~ $ cd screenFetch/
greys@centos:~/screenFetch $ chmod a+rx screenfetch-dev

That’s it, now you can run ./screenfetch-dev to get the result shown at the top of this post!

See Also




find mtime: identify recent files in Unix

find command has a great operator for narrowing down the list of results: mtime.

as you probably know from the atime, ctime and mtime post, the mtime is a file property confirming the last time the file was modified.

find uses mtime option to identify files based on when they were modified.

Typical ways of using find mtime are shown below.

Find files modified in the last 24 hours

Thi can be useful for identifying current log files, like this:

greys@server:~ $ sudo find /var/log -mtime 0
/var/log/secure
/var/log/wtmp
/var/log/datadog
/var/log/datadog/trace-agent.log
/var/log/datadog/agent.log.329
/var/log/datadog/agent.log
/var/log/lastlog
/var/log/messages
/var/log/audit
/var/log/audit/audit.log
/var/log/audit/audit.log.1
/var/log/cron
/var/log/btmp
/var/log/grafana
/var/log/grafana/grafana.log
/var/log/grafana/grafana.log.2018-10-20.001

Each of the files from this list has been updated today. You can use the exec option of the find command to invoke ls command and show timestamps for each file:

greys@server:~ $ sudo find /var/log -mtime 0 -exec ls -ld {} \;
-rw------- 1 root root 1732312 Oct 20 17:18 /var/log/secure
-rw-rw-r--. 1 root utmp 105600 Oct 20 17:15 /var/log/wtmp
drwxr-xr-x 2 dd-agent dd-agent 4096 Oct 20 10:23 /var/log/datadog
-rw-r--r-- 1 dd-agent dd-agent 2639084 Oct 20 17:18 /var/log/datadog/trace-agent.log
-rw-r--r-- 1 dd-agent dd-agent 10485782 Oct 20 10:23 /var/log/datadog/agent.log.329
-rw-r--r-- 1 dd-agent dd-agent 6271115 Oct 20 17:18 /var/log/datadog/agent.log
-rw-r--r--. 1 root root 292876 Oct 20 17:15 /var/log/lastlog
-rw------- 1 root root 188372446 Oct 20 17:18 /var/log/messages
drwx------. 2 root root 4096 Oct 20 06:32 /var/log/audit
-rw------- 1 root root 2567908 Oct 20 17:18 /var/log/audit/audit.log
-r-------- 1 root root 8388638 Oct 20 06:32 /var/log/audit/audit.log.1
-rw------- 1 root root 41498 Oct 20 17:01 /var/log/cron
-rw------- 1 root utmp 6091392 Oct 20 17:14 /var/log/btmp
drwxr-xr-x 2 grafana grafana 4096 Oct 20 09:59 /var/log/grafana
-rw-r--r-- 1 grafana grafana 172 Oct 20 09:59 /var/log/grafana/grafana.log
-rw-r--r-- 1 grafana grafana 524 Oct 19 22:09 /var/log/grafana/grafana.log.2018-10-20.001

Find files modified more than 7 days ago

This doesn’t have to be 7 days, you can specify any number here. This command is useful for confirming which (log) files haven’t been modified for more than a week – it could mean they are safe to delete.

This is how a start of such a list would look (bear in mind I’m running this on October 20th, 2018):

greys@server:~ $ sudo find /var/log -mtime +7 -exec ls -ld {} \;
-rw------- 1 root root 2309193 Sep 23 03:29 /var/log/secure-20180923
-rw------- 1 root root 0 Oct 8 03:35 /var/log/maillog-20181014
-rw------- 1 root root 44268 Sep 30 03:50 /var/log/cron-20180930
drwxr-xr-x. 2 root root 4096 Sep 18 2017 /var/log/anaconda
-rw-------. 1 root root 0 Jan 19 2018 /var/log/anaconda/syslog
-rw-------. 1 root root 0 Jan 19 2018 /var/log/anaconda/program.log
-rw-------. 1 root root 0 Jan 19 2018 /var/log/anaconda/journal.log
-rw-------. 1 root root 0 Jan 19 2018 /var/log/anaconda/anaconda.log
-rw-------. 1 root root 0 Jan 19 2018 /var/log/anaconda/X.log

Find all the files modified in the last 30 days

Again, this doesn’t have to be exactly 30 days, it can be any number. I’m using 30 because it’s roughly 1 month and is a round enough number for backup/restore points.

Here I’m checking what’s been updated in my home directory in the past 30 days:

greys@server:~ $ sudo find /home/greys -mtime -30 -exec ls -ld {} \;
drwx------ 4 greys greys 4096 Sep 21 21:30 /home/greys
-rw------- 1 greys greys 7335 Oct 20 17:22 /home/greys/.bash_history
-rw------- 1 greys greys 162 Sep 21 21:30 /home/greys/.Xauthority

See Also

 




How To: Update VM title with virsh

Use virsh desc command to update VM title in KVM

I’m updating and migrating the last few of virtual machines on one of my servers, and realised that there’s a virsh list command option that I really like: it shows descriptive titles in addition to just listing virtual machines.

You know, how we usually run virsh list to see the VMs currently running on a server?

root@s2:/ # virsh list
Id Name State
----------------------------------------------------
1 elk running
4 dbm1 running
6 v9.ts.im running
9 infra running

Well, these VM names aren’t terribly informative. So I like using the virsh list –title command to show the list of VMs with their proper titles:

root@s2:/ # virsh list --title
Id Name State Title
----------------------------------------------------------------------------------
1 elk running Elastic + Logstash + Kibana
4 dbm1 running
6 v9.ts.im running wiki [4vCPU 4GB]
9 infra running infra [4 vCPU 4GB]

And if any VMs are not showing descriptive titles yet, it’s very easy to add it (–live means “apply to the running instance of the VM” and –config means “update the VM information on the disk”). Here’s an example forth dbm1 VM:

root@s2:/ # virsh desc dbm1 --title "MariaDB server [4vCPU 4GB]" --live --config
Domain title updated successfully

…and if we check again, dbm1 VM is now sporting a brand new description:

root@s2:/ # virsh list --title
Id Name State Title
----------------------------------------------------------------------------------
1 elk running Elastic + Logstash + Kibana
4 dbm1 running MariaDB server [4vCPU 4GB]
6 v9.ts.im running wiki [4vCPU 4GB]
9 infra running infra [4 vCPU 4GB]