Unix filesystem Exercises less




Дата канвертавання22.04.2016
Памер47.28 Kb.
UST Introduction to UNIX Filesystems

Purpose


The purpose of this lab is to familiarise you with the basic UNIX commands for working with files and filesystems.

UNIX Filesystem Exercises




less


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

man less

  1. As you are reading, notice the ":" prompt at the bottom of the page.

  2. Try pressing the return key - what happens?

  3. Try pressing the space bar once - what happens?

  4. Type the letter b - what happens?

  5. Use the search forward feature to find the word "environment" by entering the command:

/environment

  1. Type the letter n a few times – what happens?

  2. less will continue until you type q for quit. Try typing q to quit.


ls


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

man ls



  1. Use ls without any arguments to display this directory's contents. How many files do you see?

  2. Now use ls with the -a option. How many files do you see this time? Notice that the "new" files all begin with a "dot", which indicates they are "hidden" files.

ls -a



  1. This command is useful for distinguishing between directories, ordinary files, and executable files. Notice how its output differs from ls without arguments.

ls -F



  1. Use the command ls -lG to obtain a "long" listing of your files. Sample output from this command and an explanation of the information it provides appears below.

-rwxr-xr-x 1 jsmith staff 43 Mar 23 18:14 prog1

-rw-r--r-- 1 jsmith staff 10030 Mar 22 20:41 sample.f

drwxr-sr-x 2 jsmith staff 512 Mar 23 18:07 subdir1

drwxr-sr-x 2 jsmith staff 512 Mar 23 18:06 subdir2

drwxr-sr-x 2 jsmith staff 512 Mar 23 18:06 subdir3

1 2 3 4 5 6 7
1 = access modes/permissions

2 = number of links

3 = owner

4 = group

5 = size (in bytes)

6 = date/time of last modification

7 = name of file



  1. Recursive listings can be very useful. Try both of the commands below in some directory with subdirectories. What does the output tell you?

ls -R

ls -Rl



  1. Try three options together:

ls -lFa


mkdir


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

man mkdir



  1. Make a new directory called UST:

mkdir UST

  1. Change into this new directory using the cd command below. Create a new directory within this using the mkdir command called unixlab1:

cd UST

mkdir unixlab1

List your directory after the command completes to prove that it worked. Change to this new unixlab1 directory and create a subdirectory called newdir:



cd ~/UST/unixlab1

mkdir newdir

ls



  1. Now create some additional subdirectories within your newdir. List newdir after the command completes to prove that it worked:

mkdir newdir/sub1 newdir/sub2 newdir/sub3

ls newdir



  1. Try to create a directory in a location where you don't have permission. What happens?

mkdir /etc/mydir


cd


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

man cd



  1. Change to your default, UST directory:

cd ~/UST



  1. Change to a subdirectory within your UST directory and list its contents:

cd ~/UST/unixlab1/newdir/sub1

ls



  1. Go up one level to the current directory's parent directory and list the contents:

cd ..

ls



  1. Change to the root (top-most) directory and list the contents:

cd /

ls



  1. Change to another one of your subdirectories and list the contents:

cd ~/UST/unixlab1/newdir

ls


rmdir


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

man rmdir



  1. First make sure you are in the unixlab1 directory. Then try to remove the newdir directory. What happens?

cd ~/UST/unixlab1

rmdir newdir



  1. Recursively list the contents of newdir. Notice that its subdirectories are all empty. Remove all of the empty subdirectories within newdir and then list newdir again to confirm that they were removed:

ls -R newdir

