EXERCISE 3: UNIX toolbox

Directions

ININTRODUCTION—The numbering below corresponds to “what to type”

THE VIRTUAL TERMINAL at the right is a sandbox.

A sandbox is a space that may can litter and discard.

Long commands may appear in two or three lines.

echo 'this is s long command that do not fits a single line, but the END OF LINE goes after the last single quote' |ENTER|

But you should type them without pressing enter. The text indicates when you need to press enter.

echo "these are:" |ENTER|

echo " two different command lines" |ENTER|

1. ============

A common thing we need to do is change a name of a file.

To that aim we use the command "mv" for move. Sounds weird?—not really, change a file name is the same as moving it to a new container.

Here we first made a copy of hello.c into hello2.c; then we changed its name, created a new folder and...

What happened with the last command?

use a command to find out what has happened to your file.

By the way, unless you make a mistake, BASH will answer nothing

2. ============

Another common thing is to change something on a file without having to open it, find the words to modify and typing. In fact, what if i have to do it with many files?—it is going to be boring!

That is what tools do for us. a powerful tool is sed (stream line editor). "sed" reads a file and does something to it, the more common thing it a change.

What we did is to replace hello world by Hello Friend. The syntax is "sed instruction file" the result was sent to ... where?

What has happened to the file hello_friend.c we had before?

Notice the form of sed instruction, it is simple:

's/something/some other thing/' it means substitute (s) something by some other thing.

it is in between quotes because we do not want do change anything, just to pass it to sed. the [Ww] and [Hh] imply that H and W can be capital or lowercase.

3. ============

what is we want to repeat something many times?

we can use a loop the easiest to use is the "for in do done" loop" the syntax is simple:

for variable in element1 elemnt2 element3... elementN ; do command1; command2; done

first thing to notice is the use of a variable. Second thing is we used "s///" instead of 's///', this time we want BASH to change ${nnm} into Juan Susana and Britt before sending the arguments to sed (first) and gcc later.

Find out what happened and explain how the commands did work.


4. ============

Now we want to pack everything, so we can take it somewhere else.

We then use "tar" (for tape archiver), we do not use tapes anymore, but the principle is the same. Pack files into a media and keep their names, dates, sizes, permissions and also the DIRECTORIES in order.

to call "tar" we can use to mayor forms of the command, if we want to pack we move to the place where the files are and use "-czvf filename.tar.gz" flags, ther we list the names of files we want to pack. Directory name as followed, so files inside are packed.

Next we move to a new directory and unpack the file. We have actually duplicated the files in a new place.

see what ls has reported.

pwd is the command that tells us where we are, it is equivalent to writing "echo $PWD", but is shorter.

5. ============

Let us make our files for us only, so the cannot be spoiled or misused by someone else.

for that we change their permissions. There are three sets of permissions, for the owner, for the member of group, and for everybody else.

permission as read (r) write (w) execute (x). so when we type ls -l we get "rwxr-xr-x" it means the owner (me) can read write and execute the file, users in my group can read and execute, but cannot write, the same as everybody else.

Let us make members of my group unable to execute and remove others the chance to see the file or execute it

If an executable file has no execution permission, it cannot be called. This is a way to avoid accidental execution of a dangerous program.


6. ============

Now we do need to open a terminal.

If you have your LINUX computer or a MACOX open the terminal applications.

If you have Windows 10 computes you need to run the BASH ubuntu application

www.howtogeek.com post 249966: how-to-install-and-use-the-linux-bash-shell-on-windows-10


7. ============

Now we want to connect to a remote shell, so we shall connect to BARRACUDA

if a computer has an IP address you might connect to it. Currently, there are computer attacks all the time. Programs called "robots" are trying user/password combinations all the time to any computer open on the net. So we need two things:

A) Strong password
B) en encrypted protocolol

The three more important protocols to communicate in BASH are:
ssh (secure shell)
scp (secure copy)
sftp (secure file transfer protocol)

to use ssh you need the address of the server, your user name & your password here replace user by your actual username:

8. ============

This new prompt ($) is a terminal, but it is being executed at a remote server, it refers to a remote disk and all the resources are remote.

You can access the remote files here, but you cannot access files here. If you want access to local files open a separate terminal.

But remember there are several different shells in UNIX—are we runing BASH?

how do we find out?

9. ============

we shall illustrate a few tools, but I am not going to tell you what they do, you can use the UNIX manual pages to find out, for instance to find out what pwd does type "man pwd", pres "q" when you are finished.

Furthermore, backquotes ` command ` are used to execute something in the command line before the main command is actually executed, it is called nesting. Only one level of nesting is allowed ` ` command ` ` will not work.

Now find out what every command is doing. and explain it in a text file. This text file is going to be your homework and you have to uploaded to the moodle site, before the next session.




10. ============

LOGOUT FROM YOUR SESSION once you are finished!—This is very important—connections hanging out are frequent backdoors for intrusion.

CONGRATULATIONS! YOU HAVE REACHED THE END OF THE TUTORIAL.