Changes

Jump to: navigation, search

Tutorial2: Unix / Linux File Management

461 bytes added, 16:49, 6 January 2021
Part 3: Manage / Manipulate Text File Content
# 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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/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 /home/your-seneca-id/a.txt /home/your-seneca-id/a.txt.bk</span><br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp /home/your-seneca-id/a.txt /home/your-seneca-id/b.txt</span><br><br># Issue one of the commands you learned to display the contents of the file called '''/home/your-seneca-id/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 /home/your-seneca-id/a.txt /home/your-seneca-id/aa.txt</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 /home/your-seneca-id/aa.txt /home/your-seneca-id/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 aa.txt 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 . /home/your-seneca-id/ </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 /home/your-seneca-id/aa.txt /home/your-seneca-id/b.txt /home/your-seneca-id/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''', '''section 2''' "Basic Unix Commands" (parts '''4''' to '''6''') labelled:<br> '''Managing Files''' , '''Accessing Files''' and '''Review Exercise'''.<br><br>
13,420
edits

Navigation menu