rmdir newdir/*

ls -R newdir



  1. Finally, remove the empty newdir directory:

rmdir newdir



  1. Make sure you are in your UST directory.

  2. Run an editor from within a Unix shell and create 3 or 4 files with miscellaneous information in them that you can work on in this lab. Call them test1, test2, test3 and test4.



cat


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

man cat



  1. Change directory to your UST directory. Use this command to display the contents of a file: What happens?

cat test1



  1. Now try this command and notice the difference. How many lines are in the file?

cat -n test1



  1. The cat command is more often used for purposes other than just displaying a file.

cat test1 - first, show file1

cat test2 - then, show file2

cat test1 test2 > newtest - now do the actual concatenate

cat newtest - finally, show the result


cp


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

man cp



  1. Copy an existing file in your current directory to another file in the current directory and then list your directory to prove that it was done:

cp test1 test1b

ls



  1. Use the copy command with the "inquire" option. What happens?

cp -i test1 test1b



  1. Make two new directories, subdir1 and subdir4. Use the recursive option to copy an entire subdirectory to a new subdirectory and then list both directories to prove that it worked:

cp -R subdir1 subdir4

ls subdir1 subdir4



  1. The shell expands "wildcard" characters before passing them to commands. Try the command below. What did it do? List the subdir1 subdirectory to find out.

cp test* subdir1

ls subdir1


mv


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

man mv



  1. The mv command can be used for renaming files. Try this command and then list your files to prove that the command worked:

mv test3 newtest3

ls



  1. mv can be used to rename directories also. Try this command and then list your files to prove that the command worked:

mv subdir4 dir4

ls



  1. The mv command is also used for moving files. Use the command below to move newtest3 into a new location, then list your files to prove that the command worked:

mv newtest3 unixlab1

ls

ls unixlab1



  1. The mv command can also be used for moving directories. Use the command below to move dir4 and subdir1 to unixlab1, then list your files in your UST directory and in unixlab1 to prove that the command worked:

mv dir4 unixlab1

mv subdir1 unixlab1

ls

ls unixlab1

  1. Make use of the shell’s expansion of wildcards. Try the command below and then list your files to prove that the command worked:

mv *test* unixlab1

ls

ls unixlab1


rm


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

man rm



  1. Change directory to unixlab1. Use the rm command to delete a file. List your directory after the command completes.

cd ~/UST/unixlab1

rm test4

ls



  1. cd to the subdir1 subdirectory. List the directory to view its contents. Then use the "*" wildcard to remove all of the files. NOTE: using rm in this manner can be dangerous! If you are in the wrong directory, you'll remove files you didn't mean to remove. You may want to use the -i option to protect yourself from accidents.

cd subdir1

ls

rm -i *

ls



  1. Get out of the subdir1 subdirectory by using the command cd .. Now try to use rm to remove a directory. What happens?

cd ..

rm subdir1



  1. This time, include the -r option when you try to remove a directory. What happens?

rm -r subdir1

ls


file


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

man file



  1. Change directory to unixlab1. Use the file command to determine a file's type:

cd ~/UST/unixlab1

file test1



  1. Now try it with a directory:

file dir4



  1. Finally, try it with a wildcard character;

file *


find


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

man find



  1. Use the find command to find the file new.sample.

find . -name newtest3 -print



  1. Now use the find command to find all files with "test" as part of their name. Don't forget to put the wildcard specification in quotes to prevent the shell from expanding it- it won't work otherwise:

find . -name '*test*' -print



  1. Try to find only directories with "file" as part of their name. Are there any?

find . -name 'file*' -type d -print


pwd


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

man pwd



  1. Issue the pwd command to display the name of your current working directory:

pwd



  1. Change to several other directories and issue the pwd command between each change. Notice the different outputs:

cd dir4

pwd

cd /usr/bin

pwd

cd ~/Mail

pwd

cd ~/UST/unixlab1

pwd


du (disk usage)


How much memory do my files take up? Type du to find out.

  • What does du by itself do?

  • What does du -s do?

  • What does du -s * do?

  • Which is most useful toward helping you determine which files take up the most memory?

  • What does the –h flag do?

Introduction to UNIX Access Permissions Exercises




These exercises will familiarize you with the basic UNIX commands for working with file access permissions.

  1. Make sure that you are in your unixlab1 exercise directory, and then do a long listing of your files:

cd ~/UST/unixlab1

ls -al



  1. Notice the access permissions assigned to each file. Can you tell:

    • which files are directories?

    • if a file is executable?

    • who has write access to each file?

    • who has read access to each file?

    • who owns the file?

    • which group the owner belongs to?

    • which permissions the group has?

    • which permissions others have?

  2. Use the chmod command to change the permissions for your test files. ONLY DO THESE OPERATIONS ON YOUR TEST FILES AS YOU CAN STOP YOUR ACCOUNT WORKING OTHERWISE.

Before you do so, read the chmod man page:

man chmod

List the file before and after each change and determine how the command changes the file permissions.



ls -l test2

chmod o-r test2

ls -l test2
ls -l test1

chmod g+w test1

ls -l test1
ls -l newtest3*

chmod go-r newtest3*

ls -l newtest3*



  1. Try a chmod command with numerical access specifications:

ls -l test2

chmod 754 test2

ls -l test2


База данных защищена авторским правом ©shkola.of.by 2016
звярнуцца да адміністрацыі

    Галоўная старонка