LAB ASSIGNMENT 2 CIT210 SPRING 2024

.pdf

School

Los Angeles City College *

*We aren’t endorsed by this school

Course

03

Subject

Computer Science

Date

May 7, 2024

Type

pdf

Pages

22

Uploaded by ColonelOxideBeaver30 on coursehero.com

Department of Computer Science Spring 2024 CIT210/L OP. SYS. MANAGE (Lab Assignment 2) (100 Points) Lab 2: Linux Directory Structure, Linux and Windows File Server, Windows Server Disk and Storage (Important Note: Some of the Tasks, Commands or Steps may not work, You need to Research, Troubleshoot and Modify Configurations to make it work for your Network Environment to get Full Credit) Task 1: Explore Linux Commands (20 Points) Visualizing file contents means displaying file contents in the screen so you can read them. 1. cat View files with the cat command. It will dump the contents of a file to another file, to the screen, or to another command. cat is short for concatenate, and can be used to sequence several files together into a larger file. For example, $ cat /etc/passwd 2. more View information one page at a time with the more command. $ more /etc/passwd 3. less Use less to view a text file with the ability to scroll up and down through the document and search for text patterns. $ less /etc/passwd 4. head This command is limited to the first several lines, you will not see how long the file actually is. By default, you can only read the first 10 lines of a file. You can change the number of lines displayed by specifying a number option (e.g. 7) as shown in the following command: $ head -7 /etc/passwd 5. tail The reverse of head is tail. Using tail, you can view the last ten lines of a file. $ tail -7 /etc/passwd 6. sed Stream editor Sed is a complex and powerful command. You can edit a file from the command line or from a script, replacing one word or expression/pattern with another. $ echo "A cow is grazing in the summer" > linuxtest3.txt
Department of Computer Science Spring 2024 $ echo "in the middle of June when all the" >> linuxtest3.txt $ echo "other cows are out in the field." >> linuxtest3.txt $ cat linuxtest3.txt | sed s /cow/computer/ > linuxtest4.txt What is the output of the above commands? _____________________________________________________________________________________ _____________________________________________________________________________________ 7. diff Find differences between two files Finding the difference between the two files from the previous example: $ diff linuxtest3.txt linuxtest4.txt Diff is useful when you are writing books or code and want to see which changes was made between two versions. 8. Pipes A pipe channels the output of one program to the input of another Allows programs to be chained together Programs in the chain run concurrently Use the vertical bar: | For example, pipe the output of echo into the program rev (which reverses each line of its input): $ echo Happy Birthday! | rev !yadhtriByppaH Task 1.2: Redirecting and piping standard output Redirecting:>,<, and >> a. Noticeably, outputs and errors are displayed on terminal screen by default. To force the outputs and possibly errors to place other than terminal display screen, the users need to redirect them to the final destination. In other words, a program can be told where to look for input and where to send output, using input/output redirection. Linux uses the less than and greater than special characters (< and >) to signify input and output redirection, respectively. 1. Obtain a list of files from the home directory, including the hidden files. Redirect the output to a file named Listing by using $ ls a>listing What is the output of the above command? _____________________________________________________________________________________ _____________________________________________________________________________________
Department of Computer Science Spring 2024 2. Use the command to view the file and pipe the output to less. $ cat listing | less What is the output of the above command? _____________________________________________________________________________________ _____________________________________________________________________________________ 3. The system will create 1.txt if it does not exit. If 1.txtexits, the new entry will overwrite the existing ones, namely it wipes out all currently existing contents. $ echo How are you? > 1.txt 4. Will read the contents of 1.txt and use them as input to the cat command. cat< 1.txt >> is similar to >, but it appends standard output to a file without overwriting the existing contents. For example, $ echo I am learning Linux. >> 1.txt adds a new line to the 1.txt file. Grep Show lines matching a pattern With this command, you can pick lines containing a specific word /phrase from of a file. Grep is a very complex command but we will use it in its simplest form: $ grep "am" 1.txt This command will display all the lines in testfile containing the word am . if you want to send the output generated by command A to as input command B, you need to build a pipe between command A and B. They pipe is a temporary, dedicated communication channel between the two linked commands. For example, $ date | wc The command date generates outputs current date and time. The pipe, denoted by | grab the outputs and send them to wc command as input. Consequently, wc counts the number of words and letters and display the final result on screen. The final results are products of date and wc
Department of Computer Science Spring 2024 through the piping. In Linux, pipes connect the standard output of one command to the standard input of another command. You can pipe more than two commands. For example, $ cat 1.txt | wc> 2.txt $ cat 2.txt Task 1.3 :Creating Files - Editors 1. We will create a file named shopping_list, and instead of using an editor use the cat command and type (Ham, Spam,Kolbassa) # cat>shopping_list Ham Spam Kolbassa Press ctrl-d a. Greater-than sign (>) necessary to create the file b. The text typed is written to a file with the specified name c. Press ctrl+d after a line-break to denote the end of the file The next shell prompt is displayed 2. The cat command will display the contents of a file whose name is given as an argument: # cat shopping_list Ham Spam Kolbassa double greater-than symbols (>>) append to a file: # cat >> shopping_list Broccoli ctrl-d # cat shopping_list Ham Spam Kolbassa Broccoli Task1.4 Exercise: Finding files 1. which,whereis : Find out where a file is on the system
Department of Computer Science Spring 2024 Which, whereis and locate are useful for fast searching. Common for them is that they don t search the entire system, but only a specific part. Try the following examples and look at the output: $ which chmod What is the output of the above command? _____________________________________________________________________________________ _____________________________________________________________________________________ $ where is chmod What is the output of the above command? _____________________________________________________________________________________ _____________________________________________________________________________________ 2. find: Search for file find is used to search your system for files matching a certain criteria. $ find ./ -name linuxtest3.txt (find files named linuxtest3.txt under current directory.) $ find /var -cmin -30 2>/dev/null (find files under /var, for which status has changed within 30 minutes.) 3. file: Determine file type Try the following commands: $ file /bin/ls $ file /etc/printcap $ file linuxtest3.txt Task1.5: Changing File Permissions Once logged in we'll create a file and set permissions on it in various ways. $ echo test file > working.txt $ ls l working.txt Write permissions of woking.txt file __________________________________________________________
Department of Computer Science Spring 2024 $ chmod 444 working.txt Check permissions using list (ls l) command and Write the new permissions of woking.txt file. ____________________________________________________________________________________ In spite of the fact that the file does not have write permission for the owner, the owner can still change the file's permissions so that they can make it possible to write to it. $ chmod 744 working.txt Or, you can do this by using this form of chmod: $ chmod o+w working.txt What happens? Define the output? (Use ls l) commands to check the permissions) __________________________________________________________ $ chmod u-r working.txt What happens? __________________________________________________________ $ chmod 777 working.txt What happens? __________________________________________________________ Task 1.6 : Creating aliases 1. Create an alias, aliases allow a string to be substituted for a word when it is used as the first word of a simple command. 2. Enter the following on the command prompt $ alias l="ls -l" $ alias la="ls -la" This will create an alias to the command ls l and ls al Enter each of the following commands in turn and write the output
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