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
What are the notations for package name of RPM and DEB package types?
RPM - Package-version-release.architecture.rpm DEB - package _version-revision_architecture.deb
26
What are package priorities?
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
What are package sections?
these are pre-bundled category of packages e.g: web, admin ulities, Games, GNOME, GNU, Phython, Ruby, Video etc.
28
What are some of the checksums ?
1. md5sum (128 bit) 2. SHA1 (160 bit) 3. SHA256(256 bit)
29
In Ubuntu, what is the administrators group referred as?
sudo Only sudoers can install /upgrade/remove packages
30
Where is all sudoers listed?
/etc/sudoers
31
how a superuser can find out unsuccessful sudo attempts
through log file /var/log/auth.log
32
where is authentic sources list file from where packages will be downloaded will be stored?
/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
How to downloaded the updates and keep it in cache?
sudo apt-get update The updates applicable only to your installed packages are used .
34
How to install the updates downloaded to cache?
sudo apt-get upgrade
35
After updating the existing packages. How to remove the unused but downloaded package updates in cache?
sudo apt-get autoremove -removes outdated versions and unwanted files. apt-get clean clean local repository of retrieved package files apt-get purge purge package files from system
36
How to uninstall a package?
sudo apt-get remove
37
How to install a package?
sudo apt-get install sudo apt-get reinstall
38
where could we find details about the dpkg package manager?
/var/lib/dpkg Files: arch, available, status Folder: info
39
How to list all dpkg packages?
dpkg -l pattern
40
How to list installed files that came from packages?
dpkg -L package
41
How do find dpkg status of packages?
kpkg -s package
42
How to search installed packages for a file?
dpkg -S pattern
43
How to query dpkg database?
dpkg-query -W -f='${section} {binary:Package}\n' -w : show -f ; format lists the package section and naame of the executable/package.
44
How to filter an output?
grep
45
What is "Sleep" command do?
Delays/sleep for specific seconds
46
how to run processes in background?
coproc sleep 10 we will get prompt immediately on enter. we could run other commands and sleep command will run in background.
47
which command lists all the processes currently running ?
ps ps -e (all process running in computer.. and not just this shell) jobs ps --forest (tree view)
48
coproc is a shell keyword (found by using command 'type') but there is no man for coproc. Why?
because for shell commands we need to use help command. help coproc
49
how to get the process id of the current shell?
echo $$
50
how to kill a process?
kill -9 kill -9 & (backgound kill) If process is running in foreground then we could use ctrl +c to kill the process.
51
How to see all processes of OS?
top (Screen gets refreshed based on cpu activity) q or Ctrl+c to exit Ctrl +z for suspend to cmd line
52
How to suspend a process?
Ctrl + z
53
How to move a process from the background to fore-ground
command 'fg'
54
What does the shell variable $- contain?
says under what selected options the current bash is running. bash -c "echo $-" - displays different text as the options are modified.
55
How to see the list of all historical commands run on the computer?
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 !
56
What is expansion command?
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
How is ";" used to run multiple commands in left to right order?
ls ; date; wc -l /etc/profile ";" - aka command separator
58
how to find the status of the previously run command?
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
how to open a calculator in ubuntu?
bc Ctrl + d to come out of calc
60
How to declare a list of items and retrieve from list?
declare -A caparray=( [Switzerland]=Bern [Germany]=Berlin [Canada]=Ottawa [Tokyo]=Japan [Mongolia]=Ulaanbaater) echo ${!caparray[@]} echo ${caparray[Tokyo]:1:2}
61
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.
head -2 half1.txt>>master.txt tail -3 half2.txt>>master.txt
62