0% found this document useful (0 votes)
4 views

Lab 4 - More Linux Commands

This document outlines Lab 4 for the ITSC 1307 - UNIX Operating System I course at Austin Community College, focusing on advanced Linux commands. It includes exercises on exploring the Unix filesystem, managing files and directories, finding files, linking files, and managing file and directory ownership and permissions. Each exercise requires students to log in to a Unix server, perform specific tasks, and provide snippets of their work as evidence.

Uploaded by

Nelson
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab 4 - More Linux Commands

This document outlines Lab 4 for the ITSC 1307 - UNIX Operating System I course at Austin Community College, focusing on advanced Linux commands. It includes exercises on exploring the Unix filesystem, managing files and directories, finding files, linking files, and managing file and directory ownership and permissions. Each exercise requires students to log in to a Unix server, perform specific tasks, and provide snippets of their work as evidence.

Uploaded by

Nelson
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Austin Community College

Department of Computer Studies and Advanced Technology

ITSC 1307 – UNIX Operating System I – Lab 4


UNIX/Linux More Linux Commands Know
Lab Description: In this lab, you will learn more about some of the Linux Commands. For
this Lab, you can Login to the ACC Unix Server that was provided at the beginning of the
class.

This Lab will be mostly over the contents of Chapter 4 of our textbook, so please use the
textbook if you do not understand the command.

Exercise 1 – The Unix Filesystem

In this exercise, we will explore the Unix Filesystem. Answer the following questions.
Provide a snippet for each question. A portion of a directory can be snipped, but for larger
directories, not the entire directory.

1. Login to cois-linux.austincc.edu OR Centos or Fedora core.


2. Provide information on the following directories below (include a snippet):
(Take a look at Table 4-1)
a. /bin
b. /boot
c. /dev
d. /etc
e. /home
f. /lib
g. /media
h. /mnt
i. /opt
j. /proc
k. /root
l. /sbin
m. /sys
n. /tmp
o. /usr
i. /usr/bin
ii. /usr/games
iii. /usr/include
iv. /usr/lib
v. /usr/sbin
vi. /usr/share
vii. /usr/src
3. Briefly review: http://www.pathname.com/fhs
ITSC 1307 – Lab 4

Exercise 2 – Managing Files and Directories

In this exercise, we will explore the Unix Filesystem. Answer the following questions.
Provide a snippet for each question. A portion of a directory can be snipped, but for larger
directories, not the entire directory.

1. Login to cois-linux.austincc.edu OR Centos or Fedora core.


2. Change to your home directory:
a. cd /home/<your user id>
b. cd
c. cd ~

3. Create the following directories in the hierarchy shown. (Remember Unix is case
sensitive)
a. mkdir unix1
b. cd unix 1
c. mkdir project1 project2 project3 project4 project5
d. mkdir projects

4. Now let’s move the Project Directories into the “projects” directory
a. mv project1 projects
b. Confirm. Do an “ls -al”, did the directory move? snippet.Yes the folder moved

2 of 13
ITSC 1307 – Lab 4

c. Change directory to projects and see if project1 directory has moved under
“projects”.
d. Go back to the previous level (cd ..) and try to move all the other directories
under “projects” at the same time.
e. Snippet

5. So, now that we have renamed directories try a file. Let’s write our first script.
6. First, change directory to the location we want to work in.
a. cd projects/project1 OR cd /home/<youruserid>/unix1/projects/project1
b. Try both forms. One is the absolute path (FULL) path, the other was relative.
7. Use the VI editor to create the following script, name the file “script.sh”.
#!/bin/bash
#
echo "This is a really cool Lab!."

8. Is the script executable? No


a. ls -al
b. If not, we have to change it.
i. chmod 755 script.sh

3 of 13
ITSC 1307 – Lab 4

9. Provide a “cat” of the script, run the script, and also provide the output.
Cat

Output

10. rename the script by using the “mv” command.


a. mv script.sh script1.sh
11. Copy an duplicate the script using the “cp” command.
a. cp script1.sh script2.sh
12. Edit script2.sh, and add another “echo” line below the previous line, your choice.
Make sure it works and check permissions.

Exercise 3 – Finding Files

4 of 13
ITSC 1307 – Lab 4

In this exercise, we will explore Finding Files. Answer the following questions. Provide a
snippet for each question. A portion of a directory can be snipped, but for larger directories,
not the entire directory.
1. One command that we could utilize is the “locate” command. However, this has to be
setup correctly.
2. Take a look at the locate command under Section 4-3 “Finding Files”.
a. We are going to do a slightly different locate command. Remember that
“locate” build a database that stores the location of files on your system. It was
designed to quickly locate files by querying the database with the “locate”
command.
3. Try this:
a. locate passwd | grep -v 202 (What is the passwd file?)

The "passwd" file is a system file in Unix-like operating systems that stores essential information
about user accounts. Each line in the "passwd" file represents a user account and contains
various details such as the username, user ID (UID), group ID (GID), user's full name or
description, home directory, and default shell.

b. One more…..
c. locate fstab | grep -v 202 (What is fstab used for?)

5 of 13
ITSC 1307 – Lab 4

The "fstab" file, short for "File System Table", is a configuration file found on Unix-like
operating systems, including Linux. It is located at /etc/fstab. This file is essential for defining
how file systems are to be mounted and managed by the operating system during the boot
process.

