Unix/Linux Assignment 8 Please Help! 1. In an earlier assignment, you created a
ID: 3917578 • Letter: U
Question
Unix/Linux Assignment 8
Please Help!
1.
In an earlier assignment, you created a fileAsst directory containing several files.
Give a command that will create a file named listing.dat, in your current (commandsAsst) directory, containing a list of the names of all the files in your fileAsst directory.
The listing must not include dates, file sizes, or any information other than the names.
2.
Someone has decided that the function sequentialInsert, declared in ~cs252/Assignments/commandsAsst/project/arrayops.h, should be renamed orderedInsertion. Give a command to produce the altered version the header file, saving it as ~/UnixCourse/commandsAsst/arrayops.h
3.
That English paper you were writing on the works of Lewis Carroll is due in a few hours and you have forgeotten the name of the text file in which you has written a number of quotations to use in your paper. Luckily, you know that the file is somewhere in your ~/UnixCourse directory or in some subdirectory directly or indirectly within it. You also know that the file name ended in ‘.txt’. You are pretty sure that you could recognize the file from just the first line.
You seem to recall having heard that there is a Unix command head that will print the first few lines of any file and suspect that, with the proper parameters, it could be used to print just the first line. (Hint - part of your task in this question is to show that you can use the built-in Unix help facilities.)
But you really don’t want to type that command out for every file or even every directory. What command would you give to produce a listing of the names of all the text files (as absolute paths) in ~/UnixCourse or its subdirectories (possibly nested several layers deep) followed immediately by the first line of text within that file? E.g., to produce a listing looking like this:
Note that the output format must look like the example above. (That’s not unreasonable, as one of the things you should have learned from this lesson is that the output of one command is often fed into later commands, which must be able to read it.) In particular, all files should be listed and absolute paths and solutions that add extraneous characters around the file name (e.g., << or ==>) are not correct.
4.
Every time you issue a command in Linux, a new process is launched to run that command. Some of these processes end immediately upon completion of the command. Some may hang around or may spawn additional processes of their own.
The command ps -Af will display a listing of all processes running on the same machine as you are. This includes processes being run by lots of other people. Part of the information shown is the name of the command that launched the process. It also will show the login name of the account that launched that process. Try it now and examine its output.
You may have noticed that there are a substantial number of system processes running under the account name root.
What command would you enter to get a count of the number of non-system (not owned by “root”) processes running on the machine where you are logged in?
Explanation / Answer
Solution: -
1) $ ls -l fileAsst | grep '^-' | cut -d " " -f 9 > listing.dat -> here ls -l is used to get all the list of files and directories. Now the output is used to grep as files starts with '-'. Using cut command to get the 9th column and redirected to listing.dat so to get only the name of files.
2) sed 's/ sequentialInsert/orderedInsertion/' ~cs252/Assignments/commandsAsst/project/arrayops.h > ~/UnixCourse/commandsAsst/arrayops.h
Using sed command switch s is used to search the pattern “sequentialInsert” and replace it with ordered insertion from file arrayops.h and redirect to create a file as ~/UnixCourse/commandsAsst/arrayops.h.
3) find ~/UnixCourse -type f -name “*.txt” -exec head -n 10 {} ; -> using the find command it will check the /UnixCourse directories and sub-directories -type is to find files, *.txt will search for only files end with .txt format. The -exec option followed by head command will show first 10 lines of those .txt files.
4) ps -Af | grep -v "root" | wc -l-> here ps -Af will give the process list and grep is used along with -v option to ignore the search pattern and will give processes used by other users except root. And wc -l will give the count.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.