Changes

Jump to: navigation, search

Tutorial2: Unix / Linux File Management

1,827 bytes added, 03:57, 24 January 2020
Tutorial Reference Material
|- valign="top" style="padding-left:15px;"
|colspan="1" |Course NotesSlides:<ul><li>[https://ict.senecacollege.ca/~uli101/notes/Week02.pdf PDF] | [https://ict.senecacollege.ca/~uli101/notes/Week02.pptx PPTX]</li></ul>Tutorials:<ul><li>[http://www.cheat-sheets.org/saved-copy/Nano_Cheat_Sheet.pdf Nano Reference Sheet (PDF)]</li><li>[https://www.smashingmagazine.com/2010/05/vi-editor-linux-terminal-cheat-sheet-pdf Vi Reference Sheet (PDF)]</li><li>[http://czegel.com/seneca/uli101/lectures/Lecture2.html Les Czegel's Week 2 Notes (HTML)]</li></ul>
*[http://man7.org/linux/man-pages/man1/cat.1.html cat]<br>
*[http://man7.org/linux/man-pages/man1/more.1.html more] , [http://man7.org/linux/man-pages/man1/less.1.html less]<br>
* [http://man7.org/linux/man-pages/man1/head.1.html head] , [http://man7.org/linux/man-pages/man1/tail.1.html tail]
*[http://man7.org/linux/man-pages/man1/touch.1.html touch]<br>
*[http://man7.org/linux/man-pages/man1/file.1.html file]<br>
|}
 
= KEY CONCEPTS=
===Unix / Linux Directories===
# Issue the following Linux command to confirm that all of the directories have been created:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -ld uli101 uli101/notes uli101/tutorials uli101/examples acp100 xyz100</span><br><br>
'''Downloading & Running a Shell Script to Check your Work'''
Although you are being asked to create the directory structure, you might have made some mistakes:<br>For Example:<br>
# Make certain that your current directory is '''your home directory'''.<br><br>
# Issue the following Linux command to '''download''' run a '''shell checking script''' to your home directory that will check your work:<br><span style="pointer-events: none;cursor: default;color:blue;font-familyweight:courierbold;font-weightfamily:boldcourier;">wget https&#58;bash /home/matrix.senecacollege.ca/~murray.saul/uli101/week1-check-1<scripts/span><br><br># Run the checking script to check your work by issuing the following:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash week1week2-check-1</span><br><br>
# If you encounter errors, then view the feedback to make corrections, and then re-run the checking script. If you receive a congratulation message that there are no errors, then proceed to the next section.
<br>
#Issue the following Linux command to display the directory structure of your home directory to confirm you copied the uli101 directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">tree</span><br><br>Let's download and run a checking script to see if you moved and copied the directories correctly.<br><br>
# Make certain that your current directory is '''your home directory'''.<br><br>
# Issue the following Linux command to '''download''' a '''shell run checking script''' to your home directory that will check your work:<br><span style="pointer-events: none;cursor: default;color:blue;font-familyweight:courierbold;font-weightfamily:boldcourier;">wget https&#58;bash /home/matrix.senecacollege.ca/~murray.saul/uli101scripts/week1week2-check-2</span><br><br># Run the checking script to check your work by issuing the following:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash week1-check-2</span><br><br>If you encounter errors and re-run the checking script until you receive a congratulations message, and proceed to the next section.<br><br>
===Part 3: Removing Directories ===
# Issue the following Linux command (entering "y" when prompted): <span style="color:blue;font-weight:bold;font-family:courier;">rm -ri xyz100</span><br><br>'''NOTE:''' You should have removed all directories that you have created.<br><br>Let's download and run a checking script to see if you have removed all of the directories that you earlier created.<br><br>
# Make certain that your current directory is '''your home directory'''.<br><br>
# Issue the following Linux command to download run a '''shell checking script''' to your home directory that will check your work:<br><span style="pointer-events: none;cursor: default;color:blue;font-familyweight:courierbold;font-weightfamily:boldcourier;">wget https&#58;bash /home/matrix.senecacollege.ca/~murray.saul/uli101scripts/week1week2-check-3</span><br><br># Run If you encounter errors and re-run the checking script until you receive a congratulations message, and proceed to check your work by issuing the following:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash week1-check-3</span>next INVESTIGATION.<br><br>
=INVESTIGATION 2: MANAGING TEXT FILES=
'''Perform the Following Steps:'''
# View the following table of Text File Management commands Your instructor should have demonstrated in class how to use these commands):<br><br><table cellpadding="5"><tr><th style="border-bottom: 1px solid black;">Linux Command</th><th style="border-bottom: 1px solid black;">Purpose</th></tr><tr><td>'''touch'''</td><td>Create empty file(s) / Updates Existing File's Date/Time Stamp</td></tr><tr><td>'''cat'''</td><td>Display text file's contents without editing (small files)</td></tr><tr><td>'''more , less'''</td><td>Display / Navigate within large text files without editing</td></tr><tr><td>'''cp'''</td><td>Copy text file(s)</td></tr><tr><td>'''mv'''</td><td>Move / Rename text files</td></tr><tr><td>'''rm'''</td><td>Remove text file(s)</td></tr><tr valign="top"><td>'''sort'''</td><td>Sorts (rearranges) order of file contents when displayed. Content is sorted alphabetically by default. The '''-n'''''Italic text'' option sorts numerically, '''-r''' performs a reverse sort</td></tr><tr valign="top"><td>'''head''' , '''tail'''</td><td>Displays the first / last 10 lines of a text file by default. An option using a value will display the number of lines (e.g. head -5 filename will display first 5 lines, tail -5 filename will display last 5 lines).</td></tr><tr valign="top"><td>'''grep'''</td><td>Displays file contents that match a pattern</td></tr><tr valign="top"><td>'''uniq'''</td><td>Displays identical consecutive lines only once</td></tr><tr valign="top"><td>'''diff''' file1 file2</td><td>Displays differences between 2 files</td></tr><tr><td>'''file'''</td><td>Gives info about the contents of the file (e.g. file with no extention)</td></tr><tr valign="top"><td>'''find'''</td><td>To find files matching specified characteristics:<table><tr valign="top"><td width="20%">'''find . -name "file*"'''</td><td>List pathname of any filenames beginning with "file",<br>from the current directory and any subdirectories</td></tr><tr valign="top"><td>'''find . -size +50k'''</td><td>List pathname of any files larger than 50 kb, from the current directory and any subdirectories</td></tr><tr valign="top"><td>'''find . -mmin -5''' </td><td>List files modified less than 5 minutes ago</td></tr><tr> valign="top"><td>'''find -P .'''</td><td>Lists file pathnames in the current directory</td></tr></table></td></tr></table><br><br>
# Make certain that you are located in your '''home''' directory.<br><br>
# Use the '''touch''' command to create the empty files called '''a.txt''', '''b.txt''', and '''c.txt'''<br><br>
# Type the letter "<span style="color:blue;font-weight:bold;font-family:courier;">q</span>" to exit the more command.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">less a.txt</span><br><br>Is there any difference between the more and less commands?<br>(again press '''q''' to quit)<br><br>
# issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">sort a.txt</span><br><br>Why does the output not look what you expected? Why?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">sort -n a.txt</span><br><br>Try the same command using both the '''-n''' and '''-r''' options to see what happens.<br><br>
# issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">head a.txt</span><br><br>What is the output from this command display?<br><br>
# issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">head - 7 a.txt</span><br><br>What is the output from this command display?<br><br>
# issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">tail a.txt</span><br><br>What is the output from this command display?<br>How would you issue this command to display only the last line contained in that file?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">grep 2 a.txt</span><br><br>What type of output appear? Why did these lines appear (what do they all have in common)?<br><br>
# Edit the '''a.txt''' file and add to the bottom 5 new lines each consisting of the <u>same</u> text: "'''end of line'''" and save changes to your file.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">uniq a.txt</span><br><br>What do you notice happened to those newly created lines?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp a.txt a.txt.bk</span><br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp a.txt b.txt</span><br><br>
# Issue one of the commands you learned to display the contents of the file called '''b.txt''' without editing.<br><br>What happened to this file?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">mv a.txt aaa.txt.bk</span><br><br>
# Issue a Linux command to view the directory contents.<br><br>What happened to the file called '''a.txt'''? Why?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">file b.txt</span><br><br>What sort of information did it provide?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">diff aaa.txt.bk b.txt</span><br><br>What was the output? Why do you think caused the result of this output?<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">diff aaa.txt.bk c.txt</span><br><br> What reason would this type of output occur?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">find -P . </span><br><br>What is the output of this command?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">rm aa.txt b.txt a.txt.bk c.txt</span><br><br># Issue the '''ls ''' command to verify that these files have been removed.<br><br># After you complete the Review Questions sections to get additional practice, then work on your online assignment#1, section 2 labelled "Basic Unix Commands" (parts '''4''' to '''6''') in this section which are respectively labelled: '''Managing Files''' , '''Accessing Files''' and '''Review Exercise'''.<br><br>
= LINUX PRACTICE QUESTIONS =
# Write a Linux command to display unique occurrences of consecutive lines in a file called '''uli101/customers.txt'''
# Create a '''table''' listing each Linux command, useful options that are displayed near the top of this tutorial labelled: '''Tutorial Reference Material'''
 
[[Category:ULI101]]
13,420
edits

Navigation menu