Question

In: Computer Science

can you please do the following? (8) Step 8: type the following command: sort /etc/passwd |...

can you please do the following?

(8) Step 8: type the following command:

sort /etc/passwd | head -5
What is the output?

Notice that this pipe can be simplified

cat /etc/passwd | head -5
What is the output for this?

You could accomplish the same thing more efficiently with either of the two commands:

head -5 /etc/passwd
head -5 < /etc/passwd

(9) Step 9:

The command displays all the files in the current directory sorted by file size

ls -al | sort -n -r +4
What is the output? What are the outputs sorting according to? Which column is this?

The command ls -al writes the file size in the fifth column, which is why we skip the first four columns using +4.

The options -n and -r request a numeric sort (which is different than the normal alphabetic sort) in reverse order

awk

Topics covered: processing columnar data

Utilities covered: awk

The awk utility is used for processing columns of data

(10) Step 10:

The following example shows how to extract column 5 (the file size) from the output of ls -l

ls -l | awk '{print $5}'
What is the output?

Cut and paste this line into a Bourne shell and you should see a column of file sizes, one per file in your current directory.

(11) Step 11:

The following example shows how to sum the file sizes and print the result at the end of the awk run

ls -al | awk '{sum = sum + $5} END {print sum}'

In this example you should see printed just one number, which is the sum of the file sizes in the current directory.

Shell Scripts

Topics covered: storing commands in a file and executing the file

Utilities covered: date, cal, last (shows who has logged in recently)

(12) Step 12:

Store the following in a file named simple.sh and execute it

#!/bin/sh
# Show some useful info at the start of the day
date
echo Good morning $USER
cal
last | head -6

What is the result after you execute it?(Shows current date, calendar, and a six of previous logins Notice that the commands themselves are not displayed, only the results )

last command - display login and logout information about users and

     terminals

(13) Step 13:

To display the commands verbatim as they run, execute with

sh -v simple.sh

Another way to display the commands as they run is with -x

sh -x simple.sh

What is the difference between -v and -x? Notice that with -v you see '$USER' but with -x you see your login name

Run the command 'echo $USER' at your terminal prompt and see that the variable $USER stores your login name

With -v or -x (or both) you can easily relate any error message that may appear to the command that generated it

(14) Step 14:

When an error occurs in a script, the script continues executing at the next command

Verify this by changing 'cal' to 'caal' to cause an error, and then run the script again

Run the 'caal' script with 'sh -v simple.sh' and with 'sh -x simple.sh' and verify the error message comes from cal

Other standard variable names include: $HOME, $PATH, $PRINTER. Use echo to examine the values of these variables

Solutions

Expert Solution

Step 8
************

Step 9
***********

Step 10
**********

Step 11
************

Step 12
***********

Step 13
*************

Step 14
***********

if you have any doubt then please ask me without any hesitation in the comment section below, if you like my answer then please thumbs up for the answer, before giving thumbs down please discuss the question it may possible that we may understand the question in a different way and I can edit and change the answers if you argue, thanks :)


Related Solutions

This lab will explore the password files. a) Open a terminal window and type less /etc/passwd....
This lab will explore the password files. a) Open a terminal window and type less /etc/passwd. Which line describes the root account? b) Type ls –l /etc/passwd. Who is the owner of the passwd file? What are the permissions? c) Type less /etc/shadow. What is in the password filed for most of these accounts? d) Type ls –l /etc/shadow. Who owns this file and how do the permissions differ from the /etc/passwd file? e) Type cat /etc/default/useradd. What is the...
please do it step by step with the use of formulas , thank you.. The following...
please do it step by step with the use of formulas , thank you.. The following are monthly percentage price changes for four market indexes. Month DJ SP500 1 0.03 0.02 2 0.07 0.06 3 −0.02 −0.01 4 0.01 0.03 5 0.05 0.04 6 −0.06 −0.04 Russ500 Nicky 0.04 0.04 0.10 −0.02 −0.04 0.07 0.03 0.02 0.11 0.02 −0.08 0.06 (17 points) Compute the following. a. Average monthly rate of return for each index b. Standard deviation for each index...
please explain the following command sequences a) who | grep "Seneca" | sort | uniq >>who<<...
please explain the following command sequences a) who | grep "Seneca" | sort | uniq >>who<< b)sort <names > names c)sort ~/files/phone 1> /dev/null2>phone2 d)ls/root/&> files.log e)ls/etc/>files.log2>&1
PLEASE EXPLAIN AND SHOW HOW TO DO THESE! (especially all the passwd ones!!) Perform the following...
PLEASE EXPLAIN AND SHOW HOW TO DO THESE! (especially all the passwd ones!!) Perform the following on your Linux instance: -Execute the command ls -l /etc/hosts /fakepath. Send the standard output to a file named ${HOME}/ls-stdout and the standard error to a file named ${HOME}/ls-stderr. -Print the text Hello, World! to a file named ${HOME}/info. Overwrite the file if it already exists. Then, append the text The date is: to the ${HOME}/info file. Finally, append the standard output of the...
Can you show how to do this step by step using Matlab please. Write a function...
Can you show how to do this step by step using Matlab please. Write a function with header [S] = myAddString(S1, S2), where S is the concatenation of the stings S1 and S2. Test Cases: S = myAddString(myAddString('Programming', ' '), myAddString(' is ', 'fun! ')) S = Programming is fun!
At the command prompt, type cd etc and press Enter. What error message did you receive...
At the command prompt, type cd etc and press Enter. What error message did you receive and why?
What is normalzing a wavefunction and how do you do it step by step? Please show...
What is normalzing a wavefunction and how do you do it step by step? Please show TWO different examples (one for SHO question, an IPW question, etc) Thanks!
Can you please show how you would solve the following using excel? Step by Step? Kaelea,...
Can you please show how you would solve the following using excel? Step by Step? Kaelea, Inc., has no debt outstanding and a total market value of $117,000. Earnings before interest and taxes, EBIT, are projected to be $8,300 if economic conditions are normal. If there is strong expansion in the economy, then EBIT will be 23 percent higher. If there is a recession, then EBIT will be 32 percent lower. The company is considering a $41,700 debt issue with...
What does the ​ ping command do? Please type "ping -c 4 8.8.8.8" and explain the...
What does the ​ ping command do? Please type "ping -c 4 8.8.8.8" and explain the output. What is this "8.8.8.8" IP address? Please briefly explain what happens behind the curtain when the ping command runs.
Can you please provide a step by step instruction to get to the answer to the...
Can you please provide a step by step instruction to get to the answer to the following question WACC. Kose, Inc., has a target debt-equity ratio of .38. Its WACC is 10.1 percent and the tax rate is 25 percent. a) If the company’s cost of equity is 12 percent, what is its pretax cost of debt? b) If instead you know that the aftertax cost of debt is 6.4 percent, what is the cost of equity?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT