> For the complete documentation index, see [llms.txt](https://tester-bszelag.gitbook.io/software-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tester-bszelag.gitbook.io/software-testing/ubuntu.md).

# Ubuntu

Start works with linux - Ubuntu.

#### Main documentation: <https://help.ubuntu.com/>

## How to install Ubuntu on VirtualBox

{% content-ref url="/pages/-MENDRkAckGDtrfn3JLo" %}
[VirtualBox](/software-testing/ubuntu/virtualbox.md)
{% endcontent-ref %}

## First steps with terminal

```bash
#Shortcut to OPEN terminal
ctrl + alt + t

#Shortcut to CLOSE terminal
ctrl + d

#Kill the terminal proccess
cltr + c

#Auto completion of files names
use TAB while you are typing any name of file
```

## Shortcuts

```bash
ctrl + A    #move your cursor to the beginning of the line
ctrl + E    #move your cursor to the End of the line
alt + C     #convert Capital character of word on Uppercase and rest on Lowercase
alt + L     #convert all characters beggining from the cursor on Lowercase
alt + U     #convert all characters beggining from the cursor on Uppercase
ctrl + K    #Cut the text from the cursor to the end of the line (Kill text)
ctrl + U    #Cut the text from the cursor to the beggining of the line
ctrl + Y    #Paste the text that you did cut (Yanking text)
```

## Basic terminal commands

### help

help command will help us how to use a parameters

```bash
help cd
help rm

cd --help
rm --help
```

![Used cd --help command](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-METoHcHrt-CLEtkWvQt%2F-METpUSsVnuj6GqbLCnT%2Fimage.png?alt=media\&token=d53724f5-dec8-4ea2-a159-67e080fbddb1)

### man

* manual page of commands (like help, but better graphical)

```bash
man cp
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEWbkUNXHPMRRPyeSOO%2F-MEWcty4q7z3xXc3LxZB%2Fimage.png?alt=media\&token=aca9c02b-518b-4d25-9db3-d5b37f4491b3)

### whatis

* short description of linux commands

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEWdrxuaBUqfDG76oF9%2F-MEWeAI6n9EOtx07Peut%2Fimage.png?alt=media\&token=dd820408-3d0d-4e2d-b2ae-954bab3c0aef)

### history

* show history of commands used in terminal
* the whole bash history is in file \~/.bash\_history

```bash
history #show you whole history of terminal

history 20 #limited by number like 5, 20, 100 ...

history -c #clean whole history (be careful)

!412 #if u type it in console just it use 412 command from history list
412 -> git clone https://github.com/testerBartek/GIT

#to look on file with history
gedit ~/.bash_history
```

![show list of used commands](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEUWjx21Km9LHeggiSz%2F-MEUYDXrlaP_rMiy8c-c%2Fimage.png?alt=media\&token=4f366863-481c-457c-90d9-e723bd35752a)

### pwd

print working directory

![Show our current path](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MERvfW98LiZiWt6oJ9Y%2F-MES-4RB0JXbNQFfleBH%2Fimage.png?alt=media\&token=08556da0-ed52-454f-8201-d3068d17ac27)

### cd

change directory

```bash
cd Desktop/      #path to cd
cd ..            #previos level of directory   
cd /             #go to root dir 
cd ~             #go to home/USER dir
cd -             #back to previous dir (in memory)
```

![cd commands](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MERvfW98LiZiWt6oJ9Y%2F-MES-eX9qd6vm1HzwefS%2Fimage.png?alt=media\&token=0f5259b4-2392-490f-b26c-ea0b062ec685)

### echo

* print a wrote text

```bash
echo texttoprint
>testtoprint
```

### gedit

* graphical text editor
* create a new file and start to edit
* edit current file&#x20;

```bash
gedit test #open a text editor
#you can close it, write something, save

#after you close editor, you can back to terminal
```

### nano

* terminal text editor

```bash
nano test #open file in terminal

#you are allow to edit it

#^G ^O ^W => ctrl+G ctrl+O ctrl+W ...
```

![nano looks like](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEUTPxMfI0qL475wXDA%2F-MEUWVlRy0btXsQ5Xspe%2Fimage.png?alt=media\&token=2ac32749-6459-4067-9ba9-26b22f3d9dd0)

### cat / tac

* show text in the same window of terminal

```bash
cat test #normal text
tac test #reverse 
```

![cat and tac commands](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEU_7yYn4QVxWqBBB3a%2F-MEUaLkj7mUoUZ4_C5tb%2Fimage.png?alt=media\&token=9e9d1753-ccbe-4043-becc-4eed607a8ad8)

### head / tail

* head print first lines from the file
* tail print the last lines from the file

{% hint style="info" %}
\[TIP]     to create 30 or more lines of numbers use command:

```bash
for((i=1;i<=30;i++)); do echo $i >> 30lines; done
```

{% endhint %}

```bash
t   ail 30lines     #tail FILE_NAME
head 30lines     #head FILE_NAME
#default command print 10 lines

tail -5 30lines  #-5 it's parameter how much lines to print
head -8 30lines
tail -n 5 30lines
```

![tail and head commands](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEUaPVGV0gkIc7cbhuU%2F-MEUd-BGQW1Bb3pujd9U%2Fimage.png?alt=media\&token=4738a729-e67a-435b-b99a-fc577f659fcc)

### wc

* show line number , word number , byte/character numbers&#x20;

```bash
wc test #wc FILE_NAME
 9  60 390 test
 #9 -> line number
 #60 -> word number
 #390 -> character numbers
 
 wc -l  #only show line number
 wc -w  #only show word number
 wc -c  #only show character number
 wc -L  #show the characters of the longest line!
```

### ls

* list a directory content

```bash
# Basic ls commands
ls           # list a dir
ls /         # list root dir
ls ~         # list home dir
ls ..        # list previous dir files
```

![basic ls commands](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MERvfW98LiZiWt6oJ9Y%2F-MES1zerNpB7pRLkP9xJ%2Fimage.png?alt=media\&token=30d86269-7a97-41a4-b938-ba5f7b82f273)

```bash
ls -i        # inode number
ls -l        # file size in bytes, date and time of modifications
```

![green - inode number | blue file size in bytes](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESGv4U9zXcFFcaGpGN%2F-MESSKehnm0nmMbYtq7_%2Fimage.png?alt=media\&token=938199b6-875e-417a-84bb-8692639a607e)

```bash
ls -a        # show every files (.hidden too)
ls -t        # show by last modificated files
ls -r        # reverse order (normal ls from A to Z, with -r from Z to A)
ls -R        # showing every dir and everything what is inside
```

{% hint style="info" %}
hidden files always have dot "." before name like .hidden
{% endhint %}

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESGv4U9zXcFFcaGpGN%2F-MESRwJlO5i1rBuJQkxZ%2Fimage.png?alt=media\&token=6af95a25-f6aa-4214-95bb-d3db5b5c0b59)

```bash
#every parameters we could mix
ls - ali = ls -ail = ls -ial = ls -ila = ls -lia = ls -lai 

ls -tr       # reverse time
ls -ltr      # reverse time and show file size
ls -latR     # show .hidden files, file sizes, show by last modificated files
                #and every files inside directories
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESGv4U9zXcFFcaGpGN%2F-MESSqkgr2NRoAUgm4fo%2Fimage.png?alt=media\&token=9cc2704e-9e8b-4f24-a3be-cc5e8af2088c)

