HW1, practicing bash and vim¶
For this problem, you will practice common and helpful bash commands, such as:
ls
pwd
cd
cp
rm
mv
mkdir
cat
tail
head
wget
grep
diff
wc -l
and more advanced (and extremely helpful) utilities such as sed
,
awk
, and vim
.
1. For each part below, type the bash commands to complete the following tasks:¶
- Create a directory named
hw01prob01
- In that directory create a file named
hopper_quotes.txt
containing the following text (okay to use vim in this part):
To me programming is more than an important practical art. It is also a gigantic undertaking in the foundations of knowledge.
No computer is ever going to ask a new, reasonable question. It takes trained people to do that.
We’re flooding people with information. We need to feed it through a processor. A human must turn information into intelligence or knowledge. We’ve tended to forget that no computer will ever ask a new question.
- From the command line, display (on your terminal) the last line of the file.
- In one line of bash commands: make a copy of that file, naming it
hopper_edited.txt
, while changing every instance ofis
toremains
(spaces added so that only the whole word is replaced, rather than parts of words, like accidentally changing ‘this’ to ‘thremains’). Display the full contents of this edited file.
- Make a new file
combined.txt
with all the contents of ‘hopper_quotes.txt’ followed byhopper_edited.txt
. Display the total number of lines of this new file.
- Display the contents of the directory
hw01prob01
including the permission on each file (additional information may be printed if desired).
- Copy the whole directory
hw01prob01
to a new one namedhw01prob01_complete
. Compare these directories. Then deletehw01prob01
and all its contents.
- Using a shortcut, navigate to your home directory. List all the hidden files. In addition to reporting the commands for these two actions, report (some of) the hidden files that you have in your home directory which change preferences for particular programs.
2. Type the vim commands needed to perform the following tasks.¶
First, make a file with the following text (you do not need to report how you created this file).
Manifesto for Agile Software Development
We are uncovering better ways of developing software by doing it and helping others do it. Through this work we have come to value:
- Individuals and interactions over processes and tools
- Working software over comprehensive documentation
- Customer collaboration over contract negotiation
- Responding to change over following a plan
That is, while there is value in the items on the right, we value the items on the left more.
Signed: Kent Beck, Mike Beedle, Arie van Bennekum, Alistair Cockburn, Ward Cunningham, Martin Fowler, James Grenning, Jim Highsmith, Andrew Hunt, Ron Jeffries, Jon Kern, Brian Marick, Robert C. Martin, Steve Mellor, Ken Schwaber, Jeff Sutherland, Dave Thomas
- Report the name you used for the file. The name should follow guidelines discussed in class (which still leaves many valid options).
- In your bash terminal, type the command to print the second word and forth word (one after the other) of every line. Verify that the first line of output is “for Software”.
- In your bash terminal, type the command to print every line that contains the word ‘we’.
All remaining parts of this problem will be completed in vim. Report the vim commands to:
- Find the first instance of the word ‘item’ or ‘items’. Then skip to the next occurence.
- Return to the first line using a shortcut. Then use a shortcut to move the cursor to the end of the line.
- Move to line 5. Cut/delete it.
- Move to the end of the file. Paste the deleted line so it will appear five times.
- Replace all instances of the word ‘we’ with the word ‘I’. Also replace ‘We are’ with ‘I am’. Save and close the file.