OPS145 Lab 2 Newversion: Difference between revisions

From Littlesvr Wiki
Jump to navigation Jump to search
(Replaced content with "The latest version is here: OPS145_Lab_2 Category:OPS145")
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
== !!!THIS PAGE IS NOT READY YET!!! ==
The latest version is here: [[OPS145_Lab_2]]


= Multi-user systems =
Linux was intended from its beginnings to be a multi-user system. A multi-user system allows multiple people to use it at the same time. That concept is hard to understand if you think of a computer as having one screen, one keyboard, and one mouse.
But originally systems like '''Unix''' (the Linux predecessor) were used as workstations by multiple people at once. They got around the problem of sharing one monitor and one keyboard by using dumb terminals. A '''dumb terminal''' might look like a computer but it isn't. It's just a screen plus a keyboard plus a serial port connection (like a slow network connection) to the actual computer (sometimes called a '''mainframe''').
Other systems like Microsoft '''DOS''' (which eventually got a graphical interface and was then called '''Windows''') had no such capabilities, and were much simpler. That made them the perfect choice for this new thing called a Personal Computer ('''PC'''). You didn't need much sysadmin training to put DOS on a PC.
For decades the mainframe was powerful enough to serve the needs of all the employees, but cheap enough that it wasn't going to get replaced with personal computers for each employee.
Eventually PCs got much cheaper, and since it was no longer financially viable to stick to mainframes: Microsoft took over the computer world with its DOS and later Windows operating systems.
= Why terminals still exist =
It turns out that when you create an operating system intended to be used by one user on their personal computer: you don't consider security or even multi-tasking performance as priorities.
In the 1980s and 1990s the entire world was plagued by viruses, blue screens of death, and abysmal server performance because the demand for IT increased exponentially but Unix was expensive, Unix administrators were hard to find, so Windows was the only option for many.
Luckily Linus Torvalds wrote an operating system kernel mostly compatible with Unix, and together with hundreds and thousands of other developers a new operating system was born which did not suffer from the MS DOS legacy problems: '''Linux'''.
Dumb terminals have almost completely dissapeared. They're now only used by very large companies who like to pay IBM lots of money for basic IT services. I've recently seen a green screen being used by a bank teller, and smiled.
The mainframes of the 1970s have been replaced by PC-compatible servers and server farms. Two types of terminals are still used pervasively:
* For regular users: a web browser is just a pretty version of a dumb terminal. All the content lives on the server, and all the actions performed by the website visitor are performed on the server.
* The server administrators use almost identical terminals now as were used 50 years ago, except they're '''software terminals instead of hardware terminals'''. A graphical interface, while inviting with its apparent ease of use, is simply not efficient enough to allow complex administration tasks on remote servers. You are going to learn to use this sort of terminal in OPS145 and the rest of the OPS stream.
= What can you do in a terminal =
If you're a server administrator: just about everything that you can do can be done in a terminal. For example:
* Copying and moving files and directories.
* Creating users and controlling their access privileges.
* Configuring and controlling services (e.g. a web server).
* Monitoring server activity.
* Installing and uninstalling software.
* Configuring networking.
* Configuring other hardware (like hard drives).
* Starting and stopping machines on demand.
* Creating, deploying, and monitoring all sorts of automation.
Terminals are probably completely new to you, and though they're older than your grandparents: don't imagine that they're ancient garbage. Most of the exciting computer things created in your lifetime were built and are managed in terminals. Once you learn the basics: you'll impress yourself with what you can accomplish by typing commands rather than opening windows and clicking buttons. That's what OPS145 is for.
= ls, pwd, cd =
One of the simplest things you can do is look at the contents of a directory (a.k.a. a folder).
* First open a graphical file manager in your ops145 VM.
* In the '''View''' menu change the '''Sidebar''' type to '''Tree'''.
* Also in the '''View''' menu change the '''Toolbar''' type to '''Location Entry'''.
This will encourage you to better understand paths over the long term. Note that it appears you have 8 empty subdirectories in your home directory.
* Open the terminal application and run the '''ls''' command. To run a command you type it at the prompt and press enter.
The ls command (as most other commands) produces some text output and that output is printed in the terminal window where you executed the command.
<<<screenshot>>>
* Run the '''clear''' command. This is helpful at times when there is too much old output in the terminal window which you don't care about and is distracting you. This doesn't undo the commands you ran previously, it simply erases their output from the screen.
* Try running ls using different capitalization, for example '''Ls''', '''LS''', or '''lS'''. Try to run some other made up commands and note that the error is the same: '''command not found'''.
[[File:BadLS.png|center]]
* Open the "Text Editor" graphical application. This works with plain text files.
* Write some text in it and save the file as '''first.txt''' in your Documents directory.
* Close the text editor, and open your first.txt again by finding it in your graphical file manager.
* Run ls in your terminal and note that the Documents directory is there, but the first.txt file does not show up. That's because by default the ls command shows the contents of the Present Working Directory (PWD), your PWD is /home/yourusername, but first.txt is in the /home/yourusername/Documents/ directory.
* Change your PWD by running '''cd Documents'''.
* And run ls again. You should now see first.txt. But it no longer shows Desktop, Downloads, etc. because those are subdirectories of /home/yourusername/ and your PWD is /home/yourusername/Documents/
* Run the '''pwd''' command. That simply shows you the PWD, which you can typically see anyway in the terminal prompt.
== ls -l ==
You can simply run a command by typing in the name of the command and waiting for it to execute its default behaviour. But you can also change that default behaviour, by following the command with one or more arguments (a.k.a. options, a.k.a. parameters). Each command has its own set of possible arguments. Sometimes they're similar between commands, most of the time they're not.
For the '''ls''' command one such argument is '''-l''' (minus lower case L). This instructs '''ls''' to print extra details about each file and directory.
* Run '''ls -l'''
For now we can ignore most of that output, but do try to find the size of the file. It's the number just before the modification date. By default the size is in bytes.
<<<screenshot>>>
Since the text is written in english: each character is an ASCII character, which uses one byte of storage. Spaces and newlines (Enters) are also one-byte characters.
* Count the number of characters in your text file and confirm that it's the same as the size of the file.
= cat =
The default behaviour of the '''cat''' command is to read the contents of a file and dump them out on the terminal. The terminal can only display text. Other types of data will likely show up as garbage.
* Run '''cat first.txt''' to see the contents of first.txt The name of the command is cat and the first argument is first.txt
[[File:CatFirstTxt.png|center|812x812px]]
Commands and arguments are separated by spaces. The number of spaces doesn't matter.
* Try to run the '''ls''' and '''cat''' commands you ran earlier but add more spaces before the command, between the command and the argument, and at the end.
The '''ls -l''' command shows you information ''about'' the file. The '''cat''' command shows you the ''contents'' of the file.
* Create a new text file in the graphical editor and save it with a name which has a space. Then try to use cat to see its contents:
[[File:catFileWithSpace.png|center|812x812px]]
"'''No such file or directory'''" is one of the most common errors. Usually it's obvious what it means, but often (as in this case) you have to think a little.
Since the command arguments are separated by spaces: the '''cat''' command has no way of guessing that '''second''' and '''file.txt''' are one filename, it assumes they are two separate files. Later in the course you'll learn to deal with spaces and other special characters in filenames.
* Try to use '''cat''' to see the contents of '''First.txt''' (note the capital first letter). It won't work since First.txt and first.txt are as different from each other as first.txt and hirst.txt.
* Use the graphical text editor to create another text file, and save it in the Documents directory with the name '''First.txt''', then repeat your last '''cat''' command:
[[File:CatfirstFirst.png|center|812x812px]]
* Note also that the sizes of the files are different. '''First.txt''' has fewer characters, therefore it's smaller.
= Also: =
[[Category:OPS145]]
[[Category:OPS145]]
* ls -l -h
*Download example files using firefox
*View a long text file in Xed, cat, less
*Plain text files vs doc files; plain text vs xls; file command
*Different image types, can't view in terminal, can check with file command
*Extensions mostly don't matter in linux
*Linux filesystem structure: one root, common directories
*

Latest revision as of 16:07, 16 January 2024

The latest version is here: OPS145_Lab_2