### ln

#### Hard Link

* the same inode number&#x20;
* the exactly same size of file

```bash
ln example hardlink1
```

![3 the same files by Hard Link](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MES4DyucEb1iR7Q3OkH%2F-MES7YPVkG65sp1OXUdp%2Fimage.png?alt=media\&token=261fa9b5-1d5b-4f76-8679-7e499e92e987)

#### Soft Link

(it's the same as shortcut in windows)

* different inode number
* smaller file size - only 8 bites

```bash
ln -s example softlink1
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MES4DyucEb1iR7Q3OkH%2F-MES8Ub2uxSQz0lZ1QOs%2Fimage.png?alt=media\&token=d253f99d-004b-4ec6-803e-426d3160ec28)

{% hint style="warning" %}
Create soft link to directory is possible but hard link isn't.
{% endhint %}

## Files commands

### touch

* change timestamp of a file on current date and time
* create a new file

```bash
touch FILE_NAME
touch example
```

![All hard linked files change timestamp like example/hardlink1/hardlink2](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESXXXYayQoibRLK20W%2F-MESXkiQQf-5KwvcIKqf%2Fimage.png?alt=media\&token=97964155-2059-42c9-b2f6-fa1030bc67e6)

![Create a new file](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESY3lYDuuRjQSHneO_%2F-MESYk3I2dyUKyfZijkl%2Fimage.png?alt=media\&token=15cd560b-f461-4383-ad27-2b01cd6efb44)

### mkdir

* create an empty directory

```bash
mkdir nameOfDir
```

### rmdir

* remove an empty directory

```bash
rmdir nameOfDir
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESYo9OsGP4ylu6_Beo%2F-MESgqzEZA2Tg2VU9srY%2Fimage.png?alt=media\&token=b17ca639-63a1-41fb-9685-bd3a9ed4847b)

