Week 3 Flashcards

1
Q

executing multiple commands?

A

1)command1;command2;command3;
each command will be executed one after other even if any one or more commands have error or failed to execute

2) command1 && command2

Command 2 will be executed only if command1 succeeds

3) command1 || command 2
command2 will not be executed if command1 succeeds

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

how to execute multiple commands in a subshell and then return their result to the original shell?

A

using parenthesis, we could do this.
e.g.: (ls, date, we filename.txt)

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

What is the name of the variable which gives the shell level in which the command is executed? Why do we need subshell?

A

$BASH_SUBSHELL , We need subshells so that we could confine the running environment of certain commands.

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

What are file descriptors?

A

There are 3 file descriptors.
Stdin (0) - Input stream normally keyboard
Stdout(1) - Output stream- usually monitor
stderr (2) - usually points to the monitor.

In linux, we assume that all these file descriptors are streaming characters which could be redirected to a file or a command.

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

What is the redirection operator?

A

command > file 1 (Stdout is redirected to a file). New file 1 will be created if it does not exist already.. if it already exists then it will be overwritten (Caution) , Note: write permission is required for the current directory else it wont work

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

Which command is used for displaying the hardware infor of the system?

A

hwinfo

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

what is the output for cat > file1

A

cat enables stdin and what ever we enter via keyboard will go into the file1. we could come to pwd by pressing Ctrl +D (End of File)

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

what happens when we execute just the cat command?

A

cat takes input from keyboard and displays it back to screen. We could come out by pressing Ctrl+D

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

How to append to a file?

A

using double redirection “»” . If file does not exist.. it will be created and if it exists, then the new content will be appended and NOT replaced, if write permissions are given.

e.g: date&raquo_space; file2; wc-l /etc/profile&raquo_space; file2; file /usr/bin/znew&raquo_space; file2;

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

How to redirect error stream to file? can we send output to a file and error to a different file?

A

ls $HOME / blah 2>error.txt

ls -$HOME / blah > output.txt 2>error.txt

ls -R /etc (Recursively traverses into the directory etc)

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

How to serve as a file as std input (ie., serve file as input stream when the program is expecting input from keyboard)

A

cat < error.txt (will serve error.txt as input to command cat)

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

How to redirect output and error to the same file?

A

command > file1 2>&1

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

What happens when we use pipes with commands?

A

command1 | command 2

Stdout of command1 will become stdin of command2

ls /usr/bin | wc-l
combines commands.

one command line with multiple commands and pipes are possible.

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

How to use redirection, pipes together?

A

command1 | command2 > file1

stdout of command1 fed into command 2 as stdin and stdout of command 2 is fed as stdin of file1

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

How is /dev/null special?

A

It is a sink for output to be discarded. Use! silent and clean scripts.

command > file1 2> /dev/null
this command output will be written to file 1 and any error will be written to null file and subsequently be discarded.

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

what does tee command do?

A

tee command reads from stdin and writes to stdout and files.

could be combined along with pipe

Tee command could be used to write multiple files.

e.g : ls $HOME | tee file1 file2

ls $HOME //blah 2> /dev/null | tee file1 file2 | wc-l

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

What are package management systems? why do we need one?

A
  1. Tools for installing, updating, removing, managing software
    1a. Install new/updated software across network.
  2. Package - File lookup, both ways.
  3. Database of packages on the system including versions
  4. Dependency checking
  5. Signature verification tools.
  6. Tools for building packages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are major package types?

A

RPM (RedHat - CentOS, Fedora, Oracle Linux, openSUSE), SUSE Enterprise Linux
* for Maintaining Linux servers.. this will be helpful

