Changes

Jump to: navigation, search

Tutorial2: Unix / Linux File Management

776 bytes added, 17:37, 10 January 2020
Part 3: Manage Text File Content
# View the following table of Text File Management commands Your instructor should have demonstrated in class how to use these commands):<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>'''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>lists 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>lists 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>lists files modified less than 5 minutes ago</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>
# 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? 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;">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 a.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 a.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 a.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 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, 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>
13,420
edits

Navigation menu