You are on page 1of 1

Lab #4 - Linux Command Line Basics

Lab Steps:
I.

Stanislav

Directory Creation, Navigation, and Deletion A. Start the Terminal application by selecting Applications > System Tools > Terminal. B. Type the pwd command. This command will show your current working directory. It currently should be /home/<username> -- e.g., /home/bjones C. Type mkdir lab4 to execute the make directory command, creating a new directory named lab4. D. Type cd lab4 to navigate into the newly created directory. E. Type cd ~ to return back to your home directory. Type pwd again to verify that you are there. F. Type rmdir lab4 to delete the lab4 directory you had just created. Creating and Deleting a File in a Directory A. Re-create the lab4 directory and change to it. Use pwd to verify your change worked. B. Type touch labfile to create an empty file named labfile inside of your lab4 directory. C. Return to your home directory and try to delete the lab4 directory. D. Type rm lab4/labfile to delete the labfile file from your lab4 directory. E. Try to delete the lab4 directory again; it should of worked this time without any errors. Using Absolute and Relative Paths A. Once again, create the lab4 directory inside of your home directory. B. Type cd /usr/local to change your working directory to /usr/local. C. Change back to your home directory using an absolute path -- e.g., cd /home/<username> D. Type pwd to verify that you are in your home directory. E. Type cd lab4 to return to the lab4 directory. This command used a relative path, not absolute. Using the ls, less, more, and cp Commands A. Change to the /var/log directory. B. Type ls -l to see a list of all files in the /var/log directory. C. Type less dmesg to view the dmesg file. Press the enter key to move down one line at a time or press the space bar to move one page at a time. You can exit by pressing the q key. D. There exists a command also titled dmesg which views the /var/log/dmesg file. By using a “pipe” on the command line, you can provide data from one command to the next. For example, run the command dmesg | less and notice how you are utilizing the less command on the dmesg contents still. Quit less when you are done. E. Next try to execute dmesg | more and quit more when you are done. F. Change your directory back to your home directory. G. Type ls -la to see a long listing of files, including hidden ones (dot-prefixed files e.g., .bashrc). H. To view the output of ls -la one page at a time, use a pipe and less. Type ls -la | less to do so. I. Create a copy of the .bash_profile file into your lab4 directory called bashprofile by typing the cp .bash_profile lab4/bashprofile command. J. Change to the lab4 directory and type ls -la and verify the bashprofile file exists. Renaming and Moving Files Using the mv Command A. Type the command mv bashprofile bashprofile2 (make sure that you are in your lab4 directory). B. Type ls -la and verify that bashprofile2 exists and bashprofile does not. C. Type mv bashprofile2 ../bashprofile2 to move the bashprofile2 file from your lab4 directory into your home directory. D. Change to your home directory and list your files, verifying that bashprofile2 is now there. E. Move bashprofile2 back to the lab4 directory, once again called bashprofile.

II.

III.

IV.

V.