OPS102 - Week 3 - Lab

.docx

School

Seneca College *

*We aren’t endorsed by this school

Course

102

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

13

Uploaded by ColonelDiscovery13270 on coursehero.com

OPS102 – Week 3 – File Systems - Sample Lab Student Name: <Elsa Koci> Student ID: <148757230> Activity 1: File Globing When issuing Linux or Windows commands, it may be more efficient (less typing) to use filename expansion symbols also called File Globing to match files that share similar characteristics (e.g. same file extension) when issuing Linux commands. Example : You can use a special character to indicate to the Bash shell to match all files that end with the extension ".txt" in your current working directory: ls *.txt a.txt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt Below are the most common Filename Expansion symbols and how they are used for filename expansion: Filename Expansion Symbol Purpose * Asterisk (*) to represent 0 or more characters ? Question mark (?) to represent exactly one character (any character) [ ] Square brackets ([ ]) to represent and match for the character enclosed within the square brackets . It represents ONLY ONE character - it's like a Question Mark (?) but with conditions or restrictions. [! ] Square brackets containing an exclamation mark immediately after the open square bracket ([! ]) to represent and match and OPPOSITE character for the character enclosed within the square brackets.
Consider following file hierarchy for the activities in this section. This applies to both of Linux and Windows. You will now get practice issuing file management commands using filename expansion symbols . We will be using the directory structure given above. A great way to practice filename expansion, use the touch command on Linux to create a lot of empty filenames (for windows use any preferred way to create such files.), write the ls/dir commands that use filename expansion , predict the filenames that will be display, and finally run the command to check your work. Perform the following steps for Linux and repeat them for windows using equivalent commands learnt previously: 1. Issue a Linux command to move to the examples directory (i.e. under practice directory as shown in diagram to the right). 2. Issue a Linux command to confirmed that you have moved to the examples directory. 3. Issue the touch command to create the following empty text files in the examples directory: (note upper and lowercase letters) abc.txt def.text hij.TxT 1a4.txt
123.TXT 456.txt 6u9.txt ab2.html 1234.txt abcdef.txt abcde.txt 4. If you encounter errors, then make corrections (eg. viewing directory contents , check for correct filename syntax , case sensitivity , missing files , files in the wrong location , etc.) 5. Issue the ls command to get a listing of files in your examples directory. The output should look identical to the diagram displayed below. You can refer to this listing to see all files so you can then predict the output from Linux commands that use filename expansion symbols. Figure 1. Linux: Creating Directories and Files
Figure 2. Windows: Creating Directories and Files 6. What do you think the output will be from the following Linux command? ls ???.txt Write down the expected output on paper, then issue the command to check your answer. 1a4.txt 456.txt 6u9.txt abc.txt 7. What do you think the output will be from the following Linux command? ls ?????.txt Write down the expected output on paper, then issue the command to check your answer. 1234.txt 8. What do you think the output will be from the following Linux command? ls ??????.txt Write down the expected output on paper, then issue the command to check your answer. abcdef.txt 9. What do you think the output will be from the following Linux command? ls [0-9].txt Write down the expected output on paper, then issue the command to check your
answer.br>Did the command work? NO What does this teach you about the character class [ ] symbol? The expected output: No such file or directory. In the above case, should be displayed all files whose name contains only one character in the interval [0-9]. Since we do not have such a named file, the command will not work. 10. What do you think the output will be from the following Linux command? ls [0-9][0-9][0-9].txt Write down the expected output on paper, then issue the command to check your answer. 456.txt 11. What do you think the output will be from the following Linux command? ls [a-z][a-z][a-z].txt Write down the expected output on paper, then issue the command to check your answer. abc.txt 12. What do you think the output will be from the following Linux command (using character class with UPPERCASE letters)?: ls [A-Z][A-Z][A-Z].txt Write down the expected output on paper, then issue the command to check your answer. “No such file or directory” 13. What do you think the output will be from the following Linux command (using character class using alpha-numeric characters)? ls [a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9].txt Write down the expected output on paper, then issue the command to check your answer. 1a4.txt 456.txt 6u9.txt abc.txt 14. What do you think the output will be from the following Linux command? ls *.txt Write down the expected output on paper, then issue the command to check your answer. Did ALL text files get listed? Why not? 1234.txt 1a4.txt 456.txt 6u9.txt abc.txt abcde.txt abcdef.txt Not all text files are listed, but only those with the suffix “.txt”. 15. What do you think the output will be from the following Linux command? ls *.[tT][xX][tT] Write down the expected output on paper, then issue the command to check your answer. Did ALL text files get listed this time? If so, why? 123.TXT 1234.txt 1a4.txt 456.txt 6u9.txt abc.txt abcde.txt abcdef.txt hij.TxT Only 2 files are not listed: ab2.html and def.text. This is because the command only lists files that have the suffix .txt (where the letters of the suffix can be uppercase or lowercase).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help