Linux Vi Help Create a file in Vi and write the steps you would take to complete
ID: 641815 • Letter: L
Question
Linux Vi Help
Create a file in Vi and write the steps you would take to complete the last five steps. NOTE: You do not have to create individual files, simply write what you would type out.
Step 16. Create a listing of all words that Linux knows of that contains the word "dog", and save it as dog_doodoo.
Step 17. Create a file from dog_doodoo that only shows the words that contain the word "dogs" sorted in reverse order and saved as detros_sgod, which is dogs_sorted backwards.
Step 18. Create a file called flat_cat that shows the count of all words that Linux knows of with the word cat in them.
Step 19. Create a script called my_details containing your user name, login name, shell being used, and home directory.
Step 20. Create a script that does the following called my_script
Displays everyone logged in
Pauses for 2 seconds
Displays a listing of the directory in long form
Pauses for 2 seconds
Displays today's date
Pauses for 1 second
Displays a calendar from Sept. 1752 only
Pauses for 2 seconds
Asks the user how they are doing today
Displays Goodbye
Explanation / Answer
Linux Vi Help
Creating a file in Vi and writing the steps taken to complete the last five steps.
vi DogCatFile
the above command will open a file called DogCatFile
The contents of the file:
The quick little dog chased over the cat. The dog ran behind the cat under the tree, on the table. The dog could not get the cat. The dog was tired. The dog sat down.
Step 16. Creating a listing of all words that Linux knows of that contains the word "dog", and saving it as dog_doodoo.
Press escape to enter the command mode
:s/dog > dog_doodoo
the above will search for all words having “dog” and save them to the file dog_doodoo
Step 17. Creating a file from dog_doodoo that only shows the words that contain the word "dogs" sorted in reverse order and saved as detros_sgod, which is dogs_sorted backwards.
:%sort! > detros_sgod
The above command :%sort! calls the sort function and ! sorts in reverse order. The redirection > saves the reslt in to the file detros_sgod.
tail –r dogs_sorted > detros_sgod
The above will also sort in reverse order
other commands like
sort –r dogs_sorted > detros_sgod
tac dogs_sorted > detros_sgod
will also do the same function.
awk, grep, sed and egrep all can be used for searching regular expressions and are related to sorting.
Step 18. Creating a file called flat_cat that shows the count of all words that Linux knows of with the word cat in them.
:%s/cat//gn > flat_cat
The above command searches and counts all the words with cat in them and puts the result in to the file called flat_cat.
Step 19. Creating a script called my_details containing your user name, login name, shell being used, and home directory.
who am i
will return your user name
both id –un and logname can be used to retrieve the login name
like
logname
id -un
ps –ef will list out the shell being used, but it needs to be piped to grep $$ as follows
ps –ef | grep $$
the sudo command will get the home directory of the logged in user.
ps –ef | grep will give you the processor id
pwd will give you the present working directory
the shell script:
#!/bin/bash
usrNm=$(whoami)
logname
ps –ef | grep $$
sudo env | grep USER
Step 20. Creating a script that does the following called my_script
Displays everyone logged in
(any one of the following will do:]
w
who –a
users
Pauses for 2 seconds
Displays a listing of the directory in long form
either ls –l
or this would do ls –la
Pauses for 2 seconds
Displays today's date
Pauses for 1 second
Displays a calendar from Sept. 1752 only
Pauses for 2 seconds
Asks the user how they are doing today
Displays Goodbye
vi my_script
(press enter and press i to get into insert mode)
w
who –a
users
sleep 2s
ls –l
ls –la
sleep 2s
date
sleep 1s
cal 9 1752
cal –y 1752
sleep 2s
echo “Dear User, How are you today?”
echo “Good Bye”
(press escape and type :wq to save the script and quit)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.