What Is The Effect Of Cat Rubbish

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

The following book may be useful and is available on-line via the Library Safari Online Books collection (via Athens).

"Sams Teach Yourself Unix in 24 Hours, Fourth Edition", Dave Taylor, 2006, Sams Publishing, ISBN 978-0-672-32814-5 (pearsontechgroup);

PRACTICAL 1.

The document on the page http://scm.ulster.ac.uk/technicalsupport.php

details how to use Virtual Box.

Use cursor to move over Applications, then Accessories, and select Terminal. A new window will appear. This is where you will work with files, run scripts etc.

Please use the filenames as suggested as you will need to refer to some of these files in later practical sessions.

2.

A simple editor to use is gedit but others may be available (for example nano, pico). A more sophisticated one is vi.

In Unix, files may have an extension (for example ‘.txt’) which is usually indicative of content but this is not mandatory.

Using a simple editor, create and save the 3 files as described below. To invoke the editor simply type gedit filename and press Return. This opens up an editor window that allows text to be entered. Help will show the commands available.

(i) File hello should contain one line echo Hello there.

(ii) File niceday should contain three lines

echo The time and date are now :

date

echo Have a nice day.

(iii) File whenandwho should contain two lines

date

who

3.

(i) Type ls and press Return. Write down what this command does.

4.

Run each of the simple scripts contained in the files hello, niceday and whenandwho. To do this:

(i) type sh hello and press Return;

(ii) type sh niceday and press Return;

(iii) type sh whenandwho and press Return;

(iv) What do you think sh is short for ?

5.

List the contents of each of the three files hello, niceday and

whenandwho, in turn, on your screen . To do this

(i) type cat hello and press Return

(ii) type cat niceday and press Return

(iii) type cat whenandwho and press Return

(i) What does the command date > rubbish1 do ?

(Hint : any new files created ? )

(ii) What does using > do in the above command?

(Hint : compare with output of date )

(iii) When would you use the < in this context ?

(Hint : opposite of output ? )

You can also create a file using cat >

(i) Type in the following, noting that the last line means press the Ctrl and D keys together.

cat > rubbish2

Are you enjoying your

first taste of Unix?

Ctrl-D

(ii) What is the outcome?

Note: If you make a mistake on a previous line, you cannot go back. In this situation you have to finish using cat > and then use an editor to correct error.

8.

When you need to check on the syntax of a particular command you can use the man command to read the manual page for it.

(i) Type man cat to find information on cat command.

Some versions of Unix will page output from man by default. If there is more information than can fit onto one screen then you can ‘page’ the information if this is not done automatically.

(ii) Type man ls | more

(iii) Press the spacebar key to view another page and the return key to see

another line.

(iv) By using the man command find out how to list the names of your files with

extra information such as filesize, date of modification etc. Write down and

explain the command.

If you are unsure which command you need to use, type man –k followed by a keyword relating to the task. You will be given a brief description of all commands indexed by that keyword.

(i) What command could you use to find who else is logged on?

(ii) Issue the command man ls again.

(iii)What is the significance of the 1 in brackets in first line of output?

What does cat < rubbish2 do?

(ii) What is the difference between the output of the above command and the command cat rubbish2 ?

What is the effect of cat rubbish1 rubbish2 ?

(i) Create a file called rubbish3 and type in echo This is file rubbish3

(ii) Now save the file.

(iii) Create a file called rubbish4 and type in echo This is file rubbish4

(iv) Now save the file.

(v) What is the effect of cat < rubbish3 > rubbish4 ?

(Hint: examine both files)

(i) What is the difference between these two commands?

date > rubbish1

date >> rubbish1

(i) What is the effect of who | tee rubbish5

(Hint: examine rubbish5)

(i) Write a shell script (store in file named additiontable ) which produces on screen the following information AND stores a copy in a file called additiontable_copy.

(Hint : consider 14 above ).

3 plus 0 is 3

3 plus 1 is 4

3 plus 2 is 5

3 plus 3 is 6

Write the shell script below.

(i) Issue the following two commands

ls -1 > rubbish6

wc -l < rubbish6

(ii) Check using the man command to find out what these options on ls and wc

commands do . Write down your answer.

(iii) What is the combined effect of these two commands?

