Linux/Unix Filesystems Objectives: The lab exercise is designed to introduce you to the linux operating system and environment employed in the Geography Department's Lab. This exercise covers: - How to log in and start working with linux - How linux files are organized and used - Several important commands for examining and manipulating files This lab concentrates on command line operations from the terminal window. It is possible to do all of this via a graphical interface using the konqueror file browser, available by clicking the Home icon on the desktop panel. Open that application, click on the File System icon, and change the view setting to Details. Task Overview Create a new directory called labs, then cd to labs and create a directory called lab1. Furthermore, cd to lab1 and create subdirectories called 1) michigan, 2) indiana, and 3) ohio. Then create 6 subdirectories, 2 under directory michigan called Detroit and lansing, 2 under directory indiana called Indianapolis and tipton, and 2 under into your lab1 directory. Then copy your address file to subdirectories lansing, indianapolis, and columbus. Furthermore, move address file from lansing subdirectory to tipton subdirectory and rename it new. Finally, delete columbus subdirectory and move back to your home directory. Detailed Instructions Step1: Log In Log in by entering your log-in name/password. In the menu on the lower-left, click linapps and log in again. A KDE desktop environment should spring up.
Step2: Create directories 1. Start a terminal window by clicking K System Konsole 1.Check your current location. What does it say? 2. If you are not in your home directory, change your current location to your home directory. %cd /home/your_username or %cd ~ 3. List all files in your current location. How many files do you have? %ls 4. If you don't already have one, create a directory called labs, then cd to labs, and create a directory called linux_lab. %mkdir labs %cd labs %mkdir linux_lab 5. Change directory to linux_lab. %cd linux_lab (full path: cd /home/<your_username>/labs/linux_lab) 6. Check your current location. 7. Create subdirectories called michigan, indiana, and ohio under this directory. %mkdir michigan %mkdir indiana %mkdir ohio 8. List all files in your current location and check that they should be 3 subdirectories. %ls 9. Now move to the michigan directory with the cd command. %cd michigan (full path: cd /home/<your_username>/labs/linux_lab) 10. Create 2 subdirectories called detroit and lansing. %mkdir detroit %mkdir lansing 11. Examine the differences between ls and ls l. What does column 5 show? %ls l 12. Move to the indiana subdirectory from michigan. What's the difference between cd /home/<your_username>/labs/linux_lab) and cd../indiana? 13. Create other 2 subdirectories under indiana. %mkdir indianapolis
%mkdir tipton 14. List all files, including hidden files. What is the.. file? %ls a 15. Move to the ohio subdirectory. %cd /home/<your_username>/labs/linux_lab/ohio 16. Create other 2 subdirectories. What happens if you type cd ashland? %mkdir ashland %mkdir columbus Step 3: Create a text file 1. Open the text editor, by clicking K Utilities Editors Kwrite. 2. Type your name and your address. 3. Save the document and name it address.txt in your linux_lab folder. Step 4: Examine and manipulate files 1. Back in the terminal window, check your current location. 2. Move to your linux_lab directory and list the files. Write the commands you type to do this 3. Look at the contents of address.txt from the command line. %more address.txt 4. Copy your address.txt file to the assigned subdirectories (lansing, indianapolis, and columbus). The following command copies just to lansing: %cp /home/<your username>/labs/linux_lab/address.txt /home/<your username>/labs/linux_lab/michigan/lansing/address.txt Write down how to copy the same file to other assigned subdirectories. You can also try: Go to your destination location using cd and then copy the file from the source location. %cp ~/labs/linux_lab/address.txt address.txt 5. Now change to the directory that you want to move the file from. %cd ~/labs/linux_lab/michigan/lansing 6. Move the file from lansing to the tipton subdirectory and rename it new. %mv address.txt../../indiana/tipton/new
7. List all files to see the your new file %ls../../indiana/tipton or ls ~/labs/linux_lab/indiana/tipton Step 5: Delete a subdirectory 1. We'll delete 'columbus'. Always wanted to do that... 2. You will have to find out what the command for removing a directory is. Make sure you are in the ohio subdirectory (~/labs/linux_lab/ohio). Check the hints section for help. After you have done deleting, move back to your home workspace. Step 6: Report Write down answers for the questions in the Report section and hand it in to TA. Step 7: Log out Click on the Launch bar and choose Log Out. Then log out of the thin-client gateway server. IMPORTANT: Make sure you log out every time you finish lab class!!! Report 1. Contrast the differences between commands cd and pwd. 2. What is the option of the list command that will show the properties of files? 3. Explain how to remove the directory 'columbus' and indicate any problems you had. 4. How many bytes are occupied by the labs directory? 5. How can you get more information about a linux command (See Hints below!)?
Hints and commands The linux File Structure: Linux organizes files into a tree directory system. If you want to work with a particular file, the system has to know which sequence of directories it must search in order to find the file you want. A path name specifies a file by giving a sequence of directories and the file s name. Linux also lets you cd to a directory (just as in DOS) and then refer to files under that directory with relative path names. Tip: Previous commands you entered in the terminal window are stored in a buffer, or list. To repeat old commands press the up arrow. Some helpful Linux commands: man: MANual. Give this command with the command you need more information on, and a series of manual will appear that describe how to use the specified utility. cd: Change Directory. Use cd to move to different directories on the network. cd.. moves you up one directory in the tree. cd ~ or cd by itself will move you to your home directory. pwd: Present Working Directory. Use pwd to see the name of the directory you are currently in. ls: LiSt. Use ls to see the contents of your current directory. ls l: List (Long option). Use ls l to see file properties. ls a: will list all files in the directory (including hidden files). rm: ReMove files. rm r: removes a directory. mv: moves a file from one directory to another. cp: Copy. Copies a specified file or files from a specific location to a specific location (directory). Source and destination files, with paths, must be specified. mkdir: Make directory. rmdir: Remove directory. more: will display an ASCII text file on the screen. du sk <directory>: shows number of kilobytes stored in that directory. Credits/Blame Written by Perry Varnakovida and Ashton Shortridge (2002, 2003) Updated by Ashton Shortridge (2006, 2008, 2010, 2012)