Week 3 Flashcards
executing multiple commands?
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 to execute multiple commands in a subshell and then return their result to the original shell?
using parenthesis, we could do this.
e.g.: (ls, date, we filename.txt)
What is the name of the variable which gives the shell level in which the command is executed? Why do we need subshell?
$BASH_SUBSHELL , We need subshells so that we could confine the running environment of certain commands.
What are file descriptors?
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.
What is the redirection operator?
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
Which command is used for displaying the hardware infor of the system?
hwinfo
what is the output for cat > file1
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)
what happens when we execute just the cat command?
cat takes input from keyboard and displays it back to screen. We could come out by pressing Ctrl+D
How to append to a file?
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»_space; file2; wc-l /etc/profile»_space; file2; file /usr/bin/znew»_space; file2;
How to redirect error stream to file? can we send output to a file and error to a different file?
ls $HOME / blah 2>error.txt
ls -$HOME / blah > output.txt 2>error.txt
ls -R /etc (Recursively traverses into the directory etc)
How to serve as a file as std input (ie., serve file as input stream when the program is expecting input from keyboard)
cat < error.txt (will serve error.txt as input to command cat)
How to redirect output and error to the same file?
command > file1 2>&1
What happens when we use pipes with commands?
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 to use redirection, pipes together?
command1 | command2 > file1
stdout of command1 fed into command 2 as stdin and stdout of command 2 is fed as stdin of file1
How is /dev/null special?
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.
what does tee command do?
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
What are package management systems? why do we need one?
- Tools for installing, updating, removing, managing software
1a. Install new/updated software across network. - Package - File lookup, both ways.
- Database of packages on the system including versions
- Dependency checking
- Signature verification tools.
- Tools for building packages.
What are major package types?
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 to find the current operating system running on our machine?
lsb_release -a
What are some of the software architectures for which linux is available?
- amd 61 | x86_64
- i386 |x86
- ARM
- ppc64el | Open POWER
- all |noarch|src
What are some of the package tools?
- RPM (YUM- Yellowdog Updater Modifier) - RedHat Package manager(RPM), Dandified YUM (dnf)
- DEB - Synaptic(graphical), aptitute(Command line) - Advanced Package Tool (apt) - dpkg, kpka-deb
How to inquire package database?
search packages for a keyword
apt - cache search keyword
How to list all packages currently installed in our system?
apt -cache pkgnames
apt-cache pkgnames nm
How to display package recrods of a package?
apt -cache show -a package
apt-cache show nmap