Changes

Jump to: navigation, search

Tutorial2: Unix / Linux File Management

156 bytes added, 11:54, 11 November 2020
LINUX PRACTICE QUESTIONS
# Enter the lines shown in the other diagram of the nano text editor on the right side.<br><br>'''NOTE:''' Refer to the table below for a list of the most common Nano navigation &amp; editing commands:<br><table cellpadding="5"><tr><th style="border-bottom: 1px solid black;">Keyboard Combination</th><th style="border-bottom: 1px solid black;">Purpose</th></tr><tr><td>'''&lt;ctrl&gt;&lt;SPACEBAR&gt;'''</td><td>Move forward one word</td></tr><tr><td>'''&lt;esc&gt;&lt;SPACEBAR&gt;'''</td><td>Move back one word</td></tr><tr><td>'''&lt;ctrl&gt;&lt;k&gt;'''</td><td>Cut line</td></tr><tr><td>'''&lt;esc&gt;^'''</td><td>Copy Line ('''Note:''' to get '''^''' character, type '''&lt;shift&gt;6''', <u>not</u> <ctrl>)</td></tr><tr><td>'''&lt;ctrl&gt;&lt;u&gt;'''</td><td>Paste Cut/Copied Text</td></tr><tr><td>'''&lt;ctrl&gt;&lt;g&gt;'''</td><td>Display help screen (ctrl-x to exit help screen)</td></tr></table><br>
# Referring to the table above, practice navigating and editing your entered lines for practice.<br><br>
# To '''save''' your editing session, press: <span style="color:blue;font-weight:bold;font-family:courier;">&lt;ctrl&gt;&lt;x&gt;</span><br><br>
# You will be prompted to modify your file: type the letter '''y''' for yes.<br><br>
# The name of the file will be displayed: press <span style="color:blue;font-weight:bold;font-family:courier;">ENTER</span>.<br><br>'''NOTE:''' This prompt for file name allows you to change the name of the file if you wish.<br>By pressing '''ENTER''', it will accept the default filename.<br><br>
===Part 2: Creating Text Files Using The vi Text Editor===
[[Image:vi-screen.png|right|300px|thumb|Using the '''vi''' text editor.]]
You will now learn basic editing skills using the '''vi''' ('''vim''') text editor including '''creating''', '''editing''', and '''saving''' text files.
'''NOTE:''' Refer to the table below for a list of the most common '''vi''' ('''vim''') navigation &amp; editing commands:<br><table cellpadding="5"><tr><th style="border-bottom: 1px solid black;">Keyboard Combination</th><th style="border-bottom: 1px solid black;">Purpose</th></tr><tr><td>'''i'''</td><td>Enter '''INPUT''' mode</td></tr><tr><td>'''&lt;esc&gt;'''</td><td>Return to '''COMMAND''' MODE</td></tr><tr><td>'''W'''</td><td>Move forward one word</td></tr><tr><td>'''B'''</td><td>Move back one word</td></tr><tr><td>'''dd'''</td><td>Cut line</td></tr><tr><td>'''yy'''</td><td>Copy Line</td></tr><tr><td>'''&lt;ctrl&gt;u'''</td><td>Paste Cut/Copied Text</td></tr><tr><td>''':help'''</td><td>Display help screen ('':q!'' to exit help screen)</td></tr></table><br>
[[Image:vi-text-editor-2.png|right|350px250px|thumb|The online vi-tutorial provides users "hands-on" experience of using the vi text editor.]]
An '''online tutorial''' has been created to give you "hands-on" experience on how to use vi text editor. It is <u>recommended</u> that you run this online tutorial in your Matrix account to learn how to create and edit text files with the vi text editor.
===Part 3: Manage / Manipulate Text File Content===
We conclude this tutorial by learning to use commands that manage the content contained instead text files whether it relate to '''viewingview''' or '''manipulatingmanipulate the <u>display</u>''' file contentwithout having to use a text editor.<br><br>This is HIGHLY ADVISED in case you only want to view contents and NOT edit file contents by mistake.
'''Perform the Following Steps:'''
# View Refer to 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;" width="20%">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>
# Confirm 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>
# Use the '''nano''' text editor to edit the empty file called '''a.txt'''. <br><br>Type the number "'''1'''" and press '''ENTER'''. On the second line, type the number "'''2'''" and press '''ENTER'''. <br>Continue entering increasing number values until you reach the number '''40''' on line 40.<br><br>
# Save your editing session.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cat a.txt</span><br><br>Can you see all of the contents?<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>
# 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 <br>'''online assignment #1''',<br>'''section 2''' labelled "Basic Unix Commands" (parts '''4''' to '''6''') in this section which are respectively labelled: <br> '''Managing Files''' , '''Accessing Files''' and '''Review Exercise'''.<br><br>
= LINUX PRACTICE QUESTIONS =
'''Review Questions:'''
[[Image:directorytree-structure-11diagram.png|right|350px|thumb|]]
# Write a single Linux command to create the directory structure starting from your home directory from the diagram displayed on the right.
# Write a Linux command to display a detailed listing of '''history''' directory.<br>How would this command differ if you wanted to also view hidden files as well?<br>
# Write a Linux command to remove both directories named '''1''' and '''2'''.
# Write a Linux command to remove the '''concepts''' directory and its contents.
# Write a Linux command to remove the '''concepts''' directory and prompt the user if they want to remove this directory’s contents.<br><br># Write a single Linux command to create the following empty files in the concepts directory:<br>'''myfile.txt'''<br>'''yourfile.txt'''<br>'''thefile.txt'''<br><br>
# Write a Linux command to view the contents of the myfile.txt text file to prove it is empty.<br>What is the difference between the commands: '''cat''', '''more''' and '''less'''?
# Write a Linux command to sort the contents of a file called '''uli101practice/customers.txt'''# Write a Linux command to display the first 4 lines of a file called '''uli101practice/customers.txt'''# Write a Linux command to display the last line of a file called '''uli101practice/customers.txt'''# Write a Linux command to match a line containing the pattern '''Linux''' in a file called '''uli101practice/customers.txt'''# Write a Linux command to display unique occurrences of consecutive lines in a file called '''uli101practice/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