KSH 1 Flashcards

(105 cards)

1
Q

What is a Shell?

A

Interface between the user and the operating system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name a type of Shell.

A
  • Bourne (sh)
  • Korn (ksh)
  • C Shell (csh)
  • Bourne Again Shell (bash)
  • tcsh
  • zsh
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the Bourne Shell (sh)?

A

The standard shell in most UNIX systems and normally the default shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Korn Shell (ksh)?

A

A superset of the Bourne shell, supporting most sh scripts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What characterizes the C Shell (csh)?

A

A shell that utilizes C language-styled syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Bourne Again Shell (bash)?

A

A standard shell in Linux based on the Bourne shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What command switches from ksh to bash?

A

$bash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What command do you use to exit from bash?

A

bash$ exit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens when commands run by default?

A

The shell waits for the command to terminate before returning to the prompt.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you run a command in the background?

A

Use the ampersand symbol (&) at the end of the command line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the command ‘% emacs test.txt &’ do?

A

It starts the emacs editor without waiting for it to exit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens when a process runs in the background?

A

It cannot be terminated using CTRL-C.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What command is used to send signals to processes?

A

kill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which signal is the strongest request to kill a process?

A

-9 signal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What command lists currently running processes?

A

ps (process status)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the tee command do?

A

Sends command output to both a file and the standard output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the syntax to use tee with ls?

A

% ls | tee filesindir

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What will be saved in the file called filesindir?

A

tut1 tut2 tut3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the command % cat filesindir do?

A

Displays the contents of filesindir.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the outcome of ls | tee filesindir?

A

Lists current directory files and saves to filesindir.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does the echo command do?

A

Displays the text passed to it, followed by newline.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How would you use echo to display ‘hello there’?

A

% echo ‘hello there’ hello there

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is another way to use echo?

A

% echo “hello there” hello there

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the equivalent command to echo?

A

