Subtitle: Basic shell commands

Version / revision: V1.0 / R 0.0.

For Nethserver all version.

Skill: Novice / Beginner

Date of presentation: Released on 2016-05-27

Often in the community using the shell.
I thought to write some commands that might be useful for beginners.

The dos prompt in Windows allows a limited number of operations. The Linux shell allows you to perform advanced scripting operations .
All commands can be chained using some special characters (| > and <) as needed.


cd path


cd /var/lib
cd nethserver

where path is the path to the folder where you want to go. It can be relative or absolute


ls path


ls /var/lib
ls nethservice

lists files and folders in path specified (relative or absolute).
The command takes several parameters:

ls -la

detailed list of files and folders including hiden files .


du path


du /var/lib

the command takes several parameters.

du -sm

calculates the overall size of a folder rather than in mega bytes.


df -m

It returns information about the space of partitions mounted.


more filename
cat filename


cat /etc/passwd

A particularly interesting feature is the ability to view real-time variations of a file. This function is used for displaying the log file.

cat /var/log/samba/smb.log | less

Another command to see the last (10) lines of a file

tail filename

Also this command takes several parameters

tail -20 /etc/passwd

Show the last 20 lines

tail /var/log/nomelog | less


grep -r "string" files

Search “string” in files.

It accepts several parameters and is useful combined with other commands:

grep -r --color "root" / etc / password

Search in /etc/passwd the string “root” and highlights it in red

grep -r --color "root" /etc> list.txt

Search the string “root” in all files in /etc including subfolders . The output is written on file list.txt


find path


find /var/lib/nethservice

Lists all files in path and subfolder.

This command is often used in combination with other:

find /var/lib/nethserver/ | grep mail | grep admin> list.txt

Lists files in /var/lib/nethserver/ extracting only those that contain in path and name the string “email” and “admin” and stores them in list.txt


ping host


ping nethserver.domain.lan


nmap [option]


nmap -v -sn

Scanning the 172.16.1.x network and lists the status of each address.
The command accepts a variety of parameters:

nmap -v -A nethservice.domain.lan

Lists all open doors for host nethservice.domain.lan


sed [options] file


sed s/Installing/Removing/ install.log

It replaceswords “Installing” with “Removing” in install.log file.
It's a very powerful editor. Here are some example:

Delete all lines that contain the word test

sed /test/d file.log

Delete all lines that do not contain the word test

sed /!test/d file.log

Delete all lines that begin with the word test

sed /^test/d file.log

Delete rows from 2 to 30

sed '2,30d' file.log

Delete rows from 2 to the end

sed '2,$d' file.log

Delete the last line

sed '$d' file.log

Print only lines with the word test. If you add -i you will change the file

sed -n '/test/p' file.log

Deletes empty line

sed '/^$/d' install.log

Add “text” at beginning of every line

sed 's/^/text/' install.log

Adds “text” at the end of each line

sed 's/$/text/'

You can run multiple instructions separated by -e

sed -e 's/Installing/Removing/' -e 's/$/text/' install.log

or placing them in a file (eg. list.txt)


and pass through the -f switch

sed -f install.log list.txt

Once the sequence of commands you can place them in a script.
The script usually has the extension .sh ( and must be executable

chmod +x


for i in $(ls); do
echo item: $i


cat /etc/passwd | while read line
  echo $line |grep apache| gawk -F: '{print $1"\t My home is:"$7}' 
  • how_to_use_linux_shell_for_beginners.txt
  • Last modified: 2016/05/27 21:32
  • by Vincenzo