BasicShell

Question 3: Head and Tail

What is the first line printed if you tail the last 10 lines of the file "lines"... i.e. what is the line 10 lines from the end of "lines"?

tail -n 10 lines

What is the word which appears on line 5000 of the file "words". Use a pipe with head and tail to make life easy... The test is CASE SENSITIVE.

head -n 5000 words

If you do an "ls" in /etc, what is the 100th filename?

ls /etc/ | head -100
gss

If you do an "ls" in /etc, what is the 100th filename from the END?

ls /etc/ | tail -100
pnm2ppa.conf

Using head and tail, store the filenames printed on lines 120 to 150 inclusive when doing an ls in "/etc". Save the names in a file called /home/demo/120. Hint: there are 31 lines from 120 to 150 inclusive...

# Hint: there are 31 lines from 120 to 150 inclusive...
ls -d * | head -150 | tail -31 > /home/demo/120
cat /home/demo/120 | wc -l

In the concatination of file1, file2, file3, and file4 in test1, how many characters are there on line 167? Hint: use the wc command to count the characters (thus include the newline character).

cat * | head -167
echo 'mail:x:12:postfix' | wc -c
18

Question 4: Permissions and chmod

What is the current symbolic permissions on "info" in /home/demo? Use the format "-rwxrwxrwx". Do not include any extended permissions if any are present

ls -al /home/demo/info 
-rw-r--r--. 1 root root 107 Aug  1 18:53 /home/demo/info

-rw-r--r--

What is this permission if it was encoded in numeric (octal) notation? Use the form 0666.

0772

Change the permissions on info so that user demo can read, write, and execute, group tutorial can read and execute, and other can write and execute.

[root@host-1-193 demo]# chmod 753 info 
[root@host-1-193 demo]# getfacl info
# file: info
# owner: root
# group: root
user::rwx
group::r-x
other::-wx

Assume you now have to set the file info using numeric notation. Preserving all permissions except group, what would be the numeric notation for giving group just execute permissions? Again use the format 0777.

chmod 0713 info

Now in Linuxzoo, take away write permissions for other on the info file.

chmod 751 info

Change the permissions again of info so that anyone in group tutorial can read the file but not write or execute it. Leave the other permissions unchanged.

chmod 741 info

Given a file owned by "gordon" in group "users", and a numeric permission code of 0654, what would user "demo" of group "demo" be allowed to do?

# if you really suck go http://permissions-calculator.org/decode/0654/
# manual -> -rw-r-xr--. 1 gordon users
Read Access

Given a file owned by "gordon" in group "demo", and a numeric permission code of 0654, what would user "demo" of group "demo" be allowed to do?

# rw-r-xr--. 1 gordon users
Read Execute

Given a file owned by "demo" in group "users", and a symbolic permission code of "-rw-rwx--x, what would user "demo" of group "demo" be allowed to do?

# rw-r-xr--. 1 demo users
Read Write

Adjust the info file once more so that a user "gordon" in group "tutorial" would only be allowed to write and execute the file info. Again do not change any other file permissions other than that required to answer this question. It might be an idea to note the current permissions just in case you have to try again!

# original -> -rwxr----x. 1 demo tutorial     107 Aug  1 18:53 info
chmod 731 info

Adjust the permissions on info once again, so that group would have the octal permission 4, and the owner would have the symbolic permission of "rw", and others would have permissions to read only.

# raw -> owner=6 group=4 other=4
chmod 644 info

Last updated

Was this helpful?