Posted in Linux commands

systemd, Part I

For my sensor network I run a server process, which collects the data from several sensors. This is a sort of a daemon. In a first version it was started in a crontab with the time “@reboot”. But during the development I had to restart it every now and then: search the PID, kill it, start it in the background.

Isn’t there a better way? systemd to the rescue. In this first systemd post I will install a service file, so that the process can be started and stopped from the root account.

Continue reading “systemd, Part I”

Posted in bash

Changing directories

Everyone knows the command cd – everyone uses it several times a day. (OK – not everyone, but every Linux user.) Most of us know, that we can change back to the last directory with

$ cd -

E.g.:

$ pwd
/home/maker/docs/sensors
$ cd /opt/sensors/bmp280
$ pwd
/opt/sensors/bmp280
$ cd -
$ pwd
/home/maker/docs/sensors

But what if you cd in your project directory and then need to change back into your docs directory? You have to type the whole path. Or do you?

Continue reading “Changing directories”

Posted in bash

Make and Change into Directory

Several times a day I have to create a directory and have immediately change into this directory. After a while I found it rather annoying to type every time

$ mkdir new_directory
$ cd new_directory

So I created a shell function to reduce the typing:

mcd ()
{
    mkdir -p "$@" && cd "$@"
}

Now I have to type only

$ mcd new_directory

and magically I’m in the newly created directory.

Posted in Linux commands

“find” with Style, Part 3: Displaying File Attributes

If you search files with the find command, you get a list of filenames:

$ find . -name '*.py'
./projekte/sensornet/bmp280/fill_bmp280.py
./projekte/sensornet/bmp280/baro.py
./github/pi_stuff/unsorted/cheerlights.py
./github/pi_stuff/sensornet/bmp280/baro.py
./progs/python/mqtt/mqtttest.py
./progs/python/database/get_last_bmp280.py

If you need the file attributes (like size, file permissions, …) you can do some tricks to let ls do the job. Or do you?

find has the parameter -ls which does this:

$ find . -name '*.py' -ls