Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC156-Operating Systems Basies and Security rv.:--r.. 1 .r2 staff 320 Dec 7 11:43 dante r.x s user2tatt 512 Dec 4 13:43 diri first position of

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
CSC156-Operating Systems Basies and Security rv.:--r.. 1 .r2 staff 320 Dec 7 11:43 dante r.x s user2tatt 512 Dec 4 13:43 diri first position of the display indicates whether this is a file or a directory. The lower case letter d indicates a directory, the dash() indicates a file The next group of characters (r.wx and dashes) are the permissions for the file or directory Next is the number of links (1, 5), followed by the Sle owner (user2), the le or directory access group (staff), file size (320, 512), the date and time created (or modified) and then the name of the file or directory, Links, owner and group are covered later in the course Change to your user2 directory form your home directory. What command did you use by using the relaive pathname? a. b. From your user2 directory, enter the basic 1a command without any optons What information was displayed on each fie or directory listed? c. Enter the command that willalow you to see a long listing for the fie names at your user2 directory. What command did you enter? d. How many files are over 300 bytes in size? e. Who is the owner of these files? Note: Using (time) option will list Sles with the most recently modifed at the top of the ist To get a detailed (long) isting of files sorted by time (most recent at the top) use the $1s -it version of the command. t Enter the 1s -1t command. What is the most recently created or modified fle? Using -S option to sort files by file sizes g. Enter the command to sort by file sizes and long list What command do you use? h. What is the flename for the biggest file size? Using -r option to sort flies by the reverse order L Enter Is -I command, do you see all files list by the alphabetical order? Enter the command to list long ist as well as sort the files by the reverse order what command do you use? What is the first filename from the list? k. Step 6. Use the la Command to List Individual Directories and Recursively Use la -ld to display detailed information about a directory, but not its contents, This is useful when you want to see the properties of a directory and not the information about its contents Use is -R (recursive) to display the contents of a directory and all of its subdirectories Recursive means to do again and again. This option is useful if you want to see all directories subdirectories and their contents for a particular part of the directory tree. If this is done at a high Page 5 of 12 CSC158 - Operating Systems Basics and Security level in the directory structure the output can be substantial. Note that the-R option is an upper case R a. Change back to your home directory. What command did you use? b. From your home directory, enter the command that wil provide a long liating of just the information for the dir2 directory not the contents. (Ether absolute or relative) c. From your home directory, enter the command that will provide a long isting for just d. From your home directory, enter the command that wil provide a recursive lsting for a. From your home directory, enter the command that wll provide a recursive listing for the information on the fruit directory using a relative pathname the dir2 directory the user2 directory Step 7. Use the 1s Command With the Asterisk ) Metacharacter Also, you will work with various metacharacters and use them with the 1s command to refine your directory listings. Metacharacters are keyboard characters with special meaning to the shell. A general definition of a metacharacter is any keyboard character that is not alphanumeric Metacharacters are used with many LINUX commands to provide greater flexiblity. Some of the metacharacters used with LINUX are similar in function to those used with DOS. The asterisk () and the question mark (?) are metacharacters which are also known as wildcards. You will work with the 1s command and the following common metacharacters with this lab Function Shortcut to home directory Character substitution (also called splat) Character substitution Metacharacter Name Tilde Asterisk Question Mark Square Brackets Range definition The asterisk () is a substitution symbol that represents zero or more characters, except the leading dot on a hidden file. The asterisk is often referred to as a wildcard character. If there were a large number of files in a directory and you only wanted to see a listing of project files that started with p1 you could use the asterisk to imit the numbers of fles listed. As an example, enter the command as: $1a p This command would list all files and directories starting with p and any number of characters after that. The asterisk can be placed anywhere (beginning, middle or end) of the string being tested and can appear multiple times. If you enter $1a d* you will see only those fles beginning with the letter d and the contents of any subdirectories that start with the leter d a. What command will you change to user2 directory? b. Enter the command to list files and directories from your user2 directory that start with the letter f. What command did you use? What was listed? c. Page 6 of 12 CSC156.Operating Systems Basics and Security d. Entor the command to Iist files and directories in your userz directory that start with the letter d. What command did you use? e. What was listed? Enter the command to list files and directories in your user2 directory that end with the number 1. What command did you use? g Enter the command to list files and directories in your user2 directory that have the characters "ru' anywhere in the file name. (Hint maybe it starts with ru or in the middle or at the end of filenames.) What command did you use? -.. . _ What was listed? h. Enter the command to list files and directories in the coffees directory that start with the letter n using a relative pathname What command did you use? What was listed? j. Step 8. Use the 1s Command With the Question Mark The question mark (?) is a substitution character that matches any single character, except for the leading dot on a hidden file. The question mark is also referred to as a wildcard character The example below shows the use of the Is command using the question mark in the fourth position. Enter the command: s is dir? This indicates that the file or directory name must start with dir but any character can be in the fourth position and the file name cannot be more than four characters long a. Enter the command to list files and directories in your user2 directory that start with the letters file in the first four positions with anything in the fith position but are not longer than five characters. What command did you use? b. What was listed? c. Enter the command to list files and directories in your user2 directory that start with etter f in the first position with anything in the second and third positions and the characters e3 in the last two positions that are not longer than five characters What command did you use? What was listed? d. Step 9. Use the ls Command With Square Brackets Square brackets (I1) can be used to match a set or range of characters for a single character position in the file or directory. The characters inside the brackets do not generally need to be in any order, for example, [abcj is the same as (cab). However, if you are looking for a range cf characters, they must be in proper order (for example, [a-z] or [3-9). If you want to search for all alphabetic characters, whether lowercase or uppercase, use [A-z] for the pattern to match. You can use alphabetic or numeric characters for the search pattern Page 7 of 12 CSC156-Operating Systems Basies and Security The examples below uses square brackets along with the asterisk wildcard character. The first example a range and will list all fles and drectories that start with the lower case letters b through fwith anything after that. The second example specifies that the frst character must be either the leter a or f and anything can be afher that dante diri dira filei file3 fruit practiee dante_1 dir2 dir sle2 tiles trusta tilei file2 tile) file4 truit truit2 a. Enter the command to lst files and directories in your user2 directory that start with the letters f through p with anything in the remaining positions. What command did you use? b. Enter the command to ist fies and directories in your user2 directory that start with any characters but have the numbers 1 through 3 in the last character. what command did you use? c Enter the command to list files and directories in your user2 directory that start with either d or p and have any characters in the remaining positions What command did you use? Step 10. Use the BASH Shell Metacharacters Another import feature of the shell includes shell metacharacters t characters that have special meaning The shell metacharacters are shown in the following table Special home dieectory variabie a At the prompt, type echo This is OK. What will it display? b. At the command prompt type echo Don't do this and press Enter. Press the Ctrl and e keys together to cancel your command and return to a shell prompt Which character needs to be protected in this above command? c. At the command prompt, type echo "Don't do this" and press Enter. What is displayed on the terminal screen? d. At the command prompt, type echo Donl't do this and press Enter. What is displayed on the terminal screen? Page 8 of 12 CSc156- Operating Systems Basics and Security At the command prompt, type echo SSHELL and press Enter to view the expansion of a variable using a shell metacharacter What is displayed on the terminal screen? f. Next, type echo $TEST and press Enter to find out what happens when a variable that does not exist is used in a command. What is displayed? g. At the command prompt, type echo $0 (Hine: number zero not letter O) and press Enter to view the expansion of a variable using a shell metacharacter What is the resul? h. At the command prompt, type echo You have $4.50 and press Enter. What is displayed? Which character needs to be protected in the previous command? i. i At the command prompt, type echo "You have $4.50 and press Enter k. Did the single quotation marks protect this metacharacter from shell interpretation? L. At the command prompt, type echo "You have $4.50 and m. Did the double quotation marks protect this metacharacter from shel n. At the command prompt, type echo You have 1$4.50 and press Enter What is displayed? press Enter. What is displayed? interpretation? What is displayed? Did the backslash protect this metacharacter from shell interpretation? o. At the command prompt, type echo My name is whoami (note: back quote' here that is the one key above the Tab key) and press Enter What is displayed? What function do back quotes ( ) perform here? p. At the command prompt, type echo There are S(who | we -) users on the system and press Enter. (note: 1 (pipe) is one key above the Enter key) What is displayed? What function do $(commands) perform? At the command prompt, type echo dir1/coffees*, what is the result? q. r. At the command prompt, type echo dir1/coffeesl, what is the result? Step 11. Determine File Type with The file Command There are many types of files found on a LINUX/UNIX system. The file type can be determined by using the file command. This information can be important when a user is attempting to open or read a file. Determining the file type can help a user decide which program or command to use to Page 9 of 12 CSC156 - Operating Systems Basics and Security open the file. The output from this command will most often be one of the following Text Executable or Data Text Files - Examples include ASCIl or English text, commands text, and executable shell scripts. This type of file can be read using the cat o or another text editor more commands and can be edited using i a. Change to the user2 directory, what command do you use? b. Use the file command to determine the file type for the dante file in your user2 c. What kind of file is it? Executable or Binary Filles - Examples include 32-bit executable and extensible linking format (ELF) code fies and other dynamicaly inked executabies. This file type indicates that the fie is a command or program. a. Use the tile command to determine the file type for the cal file under the lusribin directory, (Hint the standard directory lusr/bin directly under the root 'n) What command do you use? b. What kind of file is it? files are created by applications running on the system In some cases the type of file is indicated; for example, FrameMaker (Desktop Publishing software) document. a. Use the file command to determine the file type for the beans file is in the dir /coffees subdirectory. What command do you use? b. What kind of file is it? Step 12. Display the Contents of a File with the cat and tac Command The cat (short for concatenate) command displays the contents of a text file on the screen It is often used to display short text files such as script files (similar to batch files). The -n option causes the cat command to display a number at the beginning of each line of output. The tac command concatenates and prints the fles in reverse on the screen. (Opposite of cat To venity the current location, what command do you use? What is your current location? Use the command to copy the dante file from your user2 directory to practice directory with a new named: danteNew. What command do you use? (Hint use cp a. b. C. Use this command to display the contents of the danteNew file in your practice directory from your current user2 location, What command do you use? d. e. Use the command to print the fles in reverse on the screen of the danteNew file in your practice directory. What command do you use? f. To see the contents displayed with line numbers of the dante fle in your user2 directory. What command do you use? Step 13. Use the strings Command The strings command can be used binary file. Someone with a programming background can interpret the output produced by strings. The command is introduced characters of to print out readable characters in an executableor here solely as a method for demonstrating the printable an executable file. The stringa command must be used to read an executable file such as Jusrbin/cal. The atringa command aiso shows the usage syntax of the command in most cases. Page 10 of 12 CSC156-Operoting Systems Basics and Security The od command can be used to dump files in octal formats a. Also, use the is command we have learn to see the file type of lusribin/cal, what command and option will you use? b. What is the file type? c. Use this command to see the readable characters in the lusr/binical executable fle. (Hint the standard directory /usr/bin directly under the What command do you use? root "r d. Use this command to find out the Sle type of letciauto.net flie? Hint use the file command) What is the type of the letclauto.net file? e. To see the readable characters in the letc/auto.net file, what command do you use? t. Use this command to see the letclauto.net file in octal format, what command do you use? Step 14. Display the Contents of a Fle with the more Command The more command is the preferred method of displaying a text fle since it automatically displays the file contents one screen at a time if the information in a file is longer than one screen, the following message appears at the bottom of the screen where n is the percentage o the file already displayed "More. (n%). Pressing the Enter key continue the display one ine at a time. The Space bar will continue one screen at a time a Use this command to display the contents of the dante file from your user2 one page at a time. What command do you use? key unti-More-Kn%)" message is gone. b. Press this c. Use the more command to view the content of lusrbinical file, what is the result? d. Use the command to see the lusr/bin/ical in octal format. What command do you e. Use the command to change to the practice directory, what command do you use? use? Step 15 Display Portions of a File with the head Command The head command is used to display the first n lines of one or more text files. The first 10 lines are displayed by default if the -n optsion is omitted. The head command is useful when you only want to check the first few lines of a file regardless of its length. For example, head-5 test1 or head-n5 test1 show first five lines of the test1 fle a. Use the head command by itself to display the first portion of the dante fle under your user2 directory from your current practice directory. What command do you use? How many lines were displayed by default? Change back to the user2 directory, what command do you use? What command did you enter? b. c. d. Use the command to display the first 5 lines of the dante file in your user2 directory. Step 16 Display Portions of a File with the tail Command Use the tai1 command to display the last n lines of a fle. The last 10 lines are displayed by default if the -n option is omitted. The tail command is useful for checking the most recent entries in large log files. Backup utility programs frequently write their results to a log file showing Page 11 of 12 CSC156-Operating Systems Basics and Security fles were backed up and when. The finai entries in a backup log file are usually the total number of files backed up and messages indicating whether the backup finished successfuly The -n option displays the last n lines of the file a. Use the tal command by itself to display end of the dante file in your user2 directory. What command did you enter? b How many lines were displayed by defaut? c. Use the command to display the last 5 lines of the danteNew fle in your practice directory from your current user2 directory. What command did you enter? Step 17. Combine the files one after the other by using cat command a. Combine one fle after the other for the fruit fle and truit2 file from the user2 directory b. Check the file type of newfruit, what command do you use? (Hnt use the file command) c. and save the combined file named as newfruit onto the practice directory. what command will you use? View the contents of the newfruit Ble, what command will you use? Step 18. Logout and Close the Terminal Window Page 12 of 12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

d. What language(s) did they speak?

Answered: 1 week ago