Unit 1 Lab - Linux File Operations
Info
If you are unable to finish the lab in the ProLUG lab environment we ask you reboot the machine from the command line so that other students will have the intended environment.
Resources / Important Links
Required Materials
- Rocky 9.4+ - ProLUG Lab
- Or comparable Linux box
- root or sudo command access
Downloads
The lab has been provided for convenience below:
Pre-Lab Warm-Up
EXERCISES (Warmup to quickly run through your system and familiarize yourself)
Lab š§Ŗ
This lab is designed to help you get familiar with the basics of the systems you will be working on. Some of you will find that you know the basic material but the techniques here allow you to put it together in a more complex fashion.
It is recommended that you type these commands and do not copy and paste them. Word sometimes likes to format characters and they donāt always play nice with Linux.
Working with files
Creating files just by stuffing data in them
What is the difference between these two? Appending a file >> adds to the file whereas > just overwrites the file each write. Log files almost always are written with >>, we never > over those types of files.
Creating file with vi or vim
Copying and moving files
Look at what happened in each of these scenarios. Can you explain the difference between cp and mv? Read the manuals for cp and mv to see if thereās anything that may be useful to you. For most of us -r is tremendously useful option for moving directories.
Searching/filtering through files
Can you figure out why that worked? What do you think the ^ does? Anchoring is a common term for this. See if you can find what anchors to the end of a string.
Sorting files with sort
Advanced sort practice
Read man to see why that works. Why do you suppose that it needs to be reversed to have the highest numbers at the top? What is the difference, if you can see any, between using the -n or not using it? You may have to use head -40 to figure that out, depending on your processes running.
Read man ps to figure out what other things you can see or sort by from the ps command. We will examine that command in detail in another lab.
Working with redirection
The good thing is that youāve already been redirecting information into files. The > and >> are useful for moving data into files. We have other functionality within redirects that can prove useful for putting data where we want it, or even not seeing the data.
Catching the input of one command and feeding that into the input of another command Weāve actually been doing this the entire time. ā|ā is the pipe operator and causes the output of one command to become the input of the second command.
See if you can figure out what each of those commands do.
Read the manual man command for any command you donāt recognize.
Use something you learned to affect the output.
Throwing the output into a file
Weāve already used > and >> to throw data into a file but when we redirect like that we are catching it before it comes to the screen. There is another tool that is useful for catching data and also showing it to us, that is tee.
Do a quick man on tee to see what the -a does. Try it without that value. Can you see any other useful options in there for tee?
Ignoring pesky errors or tossing out unwanted output
Sometimes we donāt care when something errs out. We just want to see that itās working or not. If youāre wanting to filter out errors (2) in the standarderr, you can do this
In one of our later labs weāre going to look at stressing our systems out. For this, weāll use a command that basically just causes the system to burn cpu cycles creating random numbers, zipping up the output and then throwing it all away. Hereās a preview of that command so you can play with it.
May have to yum -y install bzip2 for this next one to work.
Use ācrtl + cā to break if you use that and it becomes too long or your system is under too much load. The only numbers you can play with there are the 1024k and the count. Other numbers should be only changed if you use man to read about them first.
This is the āpoor manāsā answer file. Something we used to do when we needed to answer some values into a script or installer. This is still very accurate and still works, but might be a bit advanced with a lot of advanced topics in here. Try it if youād like but donāt worry if you donāt get this on the first lab.
What happened here is that we read the input from command line and gave it, in order to the script to read and then output. This is something we do if we know an installer wants certain values throughout it, but we donāt want to sit there and type them in, or weāre doing it across 100 servers quickly, or all kinds of reasons. Itās just a quick and dirty input āhackā that counts as a redirect.
Working with permissions
Permissions have to do with who can or cannot access (read), edit (write), or execute (xecute)files.
Permissions look like this.
| Permission | # of Links | UID Owner | Group Owner | Size (b) | Creation Month | Creation Day | Creation Time | File Name |
|---|---|---|---|---|---|---|---|---|
| -rw-r--r--. | 1 | Root | root | 58 | Jun | 22 | 08:52 | datefile |
The primary permissions commands weāre going to use are going to be chmod (access) and chown (ownership).
A quick rundown of how permissions break out:
Letās examine some permissions and see if we canāt figure out what permissions are allowed.
The first character lets you know if the file is a directory, file, or link. In this case we are looking at my home directory.
rwx: For UID (me).
- What permissions do I have?
---: For group.
- Who are they?
- What can my group do?
---: For everyone else.
- What can everyone else do?
Go find some other interesting files or directories and see what you see there. Can you identify their characteristics and permissions?
Info
Be sure to reboot the lab machine from the command line when you are done.
