You are on page 1of 7

1

Trainer/trainee Notes
This module will give you a foundation into some more advanced Linux commands.

2
Trainer/Trainee Notes
Try out the commands yourself and see how it works. Sleep is a useful command if you wish to build in a
specified wait period into a script.

3
Trainer/Trainee Notes
& is a useful command to send a process to run in the background – you can again view it by running jobs
In this slide, we also introduce && and ; - as you can see && requires the first command to finish successfully
to run the second one. The ; does not require this.
|| can be used as a “please run this option if the first option didn’t work”

4
Trainer/Trainee Notes
/proc is not a real folder, it is an API into the Linux kernel. You may have heard the expression, "Everything in Linux
is a file". This is one example of that. In Windows, you would have a graphical task manager and things like that; in
Linux, you see virtual files.
Every process has an identifier, and is exposed via /proc, along with some other things.
Every process has at least 3 file descriptors:
• 0 - stdin - for input from a pipe, or the keyboard
• 1 - stdout - for output to the screen, or a log/data file
• 2 - stderr - for errors to the screen, or a log file

If the process opens files or network connections then it will have more fds, starting from the number 3 onwards.

5
Trainer/Trainee Notes
Watch is an extremely useful command if you want to see how things change over time. Here is an example of
a more complicated command – this will monitor the number of active connections on port 80 using a
combo of the netstat and grep commands:

watch “netstat –anp | grep –c ‘:80\b.*LISTEN’”

6
Trainer/Trainee Notes
This is a very useful command especially if you are ssh-ing to a server. It can happen that you accidently close a
terminal or lose connection. This will help prevent any running commands from being interrupted.

You might also like