unix questions and answers, Quizzes of Computer Science

unix basic quiz question and answer

Typology: Quizzes

2025/2026

Uploaded on 06/30/2026

teacup_tornado
teacup_tornado 🇺🇸

9 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
UNIX answers
Viewing and Editing files (cat/more/less/head/tail/vim/vi)
cat
o concatenate files and print on the standard output
more
o display files on a page-by-page basis (one screenful at a time)
less
o opposite of more
o allows backward and forward movement
o does not have to read the entire input file before starting, so with large input files it
starts up faster than text editors like vi
head
o print the first 10(by default, can be changed with –n) lines of each FILE to standard
output
o with more than one FILE, precede each with a header givin the file name
tail
o print the last 10 lines of each FILE to standard output
vim
o is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of
plain text.
o A lot of improvements compared to vi:
Multi-level undo, syntax highlighting
vi
o screen oriented text editor
Which is best for viewing a large file?
o Less
Main advantage is that less command will not load whole file into
memory,so it will be much faster than vi
How do you return the 20th -30th lines in a text file
o Two ways
sed –n –e ’20,30p’ input txt > output.txxt
tail –n +10 input.txt | head –n 11 >output.txt
If you only have 3 lines in your file, which command would you use to view the contents of
the file?
Cat
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download unix questions and answers and more Quizzes Computer Science in PDF only on Docsity!

UNIX answers

Viewing and Editing files (cat/more/less/head/tail/vim/vi)

cat o concatenate files and print on the standard output ● more o display files on a page-by-page basis (one screenful at a time) ● less o opposite of more o allows backward and forward movement o does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi ● head o print the first 10(by default, can be changed with –n) lines of each FILE to standard output o with more than one FILE, precede each with a header givin the file name ● tail o print the last 10 lines of each FILE to standard output ● vim o is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. o A lot of improvements compared to vi: ▪ Multi-level undo, syntax highlighting ● vi o screen oriented text editor

Which is best for viewing a large file? o Less ▪ Main advantage is that less command will not load whole file into memory,so it will be much faster than vi

How do you return the 20th^ -30th^ lines in a text file o Two ways ▪ sed –n –e ’20,30p’ input txt > output.txxt ▪ tail –n +10 input.txt | head –n 11 >output.txt

If you only have 3 lines in your file, which command would you use to view the contents of the file? ▪ Cat

Copying, Moving and Creating directories and files (cp/ scp/ mv

/mkdir/touch)

How can you move files from one directory to another? ▪ mv filename dir-name

How do you rename the file? ▪ mv oldfilename newfilename

How would I approach scenarios such as using “makefile”in different ways? ▪ mkdir, touch, scp (for file transfer)

Disk Space and Memory Usage ( free/ df/ du/ top)

▪ free o Displays amount of free and used memory in the system ▪ df o Report file system disk space usage ▪ du o Summarize disk usage of each FILE, recursively for directories ▪ top o display Linux tasks/ provides a dynamic real-time view of a running system.

What are the columns of each command?

▪ OO..fuck off, if you need check manual, I will not memorize this. Bastards!

How do you return the disk usage for a directory? ▪ du

How can you find the memory usage? ▪ Free –m ▪ Cat /proc/meminfo - more detailed ▪ Top

How do you check disk space?

▪ df/ df -h

How do you check CPU usage? ▪ top

How to view free disk space? ▪ df -h

If a process/system is unresponsive what would you check?

▪ Not sure about this one

How do you see a list of processes?

How do you check what processes are currently running?

How do you stop a process that is running ● Use ps to find PID and then kill command (kill [signal] PID

Different ways to find PID? ● Pidof

Kill

How do you kill a specific process? Kill pid1 pid2 pid Kill 3486 Kill -9 3486

How to find PID to run kill on?

▪ Using lsof/pidof/ps and then combination with kill

The different signals e.g. kill -9 (force kill) and kill -2 (interrupt) etc

▪ -9 nearly guarantee to kill the process

What will kill do if you don’t pass a signal and the process you’re trying to kill is busy?

▪ I assume; wait until I am done without the flag

Ctrl Z / fg/ bg/ jobs/ nohup/ &

Ctrl Z - sends SIGTSTP to a foreground application, effectively putting it in the background, suspended. This is useful if you need to break out of something like an editor to go and grab some data you needed.

Fg– command continues a stopped job by running it in the foreground fg [%job_id]

Bg– control command that resumes suspended jobs while keeping them running in the background. This restart a stopped background process. bg[job]

Jobs– list background processes

Nohup– when using the command shell, prefixing a command with nohup prevents the command from being aborted if you log out or exit the shell

&- run the command in the background

String manipulation (sed/awk)

Sed – stream editor for filtering and transforming text

Awk – finds and replaces text, database sort/validate/index (awk ‘{print $1}’ input_file

When do you use it and what's the syntax

What is sed / What do you know about sed

▪ Cat example.txt | sed ‘d’ -

▪ to find all the files under /tmp directory with name xyz.txt.

▪ find /tmp -name xyz.txt

How would you delete all files older than 5 days ▪ find /path/to/files* -mtime +5 -exec rm {} ;

The pipe command ( | ) and xargs

What does the | command do

▪ Allow you to merge existing Unix commands in a new one

Can you provide an example of how you would use it

▪ tail –n +10 input.txt | head –n 11 >output.txt

▪ ls -al | more ● Here's a simple pipeline command I use all the time, creating a long list of files and piping the output into the Linux more command

What does the xargs command do

▪ Build and execute command lines from standard input

▪ $ xargs Hi, Welcome to TGS.Hi, Welcome to TGS.

shell scripts

make typescript of terminal session. Script makes a typescript of everything printed on your terminal.

Different types of shell script

Structure (What's the first line) o #!/bin/sh

How to check test if it was a regular file in a bash script

How to reload bash profile

In a shell script, how do you check if a directory exists

Environment Variables ( export / echo )

How do you set an environment variable

▪ $FOO=”bar”

▪ Export FOO (not be visible in childs processes unless you export it)

How do you check an environment variable

▪ Echo $FOO (don’t forget the $)

wc

How can you count the number of rows in a file ▪ wc -l

chmod

ability to change permissions on the file

Describe and it's syntax (to change permissions)

▪ chmod 771 my_app

▪ chmod o+wx testfile

How do you change permission on a file and its syntax

If I try to save a table to disk and do not have permission how do I go about adding permissions to save/load

Symlink

Make a new name for a file (symbolic link)

How to create a symlink

What is a symbolic link

crontab

How does it work

▪ Schedule a command to run at a later time

How do you set up a command to be run periodically

▪ 0 5 * * * /home/myname/scripts/do-every-day.sh – run at 5 PM every day

What do the following options mean: -e, -l, -r

▪ -r – remove the crontab

▪ -e –edit