Question

Write a shell script called GetMyStuff.sh that will provide the above information (the script must be...

Write a shell script called GetMyStuff.sh that will provide the above information (the script must be a executable, and must work regardless of which directory it is in). Also, just saying cat MyStuff.txt is not sufficient. (1.0%)

A pipeline is the combination of at least 2 commands, where the output of command1 is the input for command2. The syntax is command1 | command2 where | is the pipeline operator. Read the man pages about the ls and wc commands. Devise a minimal pipeline command that will print the number of files and subdirectories in the current directory (including hidden ones, but not the current and parent directory entries). Put the answer into a text file named MyPipe.txt. (0.5%)

Describe the difference between wc `grep -l int *` and grep -l int * | wc. Why is it not giving the same output? Put the answer into a text file named Explanation.txt.(1.0%)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A minimal pipeline command that will print the number of files and subdirectories in the current directory is

1)$ ls -a1 | wc -l

Here ls -a1

-a: to get the directories and subdirectories including hidden files

-1: to make sure to list 1 directory per line

wc -l

-l: to count number of lines in a file

So we are piping the ouput of ls -a1 to the wc to get the number of files and subdirectories.

To put the answer into MyPipe.txt

$ ls -a1 | wc -l > MyPipe.txt

Difference between wc `grep -l int *` and grep -l int * | wc

Explanation.txt

$ wc `grep -l int *`

This is nothing but the count of newline, word, and byte counts for all the files in the current directory containing int

$ grep -l int * | wc

Here, first of all we are finding all the files which contains int in them and then piping the output to the wc. So we are printing out the newline, word, and byte counts of the output of grep -l int *

For any doubts feel free to ask.

Regards.

Add a comment
Know the answer?
Add Answer to:
Write a shell script called GetMyStuff.sh that will provide the above information (the script must be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Revision Question 3 on Linux. Please explain the shell script commands in the context of post...

    Revision Question 3 on Linux. Please explain the shell script commands in the context of post execution. You have just logged in and have a directory called "novel" in your home directory containing the following files: chapter1.docx chapter2.docx chapter3.docx draft.pdf save where "save" is itself a directory and contains the files Attributes.txt draft.pdf.1 draft.pdf.2 draft.pdf.3 indexA.txt indexB.txt list1.txt list2.txt a) Describe the results you would expect when executing the following shell commands: i) ls novel/save/*A* ii) ls novel/*r[23]* iii) rmdir...

  • Write a C shell script called canrun that displays the names of the files in the...

    Write a C shell script called canrun that displays the names of the files in the current directory that have execute permission set (permission being for the file owner) and how many of these files there are. For example, output from the script might look like: Executable files: canrun menunix showperm 3 files found

  • Write a script using simple shell commands. The script takes a command line argument that specifies...

    Write a script using simple shell commands. The script takes a command line argument that specifies a directory dir. The script first changes directory to dir, then prints the following in sequence: (a) A line starting “Current date and time: ”. Then on the same line, the current time and date. (b) A line starting “Current directory is : ”. Then, on the same line, the absolute pathname of the current working directory. (c) An empty line (d) The line...

  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

  • LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script,...

    LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script, we will iterate through all files in the current directory print out their name using the for loop. Example (do not type yet): foriin*;do …;done where the…does some operation on$I, which stands for the current file. To do this, enter the following in your script4.sh file:           #!/bin/bash           for i in *; do                echo $i           done Once the above works, change the for loop to...

  • QUESTION 1 What will be the output of following Unix command: find / -name ‘*’ A....

    QUESTION 1 What will be the output of following Unix command: find / -name ‘*’ A. List all files and directories recursively starting from / B. List a file names * in / C. List all files in / directory D. List all files and directories in / directory QUESTION 2 Which command is used to extract a column/field from a text file / input. A. paste B. get C. cut D. tar QUESTION 3 Which command creates an empty...

  • Hi I beed this assignment to be in a script in linux from codio. Can someone...

    Hi I beed this assignment to be in a script in linux from codio. Can someone please help me step by step thank you. Overview: In this milestone, you will demonstrate your ability to create a basic script in Linux. Review the Final Project Guidelines and Rubric document to see how this milestone will prepare you for the scripting portion of the project. You will perform this milestone in Codio in the unit called “Milestone 2: Scripting.” You will create...

  • A filename con comprise multiple embedded dots (e.g., a.b.c.d.e). True False A device file is not...

    A filename con comprise multiple embedded dots (e.g., a.b.c.d.e). True False A device file is not really a stream of characters and doesn't contain anything at all. True False Relative pathnames begin with the root directory. True False Running the ls -a command uniquely identifies directories and binary executables. True False What is the result of running mkdir -p share/man/cat1 from the command line? a. It creates the directory share. b. It creates the directory share/man. c. It creates the...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

  • Write an awk script to print just the name and size of ordinary files (do not...

    Write an awk script to print just the name and size of ordinary files (do not include directories), one on each line. The output must be aligned as shown in the example below. First, analyze a typical output of the ls -l command to see what differentiates an ordinary file from a directory and which fields contain the file name and size information. Then, determine what the field separator is and whether the default field separator of awk will work,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT