Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Worksheet Objectives Become familiar with the file system directory tree used in class Determine the current working directory with the pud command . Use the

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
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Worksheet Objectives Become familiar with the file system directory tree used in class Determine the current working directory with the pud command . Use the ls (list files) command with various options .Display hidden files and display file types .Examine and interpret the results of a long file listing .List individual directories and recursively list List all files in the reverse order and by the file size, and with the most recently modified .Use the shell metacharacters .Display the contents of text files with the cat and more commands Display the contents of text files with the tac and less commands Display portions of text files with the bead and tail commands Display the readable characters of an executable file with the strings command Display the file in octal format with the od command . Combine files using cat command Background: You will learn how to determine your current location in the directory tree and how to change from one directory to another Remembering which directory you are currently working in is often difficult. The pud (print working directory) command will display the absolute pathname of your current directory. The pwd command is used frequently to check the current location in the directory tree or hierarchy You can move from one directory to another with the cd (change directory) command. The directory location absolute pathname specifies a file or directory in relation to the entire file hierarchy. The hierarchy begins at the / (root) directory. Absolute pathnames always start at the root (/) directory and list each directory along the path to the destination file (or directory) A relative pathname describes the location of a file or directory as it relates to the current directory or the directory you are currently in. If you are in a directory and you want to move down the directory tree, you can type the path starting with the name of the next directory down in the directory structure. If a pathname does not begin with a slash, it is a relative pathname. Relative pathnames are useful because they are usually shorter than absolute pathnames. To use relative path names, you must know what directory you are currently in since that is your starting point The pwd command will tell you where you are in the directory tree or hierarchy. Shortcuts such as the tilde (-), dot/dot (.) can also be used with relative pathnames you wish to change to is specified using an absolute or relative pathname. An Use the diagram of the sample Class File system directory tree to assist with this lab. Page 1 of 12 CSC1 158 - Operating Systems Basics and Security Class File Tree Structure CSC156 Notice: Your home dictionary is homelcsc156/yourUserName Step 1. Open the terminal window Click Start>All ProgramsPuTTY(64-bit) folder PuTTY con enter centos" onto both of Host Name and Saved Sessions text box to open a terminal window. Connect CENTOS sever a Use your login name and password to login the server. Notice: the password will not show up You should now have a terminal window asking you to login Your account ld is your last name followed by your first initial, all lower case. For example, Sylvia Yeung would be: yeungs b. c. You will be prompted for your password. Your password is the word: Linux1s (Remember that Linux is case sensitive and will not display the password when you enter in it) Step 2. Use the Is Command with Arguments The 1s command will list any subdirectories and files that are in the current working directory You do NOT need to change the location to list the files and subdirectories Arguments for the is command can be directory name(s) and file name(s) (by using relative or absolute pathname) For example, use the absolute pathname to list all files or directories under the user's (user2 folder) home directory s ls /home/cac156/yourusername/user2 Or we can use the relative pathname to list all files and subdirectories if the user at his/her home directory. Use the Is command itself to list al files and subdirectories.s le a. Enter the command to verify what is your current location, what command do you enter at the shel? What is the result? b. c. Change to the user2 directory. What command did you use (either by relative or absolute pathname)? d. Then, change back to your home, what command did you use? Page 2 of 12 CSC156- Operating Systems Basics and Security e. Enter the command to display (or list) the contents of the dir2 directory using a relative pathname from your home directory What command did you use? b. What was the response? .Enter the command to list all the ties in the /etc directory (a standard LINUX drectory under the root ") using an absolute pathname What command did you use? d. Enter the command to list the files in the planets directory from the diagram using an absolute pathname? What command did you use? e. Enter the command to list only the dante file trom your home directory (to see if it exists and not see all other files and directories). What command did you use? (Using either absolute or relative pathname) Step 3. Use the Is Command to see Hidden iles File names that begin with a dot (.) are called hidden fles Hidden files are frequently used to customize a user's work environment (ex profile, .dtprofile, kshrc, cshrc etc). They are not shown by default because they are infrequently edited. The current directory link () and parent directory link (-) are also hidden and will not be displayed either since they begin with a dot Using the Is command with the-a (all) option will list all files in a directory, including hidden () files. Note that the-a option is lower case. Note: You should be in your home directory to answer the following questions. If not, change to your home directory first then answer the following questions a. Enter the command to verity where you are. What command did you use? b. What is the resut? C. Enter the basic 1. command without the any options. Do you to see any hidden fles (those that begin with a dot)? d. Enter the command that will allow you to see ALL files in your home directory? e. How many hidden files are there? Enter the following to create a new empty file called hiddenfile using the touch command (be sure to make the first character a dot). $ touch hiddenfile g. Enter the ls -a command again Is hiddenfile listed? Step 4. Use the Is Command to See File Types When using the ls command by itself, you can obtain a listing of directory contents but cannot tell which files are and which directories are. Page 3 of 12 CSC156- Operating Systems Baslcs and Security name Note that the-F option is The symbol (f present) is found at the end of the fie or directory n an upper case F. There are four LINUXIUNIX file types: Directory. Executable, ASCil teaxt file, and Symbolic link Directory - A forward slash () after the name indicates this is a directory (or subdirectory). A directory is considered a type of file with LINUXUNX ASCII Text File -If there is no symbol after the name this indicates a plain ASCli text file with no formatting characters in it. (ASCil is the American Standard Code for Information Interchange) An ASCII text file is similar to a DOS text file Executable- An asterisk (") after the name indicates that this is a command, an application or a script file, which can be run or executed Symbolic Link-An at sign (@) after the name indicates a symbolic link which is a way of giving a file an alternate name. Symbolic Inks are covered later in this course. a. From your home directory enter the basic 1s command without any options. Could you tell whether you are looking at files or directories if it were not for the fact that most of the directories have "dir in their name? b. Enter the command that will allow you to see the file names in your home directory c. List the names with symbol you see from the screen d. The /usrbin directory (a standard LINUX directory under the root) contains many and their TYPE. LINUX/UNIX executable commands, some of which you have already used. Enter the command to see the files and types in the lusribin directory What command did you use? e. What types of files are present? t. The letc directory (a standard LINUX directory under the root) contains many different type of LINUXUNIX system files. Enter the command to see the files and types in the /ete directory. What command did you use? g. Which different kinds of file types do you see? Step 5. Use the Is Command to Displaying a Long Listing The previous versions of the ls command displayed the names of directories and files in a wide format (across the screen). The la command can be used with the-I (long) option to see more detailed information on each file or directory. The 1s -1 option will also distinguish between files and directories. Note that the -I option is a lower case letter L For example Shown below is an example of a long listing for a file (dante) and a directory (dir1) from your user2 directory. The listing is interpreted as follows Enter the command: $ 1s -1 Page 4 of 12 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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

Review The New Employee, the case study for Chapter

Answered: 1 week ago