Bash commands for a tester

Introduction

Most testers in their career will sooner or later have to deal with the terminal Linux

Most likely it will start as the need to log in to the server and look at the logs.

IT engineer in a server room bash for a tester image from the site www.andreyolegovich.ru
IT engineer in a server room. Photo: freepik.com

Servers are built on different operating systems:

From the family of Linux the following are popular:

UNIX-like OSes are also often used:

They differ a little from each other but there is also a common property:

A server usually has no graphical interface

But instead it has a command shell such as bash

That is exactly why a tester needs to master the basics of working with the Linux terminal.

In this article you will see the commands that a tester specifically needs. More useful commands can be found in the articles:

Working with directories

A tester constantly has to work with logs. Every bug found usually needs to be described both functionally: what does not work, what was done at the time, what the UI showed. And confirmed with documentation: a timestamp + client/server/partner backend logs.

Even if in some particular case logs are not needed, the developers will most likely ask for them - simply out of habit.

In order to find the logs, you need to be able to move between directories and look at their contents.

Viewing directories

To go to the directory with the logs, it is enough to enter the cd command and its absolute address.

For example:

cd /glassfish_domains/server_name/logs

If the absolute address of the directory is unknown, you need to move somewhere from the current directory.

You can find out the contents of the current directory with the command ls

For example

ls -la

where the option l requires output in the so-called long format.

The output will contain access rights, the number of hard links to the file , the owner, the group, the size, the time of the last change and the file name.

a is the option that requires showing hidden files - those whose names start with a .

You can move to a directory one level down with the command cd directory_name

cd testProject01

Go up one level

cd ..

Creating a directory

To create a directory, run the command:

mkdir directory_name

where directory_name is the directory that you want to create.

For example, let's create the directory test_Project2:

mkdir test_Project2

Copying a directory

To copy a directory from one place to another, run the command:

cp -a project01 project02

where project01 is the source (the directory you want to copy) and project02 is the destination (the directory you want to copy into) the -a key means that we are performing a non-recursive copy.

For example, let's copy the directory /usr/local/project01 to our home directory and name it project01arj:

cp -a /usr/local/project01 ~/project01arj

Moving / Renaming a directory

In Linux, the mv command is responsible for moving and renaming directories.

Let's look at examples:

moving the directory /usr/local/projects into the already existing project01arj directory in the home directory:

mv /usr/local/statistics ~/project01arj/

renaming the directory /usr/local/projects to /usr/local/testedProjects:

mv /usr/local/statistics /usr/local/newstatistics

Deleting a directory

Deleting a directory and its contents can be done with the rmdir or rm commands:

we delete the directory /usr/local/testedProjects/temp:

rmdir /usr/local/testedProjects/temp

or recursively the directory /usr/local/testedProjects/temp, with all the directories inside it:

rm -rf /usr/local/testedProjects/temp

Working with logs

Read more about what logs are and what kinds there are in the section «Learning about logs»

Viewing the latest logs

Often opening the whole file takes too long. In this case you can use the tail command

sudo tail -n 1000 ~/glassfish_domains/server/logs/project-name-2019-09-25.log

This command will output the last 1000 lines of the log.

Logs in real time

The -f option allows you to monitor changes in real time

sudo tail -f ~/glassfish_domains/server/logs/project-name-2019-09-25.log

If you want to cut out a certain range of lines from the log, read my article about text preprocessors:

How to cut lines from a log with SED

To count how many lines there are in the file latest.log use

wc -l latest.log

282608 latest.log

Article author: Andrei Olegovich