DEB (Debian - Knoppix, Ubuntu - Mint
* for manintaining regular ubuntu installations , this will be helpful.

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

How to find the current operating system running on our machine?

A

lsb_release -a

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

What are some of the software architectures for which linux is available?

A
  1. amd 61 | x86_64
  2. i386 |x86
  3. ARM
  4. ppc64el | Open POWER
  5. all |noarch|src
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are some of the package tools?

A
  1. RPM (YUM- Yellowdog Updater Modifier) - RedHat Package manager(RPM), Dandified YUM (dnf)
  2. DEB - Synaptic(graphical), aptitute(Command line) - Advanced Package Tool (apt) - dpkg, kpka-deb
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How to inquire package database?

A

search packages for a keyword
apt - cache search keyword

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

How to list all packages currently installed in our system?

A

apt -cache pkgnames
apt-cache pkgnames nm

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

How to display package recrods of a package?

A

apt -cache show -a package
apt-cache show nmap

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

What are the notations for package name of RPM and DEB package types?

A

RPM - Package-version-release.architecture.rpm

DEB - package _version-revision_architecture.deb

26
Q

What are package priorities?

A
  1. required - essential to proper functioning of the system.
  2. important - provides functionality that enables the system to run well
  3. standard - included in a standard system installation
  4. optional - can omit if you do not have enough storage
  5. extra - could conflict with packages with higher priority, has specialized requirements, install only if needed.
27
Q

What are package sections?

A

these are pre-bundled category of packages e.g: web, admin ulities, Games, GNOME, GNU, Phython, Ruby, Video etc.

28
Q

What are some of the checksums ?

A
  1. md5sum (128 bit)
  2. SHA1 (160 bit)
  3. SHA256(256 bit)
29
Q

In Ubuntu, what is the administrators group referred as?

A

sudo

Only sudoers can install /upgrade/remove packages

30
Q

Where is all sudoers listed?

A

/etc/sudoers

31
Q

how a superuser can find out unsuccessful sudo attempts

A

through log file /var/log/auth.log

32
Q

where is authentic sources list file from where packages will be downloaded will be stored?

A

/etc/apt
Files: sources.list
Folder: sources.list.d (Contains sources from other programs like google, Teamviewer etc..) - as and when updates are released, package manager will update.

33
Q

How to downloaded the updates and keep it in cache?

A

sudo apt-get update

The updates applicable only to your installed packages are used .

34
Q

How to install the updates downloaded to cache?

A

sudo apt-get upgrade

35
Q

After updating the existing packages. How to remove the unused but downloaded package updates in cache?

A

sudo apt-get autoremove

-removes outdated versions and unwanted files.

apt-get clean
clean local repository of retrieved package files

apt-get purge <package>
purge package files from system</package>

36
Q

How to uninstall a package?

A

sudo apt-get remove <pkgname></pkgname>

37
Q

How to install a package?

A

sudo apt-get install <package_name></package_name>

sudo apt-get reinstall <package-name></package-name>

38
Q

where could we find details about the dpkg package manager?

A

/var/lib/dpkg
Files: arch, available, status
Folder: info

39
Q

How to list all dpkg packages?

A

dpkg -l pattern

40
Q

How to list installed files that came from packages?

A

dpkg -L package

41
Q

How do find dpkg status of packages?

A

kpkg -s package

42
Q

How to search installed packages for a file?

A

dpkg -S pattern

43
Q

How to query dpkg database?

A

dpkg-query -W -f=’${section} {binary:Package}\n’

-w : show
-f ; format

lists the package section and naame of the executable/package.

44
Q

How to filter an output?

A

grep <filter></filter>

45
Q

What is “Sleep” command do?

A

Delays/sleep for specific seconds

46
Q

how to run processes in background?

A

coproc sleep 10

we will get prompt immediately on enter. we could run other commands and sleep command will run in background.

47
Q

which command lists all the processes currently running ?

A

ps

ps -e (all process running in computer.. and not just this shell)

jobs

ps –forest (tree view)

48
Q

coproc is a shell keyword (found by using command ‘type’) but there is no man for coproc. Why?

A

because for shell commands we need to use help command.

help coproc

49
Q

how to get the process id of the current shell?

A

echo $$

50
Q

how to kill a process?

A

kill -9 <process_id></process_id>

kill -9 <process_id> & (backgound kill)</process_id>

If process is running in foreground then we could use ctrl +c to kill the process.

51
Q

How to see all processes of OS?

A

top (Screen gets refreshed based on cpu activity)

q or Ctrl+c to exit

Ctrl +z for suspend to cmd line

52
Q

How to suspend a process?

A

Ctrl + z

53
Q

How to move a process from the background to fore-ground

A

command ‘fg’

54
Q

What does the shell variable $- contain?

A

says under what selected options the current bash is running.

bash -c “echo $-“ - displays different text as the options are modified.

55
Q

How to see the list of all historical commands run on the computer?

A

use command “history” . It will list shortcut numbers so that it could be used to repeat the operation/command. we could run the historical command by using !<shortcut/line no>

56
Q

What is expansion command?

A

echo {a..z} lists all characters from a to z

echo {A..D}{A..D} will give all combinations from AA till DD

echo * (expansion of all directories in pwd)

echo d* (expansion of all directories in pwd staring with d) - case sensitive

57
Q

How is “;” used to run multiple commands in left to right order?

A

ls ; date; wc -l /etc/profile

”;” - aka command separator

58
Q

how to find the status of the previously run command?

A

echo $?

Range : 1 -255
0 sucessful
1-255 - error
1 - permission denied
127 - command not found
137 - process killed using kill command

we could manually send a exit code from a shell inside a shell. if number is bigger than 256 then number %256 will be displayed.

59
Q

how to open a calculator in ubuntu?

A

bc

Ctrl + d to come out of calc

60
Q

How to declare a list of items and retrieve from list?

A

declare -A caparray=( [Switzerland]=Bern [Germany]=Berlin [Canada]=Ottawa [Tokyo]=Japan [Mongolia]=Ulaanbaater)

echo ${!caparray[@]}
echo ${caparray[Tokyo]:1:2}

61
Q

There are three files master.txt, half1.txt and half2.txt in the current working directory. Add first 2 lines of half1.txt to the file master.txt at the end(starting at a new line) then append the last 3 lines of the file half2.txt to the file master.txt at the end(starting at a new line). Append the lines in the sequence mentioned.

A

head -2 half1.txt»master.txt
tail -3 half2.txt»master.txt

62
Q
A