(Hint : there are 2 outcomes to consider.)

(i) Issue the following command

ls -1 | wc -l

(ii) What is the effect of this command?

(iii) How does it differ from the two commands in previous question?

The | symbol is referred to as a pipe.

Deleting files is done using rm command.

It is recommended that you use option –i so that you are prompted before the deletion occurs.

(i) Issue the following command and note how it runs.

rm – i rubbish6

Explain below what this command does.

(i) How would you list the contents of a file on screen with each line being numbered automatically?

Summarise new Unix commands that you have learnt in this practical as well as techniques and new features of Unix.

PRACTICAL 2.

1.

When you first logon you will automatically be in your home directory.

If at any stage you are not sure which directory you are in, issue the command pwd .

(i) While you are in your home directory, issue the command

mkdir directory1 to create a directory called directory1

(ii) Stay in your home directory, issue the command

mkdir directory2 to create a directory called directory2

(iii) Move to directory1 using cd directory1 then issue the command

mkdir directory3 to create a third directory called directory3 which is in

directory1, as shown in diagram below.

(iv) Go back to your home directory by typing cd

Typing cd .. takes you up one level.

home

directory1

directory2

directory3

Directory is same as folder and .. means parent.

(v) What does ../.. mean ?

(vi) From your home directory how can you go directly to directory3? Write down your answer.

(vii) Create a file called relativeandabsolute in directory3 which contains one line as follows

echo It is convenient to have this file here.

(viii) The name given to this file in (vii) could be used in another directory but each will have a unique absolute name. Write down the absolute name of this file that you have created in directory3.

(HINT: you may need to use pwd command to help you. )

2.

Input and Output Streams

Once you have typed in a command, and the command begins to be executed, you may be requested to type in data as input to the command, and it will send messages as output.

Output consists of the stream of characters usually sent to the screen.

Some commands eg ls, date and who give output but require no input.

For simple commands which require input, the input is formed by the characters you type in on the keyboard.

Each command has associated with it three streams, as shown below. They are called standard input, standard output and standard error (often abbreviated to stdin, stdout and stderr ).

Normally, standard input will be taken from the keyboard, and standard output and standard error will both be sent to the terminal screen.

A command may in addition have other input and/or output streams.

Each input/output stream is also given a number: 0 for standard input, 1 for standard output and 2 for standard error.

Commands that require input will usually take it from standard input, and the normal output of a command will go to standard output.

Standard error is used for other messages, typically warning messages if the command could not be executed as intended .

Thus the output from a command and the diagnostics can be separated.

3.

Redirection of input and output

It is possible to redirect input and/or output.

Instead of input coming from the keyboard, it can be the contents of a file or the output of another command.

Similarly output from a command can be sent to a file or used as input to another command.

The symbol < indicates that standard input should come from a file. The standard output can be directed to a file using >.

Beware that you do not take input from and send output to the same file - it won't work. The file you try to take the input from will be destroyed in preparation for receiving the output before anything is read from it.

Pipes

The syntax for pipes is similar to that for file redirection, except that the symbol | is used instead of < and > .

If we have a command X whose standard output is to be used as the standard input to a command Y, we could have

X > tempfile

Y < tempfile

storing the output of X in a temporary file tempfile. However this is not

elegant and by means of a pipe we can join the two streams together, thus :

X | Y

Using > or < different input or output streams can be specified, but pipes only connect standard output to standard input, and cannot be used with the standard error stream.

Scripts

A method of performing several commands, one after the other, is to create a file containing those commands, one per line, and then 'execute' that file ( also known a shell script.)

When you are logged in, you will be communicating via a program called a shell. The shell which is run from the moment you login to the end of your session is your login shell.

It is possible to run further copies of the shell by typing the command sh. In order to execute a shell script, the program sh is run, but instead of taking standard input from your terminal, the input comes from the file. Thus while the script is executing there will be two copies of sh running. The login shell will be running one command, namely sh, and this shell will execute the commands in the file.

4.

(i) Make sure you are in your home directory. (How ?) Write down your answer.

(ii) Now issue the command ls –l

(iii) How are directories denoted? Write down your answer.

(iv) Find out using the man command how to display ‘hidden’ files ( ie files starting with a dot.) Write down your answer.

