Changes

Jump to: navigation, search

Tutorial2: Unix / Linux File Management

11 bytes added, 12:33, 27 August 2020
INVESTIGATION 2: MANAGING TEXT FILES
<table align="right"><tr valign="top"><td>[[Image:nano-text-editor-1.png|thumb|right|250px|The '''Nano Text Editor''' is Easy to Operate for Novice Users.]]</td><td>[[Image:vi-text-editor-1.png|thumb|right|300px|The Vi Text Editor, although taking longer to master, has outstanding features and allow the user to be more productive.]]</td></tr></table>
<br>
Since IT students will be working in the Unix / Linux command line environment, it is useful for them to learn a least a couple of command-line '''text editors'''.
Although '''programming students''' can use '''graphical IDE's ''' to code and compile programs, they can '''create source code''' using a text editor in the Linux system, and '''compile their source code''' to generate executable programs (without having to transfer them for compilation or execution).
'''Networking and Tech Support students''' would find a text editor useful to '''edit configuration files'''. These students in upper grades will become familiar with the process of installing, configuring, and running network services and text editors are an important tools<br>to help setup but also "tweak" or make '''periodic changes in networking services configuration'''.
A general rule is for a student to '''expose themselves to a number of different text editors and then use one that they feel most comfortable working with'''. The two most readily-available command line text editors in Linux are '''Nano''' and '''Vivi'''. The Nano text editor would seem like an easier-to-use text editor, but Vi vi (although taking longer to learn) has outstanding features and allow the user to be more productive.
<br><br>
'''Perform the Following Steps:'''
# Create the following directory structure (displayed on the right side) by issuing a single Linux command:<br>(You should know how to perform this task).<br><br># Issue the following Linux command to edit a text file called '''mytext.txt''' in the '''linux/practice''' directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">nano uli101/practice/mytext.txt</span><br><br>'''NOTE:''' When using the '''Nano ''' text editor, you are placed in '''INPUT''' mode, so you can enter text immediately.<br><br>
# Enter the lines shown in the other diagram of the nano text editor on the right side.<br><br>'''NOTE:''' The '''^''' symbol represents press the '''&lt;ctrl&gt;''' followed by a character.<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>
</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>
===Part 2: Creating Text Files Using The Vi vi Text Editor===
[[Image:vi-text-editor-2.png|right|350px|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 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 vi text editor.
'''Perform the Following Steps:'''
# Issue the following to run the Vi vi online tutorial:<br><span style="color:blue;font-weight:bold;font-family:courier;">/home/murray.saul/vi-tutorial<br><br>
# In the tutorial menu, select the first menu item labelled "'''USING THE VI TEXT EDITOR'''"<br><br>
#Read and follow the instructions in the tutorial. Eventually, it will display a '''simulated''' Vi vi environment and will receive step-by-step instructions on how to use this text editor.<br><br>
# When you have completed that section, you will be returned to the main menu. If you want to get extra practice, you can select the menu item labelled "'''REVIEW EXERCISE'''".<br><br>
# When you want to exit the tutorial, select the menu option to exit the tutorial.<br><br>
===Part 3: Manage / Manipulate Text File Content===
We finish conclude this tutorial by learning to use commands that manage the content contained instead text files whether it relate to to '''viewing file content ''' or '''manipulating ''' file content.<br><br>
'''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 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'''. 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;">more a.txt</span><br><br>Can you view or at least navigate to see all of the contents? <br>What is the advantage of using the more command?<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;">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 =
13,420
edits

Navigation menu