You are on page 1of 6

find

1. Read/scan the man page for find with the command:


2.
3. man find

4. Use the find command to find the file new.config.


5.
6. find . -name new.config -print

7. Now use the find command to find all files with "file" as part of their name. Don't forget
to put the wildcard specification in quotes - it won't work otherwise:
8.
9. find . -name 'file*' -print

10. Try to find only directories with "file" as part of their name. Are there any?
11.
12. find . -name 'file*' -type d -print

diff and sdiff

1. Read/scan the man page for diff with the command:


2.
3. man diff

4. Use the diff command to determine the differences between two files:
5.
6. diff names1 names2

7. Use the diff command to determine the differences between two directories.
8.
9. diff subdir1 dir4

10. Try using sdiff to display the differences between names1 and names2:
11.
12. sdiff names1 names2

13. Now try sdiff specifying that the screen width is 80 characters...not the default 130:
14.
15. sdiff -w 80 names1 names2

sort

1. Read/scan the man page for sort with the command:


2.
3. man sort

4. Use the cat command to look at an unsorted list of names. Notice that there are multiple
columns of information and that the list is not alphabetically sorted.
5.
6. cat name.list

7. Use the sort command to perform a basic sort of the list:


8.
9. sort name.list

10. Do the same sort, but send the output to a file. Then use the cat utility to view the file:
11.
12. sort name.list > sorted.list ; cat sorted.list

13. Sort the list by first names. This requires skipping over the first field, which is the last
name:
14.
15. sort +1 name.list

16. Sort the list by department. This requires skipping over the first four fields and using the -
b option to ignore blank characters:
17.
18. sort -b +4 name.list

Access Permissions Exercises

These exercises will familiarize you with the basic UNIX commands for working with file access
permissions. Click here for more information on access permissions.
1. Make sure that you are in your Filesystem exercise directory, and then do a long listing of
your files:
2.
3. cd ~/Filesystem
4. ls -al

5. Notice the access permissions assigned to each file. Can you tell:
o which files are directories?
o if a file is executable?
o who has write access to each file?
o who has read access to each file?
o who owns the file?
o which group the owner belongs to?
o which permissions the group has?
o which permissions others have?
6. Use the chmod command to change the permissions for some files. List the file before
and after each change and determine how the command changes the file permissions.
7.
8. ls -l names1
9. chmod o-r names1
10. ls -l names1
11.
12. ls -l names2
13. chmod g+w names2
14. ls -l names2
15.
16. ls -l file*
17. chmod go-r file*
18. ls -l file*

19. Try a chmod command with numerical access specifications:


20.
21. ls -l prog1
22. chmod 754 prog1
23. ls -l prog1

24. Look in your ~/.cshrc file and find where your umask setting is specified. What is it and
what does it do? How would you change it so that nobody except you could see your
files?
25.
26. cd
27. more .cshrc
Standard UNIX File System Exercises

These exercises will familiarize you with the overall organization of your UNIX filesystem.

1. Change directory to the root level and then list the contents.
2.
3. cd /
4. ls

5. Change to the /usr directory and list it.


6.
7. cd /usr
8. ls

9. Spend some time navigating about the upper levels of the filesystem.... see how lost you
can get!!

Don't forget that you can always use the pwd command to tell you where you are, and
the cd command to return to your home directory.

Basic Use of Metacharacters

In this practice you will practice using wild cards and a few other metacharacters.

1. List the files in the directory "/bin" that end in "sh". What command did you use?
ls /bin/*sh

2. On one line, use the "cd" command to first go to your home directory then to the "UNXclass"
subdirectory. What is the command line?
cd ; cd UNXclass

3. What command lists the files in the current directory that begin with upper case letters?
ls -d [A-Z]*

4. If they do not already exist, create three new directories in the UNXclass directory; "Letters",
"Programs", and "Misc". What command(s) did you use?
mkdir Letters Programs Misc

5. Copy all files in the current directory whose names contain the character string "let" into the
subdirectory "Letters". What command did you use?
cp *let* Letters
6. Copy all files in the current directory whose names end in ".c" or ".h" into the subdirectory
"Programs". What command did you use?
cp *.[ch] Programs

7. Copy all files in the current directory whose names contain the character strings "notes" or
"misc" into the subdirectory "Misc". What commands did you use?
cp *notes* Misc
cp *misc* Misc
or
cp *notes* *misc* Misc

8. Copy all files which begin with "copy.me" into the "UStoreIt" subdirectory. Move all files
which begin with "move.me" into the "UStoreIt" subdirectory. What commands did you use?
cp copy.me* UStoreIt
mv move.me* UStoreIt

9. Delete all files which contain the sequence "del". What command did you use?
rm -i *del*

1.

Practice 3 - Working with File Permissions

This practice will familiarize you with how UNIX permissions work. This practice
will also generate error messages to familiarize you with what file permission error
messages look like.

1. View the file "README.1", using the command "cat". What message did you
get?
This is a simple bit of text

2. View the file "README.2", using the command "cat". What message did you
get?
README.2: Permission denied
cat cannot read it because you do not have read permission on that
file.

3. cd into the NoWrite directory. Create a new file, named try.me, using
the command
touch try.me
What happened and why?
You cannot create try.me because you do not have write permission in
the NoWrite directory.

4. Use cd to go back up one level to UNXclass. What is one command that


will change the permissions on the NoWrite directory to allow the
creating of files.
chmod u+w NoWrite or chmod 700 NoWrite

5. Run the command runMe.1 by typing ./runMe.1 . What did it print out?
What are its permissions?
You ran runMe.1
permissions are rwxr-xr-x (755)

6. Run the command runMe.2 by typing ./runMe.2 . What did it print out?
What are its permissions?
The file does not run because you do not have execute permission on it.
Permissions are rw-r--r-- (644)

7. Permission practice- change the following files, which currently have


no permission settings, to have the specified permissions (use chmod
with either symbolic or numeric permission specs and use ls to check
your success):

File Permissions Symbolic Mode Command Numeric Mode Command

pp1 rwxrwxrwx chmod a+rwx pp1 chmod 777 pp1

pp2 rwxrwxr-x chmod ugo=rwx,o-w pp2 chmod 775 pp2

pp3 rwxr-xr-x chmod u+rwx,go=rx pp3 chmod 755 pp3

pp4 r-x------ chmod u=rx pp4 chmod 500 pp4

pp5 r--r----- chmod ug=r pp5 chmod 440 pp5

pp6 rw-r--r-- chmod u=rw,go=r pp6 chmod 644 pp6

pp7 r--r--r-- chmod ugo=r pp7 chmod 444 pp7

pp8 rw-rw-rw- chmod ugo=rw pp8 chmod 666 pp8

pp9 rwx------ chmod u+rwx pp9 chmod 700 pp9

You might also like