{% hint style="warning" %}
remove not empty directory isn't possible
{% endhint %}

### rm

* remove a files and directories with files

```bash
rm file1        #remove file
rm -R dir1      #remove directory
rm -r dir1      #remove directory
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESYo9OsGP4ylu6_Beo%2F-MESjIby6xwD6L-4AjhP%2Fimage.png?alt=media\&token=be2f1e8b-bb14-44f5-a92a-d498cbcceb62)

```bash
rm -i file1     #ask about remove the file
rm -iR dir1     #ask to remove every single file
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESYo9OsGP4ylu6_Beo%2F-MESkrNnT-Zhc5-Kn3ZX%2Fimage.png?alt=media\&token=e4b23e8b-bcc0-4a13-a0c9-3fa3df10800d)

```bash
rm -f file1    #remove force file
rm -fR dir1    #remove force dir 

#you can use it on not existing file 
#and logs don't give any information about this
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESYo9OsGP4ylu6_Beo%2F-MESmteHJ1QM-AyWAZMc%2Fimage.png?alt=media\&token=b9038c79-904b-4819-8ce8-99de51176302)

```bash
rm -v file1 file2     #remove file with information about it
rm -vR dir1           #remove directory with information about it
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESYo9OsGP4ylu6_Beo%2F-MESoJ9xNZM1eKhxV1mo%2Fimage.png?alt=media\&token=aef1f10a-386c-4a58-ad92-3e8e6dcbe2b4)

### cp

* copy files

```bash
#command scheme
#cp file1 file2 ... file99 ... dir1 [the last is destination]
cp file1 file2         #copy file1 and paste in file2
cp file1 file2 dir1    #copy file1 file2 and paste it in dir1
cp -R dir2 dir1        #copy dir use -R
cp -i file1 file2      #ask about overwirte files
cp -vr dir1 dir2       #show logs about the files
```

{% hint style="danger" %}
Be careful file could be overwrite !
{% endhint %}

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MESrjODc_sPbvEPUC52%2F-MEStCOwDsTgqNHeb_MZ%2Fimage.png?alt=media\&token=b4381e86-4f2f-4af5-9c88-659d07db9916)

### mv

* move files
* renaming files

```bash
mv oldfilename newfilename     #changing name of file
mv hiddenfile .hiddenfile      #make hidden file
mv file1 file2 dir1            #move file1 and file2 to directory
mv -i file1 dir1               #ask to confirm overwrite file
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEStXQQ4TnvN_5sJ5kt%2F-MESwy51qtoKAtocDCrQ%2Fimage.png?alt=media\&token=366be01e-5166-4721-ab50-f6729ee05e15)

### file

check properties and file extension

```bash
file file1 cat earth
file file1
```

![After delete file extension in Ubuntu still possible is correctly opening files ](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MET7vGKTv3jzGU6TnqA%2F-METVQ6iIdBf6lWhXAZ6%2Fimage.png?alt=media\&token=b39db4af-c7bd-4d6c-ad77-2db0eec3548f)

### which / type

* which -> print path to another command like cp / ls ...\
  \[display an Executable's location]
* type -> print path to another command and show is this command is shell builtin

Types of commands:\
1\. Executable Programs\
2\. Shell builtins\
3\. Shell scripts\
4\. Alias

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEW_P6ZV94kDn_-vOBu%2F-MEWb57V1Sb962ZspbwA%2Fimage.png?alt=media\&token=ea7e43c8-d6a5-4f82-98a3-a55f36aa4d21)

## Filenames with space and special characters

Create file and directory with space or special characters

special characters like: $, >, <, &, ;, |, ', " ...

```bash
mkdir'text with space'
mkdir "text with space2"
touch text\ with\ space3

