Shell commands, pipes, redirections and scripts

You can use ubuntu without doing any of this. If you are an ordinary user you are unlikely to need it but I have included it to show that ubuntu is a full linux version.

Remember that the shell is the user interface that allows the users to carry out tasks not available in the graphical interface. There are many shells and more than two hundred commands. The commands here are found in the Bourne shell, called bash, that is the default in ubuntu. Not all bash commands are delivered with ubuntu, but may be added.

To use shell commands you must open the terminal. Click the top-left ubuntu icon in the Launcher to open the dash, or press Alt-F2, and type terminal into the search box. Then click to open it.

You will see your personal prompt, similar to: peter@zoostorm:~ $

The first word is your user name. Next is your computer name after the @, then after the colon is your home directory called ~ (no Windows 'folders' here!). The final dollar shows it is the Bourne shell.

The prompt awaits your command.

Single commands

Commands can be used on their own or with switches that change how they work.

The switch symbol is a dash followed by one or more letters eg -al

Try them out at the terminal with the aid of a good book such as 'Ubuntu Linux Toolbox' by Negus and Caen

Here is a brief selection of the often-used ones:

man Manual about shell eg man cal tar Stores or extracts archived files
ls List directory contents gunzip Compresses files losslessly
cat Look at contents of file who Who is currently logged in
pwd Print working directory ps List running processes
cd Change directory kill Stop a process
mkdir Make directory free Memory use details
rd Remove directory date Prints date
mv Move a file (cut and paste) lspci Details of PCI interfaces
cp Copy a file (copy and paste) lsusb Details of USB interfaces
rm Remove a file ping Bounce data off an IP address
chown Change the owner of a file traceroute Trace data route to an IP address
chmod Set read/write/exe file permissions useradd Add a user
locate Find file by name usermod Modify account eg shell
grep Find a character pattern in a file userdel Delete user
wc Word count for a file passwd Change a user's password
sort Sort line alphabetically in a file sudo Superuser for one command
diff Reports differences between files cal Calendar (look at 1752)

Some require the user to have super-user privileges.


The Shift/Backslash character | is called a pipe and is used to send data from one command to another.

For example: ls | less

This gives a directory listing a page at a time


By default all data is output to the screen. However it can be redirected somewhere else.

For example to a printer: ls > lpt1

Or to a file: ls > newfile.txt

This command is also available in DOS.

Shell scripts

(There is a pale imitation of shell scripts in Windows DOS called 'batch files')

You write plain text scripts where each line is a shell command or series of piped commands. By default in ubuntu you can't run scripts. You need to add software and make changes to handle them.

You start the script by typing its name at your prompt.

Scripts can include coding structures like if, repeat and so on.

They are used for complex shell tasks that have to be done regularly.

Here is an example:

echo "Hello " $USER

echo "Your current directory is: " $PWD

Your could write it in a text editor, or LibreOffice writer, and save it as

To run it you type at your shell prompt, though not in default ubuntu.



(C) Peter Scott 2013

Last edit 26 December 2016