4. Now, let’s use a different command, the “find” command. Not database, it just does a
massive search from the place in the file system hierarchy that you start the search, so
it’s slower and we don’t want to search thousands of files to figure out the locating of
the file we are looking for.
a. cd ~
b. find . -ls (This find command says find at my current locating, and do a “ls”)
This will show everything in the directory, and the relative path.

c. find /var -size +4096k 2> /dev/null

6 of 13
ITSC 1307 – Lab 4

This command searches the /var directory looking for file sizes over 4096K
(kilobytes). Notice the 2>, what is that? Try with and without “2> /dev/null”,
and explain the difference.

The command `find /var -size +4096k 2> /dev/null` searches the "/var" directory
for files larger than 4096 kilobytes. The "2>" redirects any error messages
(stderr) to `/dev/null`, effectively suppressing them. Without "2> /dev/null", error
messages was displayed, cluttering the output.

d. Review section 4-3 in our textbook (CH4), pick a Find command of your own
choosing, and pick a specific file. Also, suppress and permission denied
messages.
find /etc -name "hosts" -exec ls -l {} + 2>/dev/null;

This command searches the "/etc" directory for files named "hosts" and executes the "ls -l" command
on each found file. The 2>/dev/null part redirects any permission denied messages to /dev/null,
suppressing them from the output.

Exercise 4 – Linking Files

7 of 13
ITSC 1307 – Lab 4

In this exercise, we will explore Linking files by creating a Symbolic Link, and a Hard link.
Answer the following questions. Provide a snippet for each question. A portion of a directory
can be snipped, but for larger directories, not the entire directory.
1. Review Section 4-4, Chapter 4, Linking Files.
2. Let’s create a hard link to our script above. Change to the directory and do an “ls -l”
3. cd ~/unix1/projects/project1

4. ln script2.sh script3.sh

5. Do a listing again, notice that we have created a new file called “script3.sh”, notice
that the file sizes of script2.sh and script3.sh are the same. Also, notice the “2”, next to
the permission, this indicates both files are sharing the same inode.
6. Edit script2.sh and add another line. What happens to script3.sh?
In the previous example, both files share the same inode, meaning they point to the same data on
the disk. Any changes made to one file will be reflected in the other since they are essentially the
same file under different names.

7. In this previous example, both files are sharing the same “inode”,

Each Filesystem in Unix has a superblock that contains general information about the
Filesystem, for example the number of inides and data blocks in kilobytes. An “inode table”
consists of information nodes that describes one file or directory on the filesystem. Each inode
contains unique number for identification and the inode stores metadata about the directory or
file. NOTE: A hard linked file must reside on the same filesystem.
8. Now, let’s take a look at a Symbolic Link
9. In the same previous directory, let’s create a Symbolic Link.
10. ln -s script3.sh script4.sh

8 of 13
ITSC 1307 – Lab 4

11. Once created, do a listing (ls -al), notice that a Symbolic Link is a pointer to another
file or directory. Also, with Symbolic links, we can cross to other filesystems.

12. Create some other Symbolic links and Hard Links on your own

Exercise 5 – File and Directory Ownership

In this exercise, we will explore File and Directory Ownership. Answer the following
questions. Provide a snippet for each question. A portion of a directory can be snipped, but
for larger directories, not the entire directory.
1. Review Section 4-5, Chapter 4, File and Directory Ownership
2. What are your login credentials? “whoami” (username) lishaqzai

9 of 13
ITSC 1307 – Lab 4

3. What groups are you in? “groups”

4. Change directory to project2

5. create an empty file (touch file1)

10 of 13
ITSC 1307 – Lab 4

6. What are the permissions of the file? Provide detailed information and a snippet. The
permissions of "file1" are read and write for the owner (lishaqzai) and the group
(lishaqzai), with read-only permissions for others.

7. Change the permissions of the file to be executable for owner and group, but no
permissions for “other”, world privs.

8. Since, we are not “root” on the ACC system, these commands can’t be done;
However, answer the following questions for our textbook. You can also try it on
Fedora or CentOS as “root”.

a. What is the command to change the group of a directory or file? chgrp


b. What is the command to change the owner of a directory or file? Chown
c. What is the command to change the owner of a directory, and files &
directories below the top directory? All of them. chown -R
d. What is the command to change the group of a directory, and files &
directories below the top directory? All of them. chown owner:group
file_or_directory

e. Can I combine both the owner and group into a single command that changes
both at the same time? Show an example. chown -R lisha:admins
/var/www/html

Exercise 6 – Managing File and Directory Permissions

In this exercise, we will explore managing file and directory permissions. Answer the
following questions. Provide a snippet for each question. A portion of a directory can be
snipped, but for larger directories, not the entire directory.

11 of 13
ITSC 1307 – Lab 4

1. Review Section 4-5b, Chapter 4, Managing File and Directory Permissions


2. In the project 2 directory, create several files using the “touch” command

3. Change permissions of a file or directory to the following. Utilize both the binary
mode and the plus-minus mode for each:
a. Read Execute for User, Group, and Other

b. Read, Write Execute for User, Read Execute for Group, and Read only for
Other.

c. Read, Write Execute for User, No privs for Group and Other

d. Read, Write, Execute for All

12 of 13
ITSC 1307 – Lab 4

e. Read, Write for user, Read Only for Group and Other

f. No Privs for User, Group, but other Full Privs.

Example: chmod 777 file1


chmod u=rwx,g=rwx,o=rwx file1

Which one do you like better? Remember, in Unix there are always more than one way to do
something.

13 of 13

You might also like