5 hidden KDE commands for the command line
Tagged:

By default, KDE comes with a number of programs which may come in handy from time to time in the shell. It is possible to embed some KDE technology inside a script. This articles shows 5 commands which you will not encounter in your application menu: kdialog, kioclient, ktrash, kquitapp and kdebugdialog.

kdialog

The first command we look at is kdialog. This command enables you to generate simple dialogs, like a confirmation dialog or to show a Save As dialog.

Some examples:

To ask a Yes/No question you can enter the following command:

kdialog --yesno "Don\'t think, just press Yes."

And this is the result:

kdialog with a Yes/No question

You can check the return code of the kdialog command to determine which button was pressed (in this case: 0 means Yes and 1 means No).

To invoke the well-known Save As dialog use the following command::

kdialog --getsaveurl /tmp '*.jpg'

The last two parameters are optional. The first indicates the start directory and the second parameter the file extension which is to be saved (it is the filter, actually). The return code of the call indicates whether the user pressed OK or Cancel. The standard output shows the path chosen by the user.

For an overview of all features of KDialog you can pass the --help parameter. It offers enough possibilities to supply a shell script with some graphical user interface elements.

kioclient

The kioclient command allows you to execute file operations from the command line. Think of opening, copying and moving files.

For instance, you can open a remote PDF file with the following command:

kioclient exec sftp://bram@10.0.0.1/home/bram/manual.pdf

In this case I log in with SSH, so an authentication dialog pops up and after that the default PDF viewer is opened with that file. But of course you can use any other protocol as well.

One handy invocation is the following command:

kioclient exec .

It will open the current working directory in your default file manager.

There's a separate command which does exactly the same: kde-open.

There are a couple of other sub commands inside kioexec:

  • copy Copy one or more files. An equivalent command is also available: kde-cp.
  • move Move one or more files. For example, it allows you to move a file to trash:
    kioclient move ./file.bak.orig~ trash:/

    An equivalent command is also available: kde-mv.

  • cat Shows the contents of a file on the standard output.
  • download Download the file to a given location.
  • openProperties Open the Properties dialog for a folder or file.

The beauty of these commands it that all protocols can be used. It is possible to download a file from the internet (http://) and to save it directly to a remote computer (sftp://).

ktrash

This command allows you to empty the trash from the commandline:

ktrash --empty

Or, you can also restore a file in the trash to its original location:

ktrash --restore oops.txt

kquitapp

Use this command if you want to quit a KDE application gracefully. This won't work if the program is in a locked state. In that case there's still kill.

kdebugdialog

kdebugdialog is a small application which allows you to orchestrate the debug output of KDE applications. If you execute it you'll see the following dialog:

kdebugdialog

In this dialog you can choose whose debug output you would like to see when you execute a KDE application from the command line. This is useful if you wish to surpress some noise from other components when you are composing a bug report.

When you supply the parameter --fullmode you a more granular control over the debug output:

kdebugdialog in full mode

You can distinguish several message types per component (e.g. general information or error messages). You can redirect every message type to a different destination. You can redirect general information to the shell and error messages to a file. But, this level of control is seldom necessary.