(v)Why are these files not normally displayed when using the ls command?

When a file is created, space to store it is found on the disk. That space is given a unique number, called an inode, which remains with that file until it is deleted. At creation , the file is also given a name. The file is created in a directory which is updated to contain the name of the file and its inode.

(vi) How do you check which inodes are allocated to which files?

(vii ) How do you find the inode of your home directory?

Sometimes it is useful to give a file several different names. ( Eg if you have data that needs to be accessed in several different directories and any changes to it need to be made consistently. If you create several copies, then updates would have to be made one per copy which can lead to errors. ) We can use the concept of an inode to good effect.

5.

Make sure that you are in your home directory.

Create and save a file called mydata which has the following 2 lines

echo This is a file which will be used to show how files can be linked

echo Data is 1,2,3 ,4 ,5

While still in your home directory issue the command

cp mydata mydata2 (  note that a completely new file is created with a new inode but contents of file are not changed.)

Copy ( using cp ) file mydata to directory1 which you created earlier. This means you will have 2 files called mydata.

How does this differ from (iii) ?

Change directory to directory1 and then rename the file called mydata in

directory1 by issuing mv mydata mydata1

Move the file mydata2 into directory2 and do not rename it. Write down the command you used to do this.

On the diagram below, please identify where each of the files mydata, mydata1 and mydata2 are located in your filesystem.

Home

directory1

directory2

directory3

Create a link between the file mydata and a new, as yet non-existent, file (mydata3) in directory3 by using the ln command followed by the name of the existing file and then the new file. Write down the command you used.

NOTE: A file can be named relative to the current directory or given a unique absolute name starting from the root directory. Since you are linking 2 files in different directories , it will be necessary to use at least one absolute name.)

This edit must be performed using the vi ( or pico , jpico, nano ) editor. Edit file mydata3 and modify the last line so that it reads

echo Data is 1,2,3,4,5,6,7,8,9

If you choose the vi editor ask for help to make the above change. Now save and close the file.

Now list file mydata. Explain below any changes to the file.

The kernel will keep track of how many names (links) an inode has

and when this drops to zero, the filespace allocated to that inode is released for use elsewhere.

Does making changes to mydata affect mydata3 ?

How does Linux record that 2 files are linked (as per above

process )?

6.

Summarise new Unix commands that you have learnt in this practical as well as techniques and new features of Unix.

PRACTICAL 3.

Unix has a flexible way of protecting files. Each file divides the users into 3 categories:

the files’s owner

a group of users

other users

For each of these categories of user, that user may be given or denied the following access privileges:

read, write, execute

Access privileges for directories have a different meaning than for ordinary files. If a directory has write permission, files in that directory may be created or deleted. If it has read permission, it is possible to see what files are contained in that directory. If it has execute permission it is possible to cd to it.

(i) Under what circumstances would you want to give one of your

directories execute access but not read access?

(ii) Issue the command ls –l from your home directory and identify each of the fields which appear for each file and directory. Write them down in the order they appear in space provided.

(iii) When you create a file, what are the default access privileges? Write them down in space provided.

(iv) When you create a directory, what are the default access privileges? Write them down in space provided.

(v) Find out which files are linked use the ls –il

The most frequent change you are likely to make to a file, apart from its actual contents is to the access privileges, using the chmod command.

This command uses the addition symbol + to add, the subtraction symbol – to take away permission(s) and equals sign = to set permission(s).

