User Tools

Site Tools


Introduction to Bash

The object of this document is the use of Bash language to explore and manipulate files rather than to set/interact with the operation system.
You can read and follow the text. At the same time you can copy the commands included in the frames part of this document and paste them into an interactive Bash shell.
Once you have familiarity with the general commands of Bash you can further advance in learning bash with online manuals and guides. There is a large variety of documentation available at:

A very useful summary of the most important commands can be found on ~/ost4sem/reference/UnixLinux_command_reference_card.pdf . It is recommended to print and use it during the course.
The best way is just to try each command using a file, and/or search on the Internet for more examples and deeper explanations.

Searching for a command, getting help, running a command, saving a result

Searching for a command, getting help

In a Shell window (the terminal) the following prompt is written:


after the $ you are able to insert the command
Command syntax:

 command [option] [file]

The symbol [] identifies an optional feature of the command. It can be inserted to retrieve more information or different setting of a command.
To get a command for a specific action type “apropos thewordthatyouneed”.
e.g. I want to search for a command able to count the line in a file

   man -k count

in the last lines you get:
“wc (1) - print newline, word, and byte counts for each file”
so the command “wc” is your command
To get information about a command type “man command” or info “command” e.g.

   man wc


   info wc

To exit from the help press “q”

Running a command, saving a result

The symbols > are used to save the result of a command in a file.
Instead < is used to retrieve information from a file.

In this case, using the informatics terminology we can use the expression “standard input and output redirection”.

This page summarize the Standard Input and Output Redirection common used.

In this course we will mainly use the symbol > > > <. e.g.

   ls > mylist.txt

it will save the file names that you have under the directory in a file called mylist.txt

   ls >> mylist.txt

It will append again the file names to the same file without deleting the previous content of the file.
See the result by typing:

   more mylist.txt
wiki/startbash.txt · Last modified: 2021/01/20 20:36 (external edit)