touch'$%@ text with special characters $!@#'
mkdir $\%\>\special\ character
mkdir \\ #show only 1. \
```

![Spacebar](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-METgaHS_FhYKO-Tk5vs%2F-METjg09vxeQnrOTpDVi%2Fimage.png?alt=media\&token=23fa7697-4133-4974-bfda-e1ea02c4f9dd)

![Special characters](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-METjtqtQ9eSK5Qq4Gpd%2F-METoAv-XrTaFSWrVizh%2Fimage.png?alt=media\&token=b3669895-ed03-433b-8054-970f532e6521)

## Own commands

### multiple commands

* use more than 1 command in one time

```bash
1stcommand; 2ndcommand; ...;nthcommand

1stcommand && 2ndcommand && ...&&nthcommand 
#if command is incorrect the rest of commands will not execute

#USABLE
#1. create dir 2. create file 3. move file to new directory
mkdir dir1; touch file; mv file dir1
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEWnpMIrp9E-wuOR6t-%2F-MEWoRO4wYdq0AuoIDgr%2Fimage.png?alt=media\&token=8a0b1553-b67e-4057-bb2a-8961c788d7e1)

### wildcards

#### '\*' and '?'

* wildcard is a symbol that represents one or more characters
* symbol '\*' represents (matches) ANY characters
* symbol '?' represents (matches) a SINGLE character

```bash
#FILES: file1.txt file1 file11
# file2 file2.txt abcd qwerty uiop dir1

#'*'
1. cp file* dir1    #copy files file... [file1 / file1.txt ...]
2. cp *.txt dir1    #copy files ....txt [file1.txt / file2.txt]
3. cp f* dir1       #copy files on f... [file1.txt file1 ...]
4. cp f*t dir1      #copy files on f...t [file1.txt / file2.txt]
5. rm *             #remove all

#'?'
1. cp file?.txt dir1
2. cp f???? dir1
```

!['\*' and '?' wildcards in use](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEWpynmfRg93-I7tmjU%2F-MEX8wADVoYSO3eSLhP7%2Fimage.png?alt=media\&token=f0f0557f-c3cb-4140-88bc-3cc21896e113)

#### '\[RANGE]'

```bash
cp [abcd]* dir1      #copy files which start on letters a,b,c,d
cp [!abcd]* dir1     #copy files which aren't start on letters a,b,c,d
cp [1-3]* dir1       #copy files which start on numbers from 1 to 3 [1,2,3]
cp [[:upper:]]* dir1 #copy files which start from UPPER letter
cp [[:lower:]]* dir1 #copy files which start from low letter
cp *[[:digit:]] dir1 #copy files which ends on number
cp [[:alpha:]]* dir1 #copy files which starts on any letter (upper and lower)
cp [[:alnum:]]* dir1 #copy files which emds on alhpabet or numeric

```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEX98je_vuZcPHgJ83u%2F-MEXGepy6Tb9MKesyPHJ%2Fimage.png?alt=media\&token=efe7dae9-7c90-4943-898b-2609e7e7adb0)

### aliases

* help to works faster with use specific own commands

```bash
alias #type list of created alias
alias newcommandname="YourCommand" #create alias
alias newcommandname #use definied alias
unalias newcommandname #delete alias

gedit ~/.bashrc #file with aliases (edit / delete ...)
```

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MEXGwTCWbQU3tsjkI3W%2F-MEXUyUdUvpimbwQ9prB%2Fimage.png?alt=media\&token=bfc5f3ac-620c-4edc-9bde-a03043b349d2)