It also makes use of who symbols ( u for user, g for group, o for other, a for all. Permission symbols are r,w,x or - .

Eg the command chmod go-w myfile will deny write permission to group and to others for the file myfile.

What effect does the following command have, assuming there is a file called myfile?

chmod g=rx myfile

(ii) Create a file called unreadable which no-one can read and confirm that you yourself cannot read it. Write down the command you used.

Unix treats a file as a sequence of bytes.

A file named myfile.c does not necessarily contain a program written in C. The file command can help in determining what a file contains but is not infallible.

(i) Try out this command on a file you have created. Explain the outcome.

Does it make sense?

There is another way to change a file’s permissions which is based around treating the presence of each r,w,x as a 1 and treat the absence of each r,w,x as a 0 and working out the octal value.

The chmod command allows you to specify the new permission settings as an octal number. Eg If you wanted rubbish1 to have the following permission settings:

rwxr-x---

then the octal permission setting would be 750 ( see table ) .

The command to achieve this is chmod 750 rubbish1

(i) Create a new file called filepermission with one line

echo This is to allow permission settings to be changed.

(ii) By specifying the appropriate octal value in conjunction with the chmod command, change the permissions on this file so that absolutely anyone can read , write or execute filepermission. Write down the command you used.

User

Group

Others

setting

rwx

r-x

---

binary

111

101

000

octal

7

5

0

Again, by specifiying the appropriate octal value in conjunction with the chmod command, change the permissions on this file so that everyone can only read filepermission. Write down the command you used.

(iv) Who can change ownership of one of your files?

awk - provides more sophisticated processing of files divided into records and fields

cmp – like diff but stays silent if files being compared are the same and gives a short message if they are different. Can work with files of any type.

cut – is a very useful utility for extracting columns and can distinguish between fields and specify delimiters ( option –d)

diff - gives you details of differences between 2 text files

du - displays file space usage.

grep – is a utility which allows you to search for a pattern ( regular expression ), possibly in a list of files. If no files are specified it searches standard input instead. All lines that match the pattern are displayed to standard output. The –w option restricts matching to whole words. To search all files with extension .c for the string x you could issue the command grep –w x *.c

head - can list the first number of lines of a text file ( can specify number or accept default number).

paste - useful when you have two or more files containing what can be thought of as columns in a table and you require corresponding lines from the files to be concatenated so as to actually produce a table

sort - sorts its input into alphabetical order line by line. It has many options and can sort on a specified field of the input rather than the first or numerically (option –n )

tail - can list the last number of lines of a text file ( can specify number or accept default number).

uniq – with no options, this filters out consecutive repeated lines but only if they are consecutive ( can use option –u). Options exist to indicate how many times a line is repeated, output only repeated lines or only lines which are not repeated.

wc – can count number of lines , words and characters ( can use options –c, -w , -l to select only one of these counts.) This command does not work on directories.

(i) Create a new file in your home directory called bloggs and type in the following 3 lines containing date of birth, surname, first name

17.04.1981 Smith Fred

22.01.1983 Jones Susan

03.11.1982 Bloggs Joe

(ii) Use the cut command with options to produce only the surnames from the file bloggs. Write down the command you used.

What happens when surnames vary greatly in length?

(iii) Use the cut command with options to produce only the year of birth for each of the three people listed in the file bloggs. Write down the command you used.

(i) Find the most recently modified file (excluding ‘dot’ files) in the current directory. This will involve several commands using pipes.

Write down the command you used.

(i) Find out how many separate inodes are represented by

the files ( excluding ‘dot’ files) in the current directory.

Write down the command you used.

(i) Write a script below which will list the files in the current directory (excluding ‘dot’ files ) in long format (i.e. including the information that ls provides with option –l ) and in increasing order of size.

Summarise new Unix commands that you have learnt in this practical as well as techniques and new features of Unix.

14.

What is the Windows Experience Index?

How do you update the index and display a report for your computer?

15.

Describe how you could use the ReadyBoost feature to use a USB flash drive as a memory expansion device.

ADVANCED PERFORMANCE TOOLS.

16.

From the Performance Information and Tools dialog, there is a link to the right that is Advanced Tools. Clicking on this will highlight any performance issues. It also makes available a variety of tools to help monitor and improve system performance.

Briefly describe the performance tools available.

17.

What events are monitored by the Reliability Monitor?

18.

Briefly describe the functionality of the Resource Monitor.

19.

Briefly describe the operation of the Performance Monitor.

MANAGING AND TROUBLESHOOTING.

20.

From within the Control Panel, there is a new Backup and Restore applet. What tasks does this enable you to perform?

21.

Access the Troubleshooting applet in the Control Panel. Click View All from the links on the side and you will see all the Troubleshooting packs and their descriptions.

What check-box settings are available?

What is available from the "Get Help from a Friend" link?

22.

Briefly describe the functionality of PowerShell.

ANSWERS TO QUESTIONS FOR PRACTICALS 8 TO 11.



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now