Permissions, Pipes, VI Editor
Permissions
What is the octal value for the permissions on /home/demo/bigfile?
ls -al /home/demo/bigfile
644
What is the "other" permissions on /home/demo/bigfile?
Only Read
Take away from the scripts directory read and execute (search) permission for yourself ONLY.
ls -al scripts/
total 8
drwxr-xr-x. 2 demo tutorial 21 Aug 2 11:55 .
chmod 255 scripts/
What did removing read and execute do to you ability to look into scripts?
Could not ls the directory
Add in read access for yourself on the scripts directory.
chmod 655 scripts
What did restoring read access do to you ability to look into scripts?
Could ls, but not access contents
Restore the directory scripts to read,write,execute for the owner, and read and execute for both others and group.
chmod 755 scripts/
What umask setting would be required to give, when creating a directory, read/write/execute for yourself, read and execute for group, but only execute for others?
# if you really confurse, go https://wintelguy.com/umask-calc.pl
026
Pipes
Using cat create a pipe that will concatenate the two files club_members and names, sort them and send the output to the file s1.
cat club_members names | sort > s1
Using cat create a pipe that will concatenate the two files club_members and names, sort them in reverse order and send the output to the file s2.
cat club_members names | sort -r > s2
Sort the file club_members numerically by meetings attended (this is the last field). Send the output to file s3
# k count field, n count numercial
cat club_members | sort -n -k 5
Sort the /etc/passwd numerically by user id numbers (third field) in ascending order. You may wish to use the -t option here. Send the output to file s4
# sort -t: like cut -d':', -k 3 mean third field (UID)
cat /etc/passwd | sort -n -t: -k 3 > s4
Use grep on /usr/share/dict/words to find the first word that contains the three letter sequence wta
# find length 3 - grep -E '^s.{2}$' /usr/share/dict/words | grep wta
grep 'wta' /usr/share/dict/words
cowtail
Use grep piped through wc on file /usr/share/dict/words to find the number of words that contain the letter x.
grep -c 'x' /usr/share/dict/words
12249
Use grep to find all lines in /etc/passwd that do not have nologin one the line. Make grep include the line numbers of the matching lines and send the output to file s5
# https://linuxize.com/post/grep-exclude/
grep -nv nologin /etc/passwd > s5
Use ls -l and grep to find all the files in the directory /etc that were last modified in March (hint: try looking for the case sensitive string "Mar"). Send this list to s6.
ls -l /etc | grep 'Mar' > s6
Use ls -l and grep and sort to find all the files in /etc that were last modified in Jun. Sort this list in descending order of size and then alphabetically by name (so 2 files with the same size will appear in alphabetic order). Send the output to s7. Sorting using other techniques will probably not get the same answer...
# I think this is the corret answer, but it's not:(
# ls -l /etc | sort -k5nr | grep 'Jun' > s7
# ls -l /etc | grep 'Jun' | sort -k5nr > s7
ls -l /etc | sort -k 5,5 -nr | grep 'Jun' > s7
Find all the files and directories in /var (including subdirectories) that are owned by user root. Send the list of full path names to s8. Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
find /var -user root 2>/dev/null
Find all the files in /etc (including subdirectories) end .conf Send the list of full path names to s9. Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
find /etc -name *.conf 2>/dev/null > s9
Find all the files and directories in the demo directory that are newer than s1. Send the output of the command to /var/tmp/t1 (don't send it to the demo directory). The names of the files should appear as full names. For example, the file "s5" would appear as "/home/demo/s5". The "/home/demo", if it appears in the output, should not have a trailing "/". The secret to avoiding the trailing slash is to use "/home/demo" not "/home/demo/" in the find command.
find /home/demo -newer s1 > /var/tmp/t1
Find all the files in the directory directory /etc/ and its subdirectories that are larger than 1 megabyte (which you can assume is 2048 blocks of 512 bytes). Send the output to s10. Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
find /etc -size +1M 2>/dev/null > s10
Create a directory called smallc in /home/demo. Copy into it all the file that begin with s from /usr/include that are smaller or equal to 12K. You may find these instructions on the use of find from Developer's Daily useful. Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
find /usr/include -type f -name 's*' -size -25 -exec cp {} /home/demo/smallc \;
The VI Editor
In the demo account home page, use vi to edit a file called ex1. Insert into this file the following lines.
This is an exercise! Up, down, left, right, build your terminal's muscles bit by bit
vi ex1
# to insert string -> press i
# to write and quite -> Esc + :wq
Delete the word "an" from the first line, plus one of the spaces. The line left should read "This is exercise!".
vi ex1
press i and delete
Add " and byte by byte" to the end of the line "muscles bit by bit".
press i and add string
Create a new file called "ex2". In this file type a number on each line from 1 to 50. Scroll up and down this file. Write the file out to disk.
seq 1 50 > ex2
Go to the end of the file and Append the following line of text:
123456789 123456789
echo '123456789 123456789' >> ex2
If you are in command mode, what character are you on if you move onto the line of ex2 with "123456789 123456789" and then type
^7l Note this is HAT (e.g. shift 6) then 7 then the CHARACTER l (not a one).
go to end of the line 123456789 123456789
type ^7l
your cursor point to number 9
If you are in command mode, what character are you on if you move onto the line of ex2 with "123456789 123456789" and then type
$7h
2
Make sure you are in command mode, and move to the first line of ex2. Search forward for the character 8, then search on again, and then once again. What number is written on this line?
28
Create a file using vi called ex3. Insert into this file the following lines.
Append text Insert text a computer's job is boring. Once edited, you must do a write (:w then return) to write the file so that the checks can find your edits.
vi ex3
Append text
Insert text
a computer's
job is boring.
:wq
Add the following line of text ABOVE the first line.
First text
vi ex3
First text
Append text
Insert text
a computer's
job is boring.
:wq
Add the following line of text AFTER the last line.
Last text
vi ex3
First text
Append text
Insert text
a computer's
job is boring.
Last text
:wq
Move the line "Last text" to line 2 (i.e. between "First text" and "Append text".
vi ex3
First text
Last text
Append text
Insert text
a computer's
job is boring.
:wq
Change the last line to read "job was boring" rather than "job is boring".
vi ex3
First text
Last text
Append text
Insert text
a computer's
job was boring.
:wq
Last updated
Was this helpful?