% printf “%s\n” “string”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How would you use printf to display 'hello there'?
% printf "%s\n" "hello there"
26
What are the built-in shell commands?
Functions interpreted as commands Part of the shell itself
27
Name a few examples of command shells.
Bourne Shell Korn Shell Bourne Again Shell
28
What does the alias command do?
Creates a shortcut for a command (e.g., alias ls1="ls –l")
29
How do you print a message in shell?
Use echo command (e.g., echo Hi, "\n" this is a test)
30
What does the history command do?
Displays previous commands (e.g., history [no. or letter or string])
31
How to kill a job in shell?
Use kill –9 jobID
32
What does the set command do?
Displays set values To assign value: var=value To echo value: echo $var
33
How do you remove an alias with unalias?
Use unalias label, e.g., unalias ls1
34
What does unset command do?
Removes a variable (e.g., unset var_label)
35
What are metacharacters?
Special characters used to select lists of existing files.
36
What happens when metacharacters appear in an argument?
The shell expands the argument into a list of filenames.
37
What does the shell do with the list of filenames?
It passes the list to the program called by the command line.
38
What does the '*' meta character do in KSH?
Matches any characters.
39
What does the '?' meta character do in KSH?
Matches any single character.
40
What is the purpose of '[' in KSH?
Begins a character group.
41
What is the function of ']' in KSH?
Ends a character group.
42
What does '-' denote in KSH?
Defines a character range.
43
What is the use of '!' in KSH?
Negates a character group.
44
What does '|' signify in KSH?
Logical 'or' between patterns.
45
What does '?(pattern)' match in KSH?
Matches zero or one instance of pattern.
46
What does '*(pattern)' match in KSH?
Matches zero or more instances of pattern.
47
What does '+(pattern)' signify in KSH?
Matches one or more instances of pattern.
48
What does '@(pattern)' match in KSH?
Matches exactly one instance of pattern.
49
What does '!(pattern)' do in KSH?
Matches strings that don't contain pattern.
50
What does the ? special character do in file selection?
Matches any single character.
51
What files would the command % ls tut?.txt match?
tut1.txt tut2.txt tut3.txt
52
What will the ? special character not match?
Will not match leading hidden files (e.g., files starting with a period).
53
What does the asterisk special character match?
Zero or more characters (excluding leading period in hidden files).
54
What command lists files when using the asterisk?
% ls
55
How to list files starting with 'file'?
% ls file*
56
What command lists files matching '*le1'?
% ls f*le1
57
How do you use square brackets in the shell?
Square brackets [] match filenames containing the characters within them, e.g., % ls [aei]* lists files starting with a, e, or i.
58
What does % ls [aei]* yield?
abc.txt edd.txt
59
Consider a directory with these files: tut1.txt, tut2.txt, tut3.txt, abc.txt, edd.txt. Which command lists relevant files?
Use % ls [aei]* to match files starting with 'a', 'e', or 'i'.
60
How to display files part1.txt, part2.txt, and part3.txt?
% cat part[1-3].txt
61
How to display part1.txt to part5.txt?
% cat part[1-35].txt
62
How to list files with extensions ending in a single character?
% ls ·[a-k]
63
How to list files starting with 'test' followed by numbers 0-2 and 1-3?
Use the command: % ls test[0-2][1-3]
64
Which files are selected by the command % ls test[0-2][1-3]?
test01 test02 test03 test11 test12 test13 test21 test22 test23
65
Which files are not selected by the command?
test24 test_1
66
What does the command 'ls prog+([0-9]).c' do?
Lists files starting with 'prog', followed by one or more digits, and ending in '.c'.
67
What does 'ls prog*([0-9])@(.f|.c)' achieve?
Lists files that start with 'prog', followed by zero or more digits, ending with '.f' or '.c'.
68
What does the \ character allow in commands?
Splitting commands across multiple lines
69
What is the purpose of using a line continuation character?
To extend a command over multiple lines
70
What symbol is used to separate commands in a command line?
The semicolon ';'
71
What does the command '% ls ; cat file.txt ; ls /lib' do?
Executes 'ls' to list files Displays contents of 'file.txt' Executes 'ls /lib' to list files in '/lib'
72
What is the sequence of processes in the command 'ls ; cat file.txt ; ls /lib'?
They are executed sequentially: 1. ls 2. cat file.txt 3. ls /lib
73
What is the command to list files in a directory in Linux?
ls
74
What command reads the content of a file?
cat file.txt
75
What is the command to list directories in '/lib'?
ls /lib
76
What happens when you execute multiple commands with %?
Output may be mixed and interleaved.
77
What do parentheses do in shell commands?
Group commands together.
78
What happens when a shell groups commands?
It creates a subshell for each group.
79
What does the shell do when executing commands?
It forks processes to execute them.
80
How to execute commands a and b in the background?
Use '% (a ; b) &'.
81
What command executes c in the foreground?
It follows the grouped command % (a ; b) &.
82
How to create a script to show logged users and date?
Type date Type echo Users currently logged in Type who
83
What command makes the script executable?
chmod +x filename
84
How to execute a shell script?
Type ./filename
85
What does the line #!/bin/ksh specify?
Shell for command execution
86
What happens when a script finishes running?
Returns to the standard shell
87
What is the role of the # character in a script?
Indicates a comment line
88
How do you mark a file as executable in UNIX?
Use the command chmod +x filename
89
What is the purpose of #!/bin/sh?
Specifies the shell for the script
90
Can comments be included in UNIX scripts?
Yes, using the # character
91
What does #!/bin/bash indicate?
The script should use Bash shell
92
What command is used to exit the shell?
exit
93
Which shells support the if command?
Bourne Shell Korn Shell Bourne Again Shell
94
What command is utilized for arithmetic operations?
let
95
Which command is used to read input?
read
96
What command is used to perform conditional testing?
test
97
What looping command is available in all three shells?
while
98
Which command handles repetitive execution until a condition is met?
until
99
What does the script display first?
The current date and time
100
How does the script count the number of users logged on?
Using who | wc -l to count lines emitted by who
101
What command displays the current working directory?
pwd to show the full path
102
What is the command line output shown?
11 tiger% ./path.ksh Wednesday February 1 14:54:35 GMT 2006 32 /home/camel/u2/staff00/charalg 12 tiger%
103
What is the date and time in the output?
February 1, 2006, 14:54:35 GMT
104
What is the execution command given?
./path.ksh
105
What is the user prompt notation shown?
12 tiger%