Topic 5 - The command-line interface Flashcards
what is the outcome of typing
Grep ‘sat’ -I ‘datefile’
into a linux terminal
in a linux terminal:
this will search for the text pattern ‘sat’ while ignoring letter cases in the file named ‘datefile’
this is used to redirect the STDOUT (standard out stream) of a command to a file
what is the > symbol used for
Standing for ‘global regular expression print’. is a tool for finding a given text pattern in a given text.
Text can be pipelined into this command or can be held inside a file
describe the linux
grep
command
give a description of the linux
cat
command
this command will concatenate files and print on the standard output
what is the outcome of typing
Touch existing-filename
into a linux terminal
in a linux terminal:
this will update the access and modification timestamps of the given filename
what is the name and purpose of the ~ symbol in linux
in linux this is called a
tilde and points / references your home directory
in a linux terminal:
this will redirect the output from the date command into the given filename, creating a new file if it does not exist
what is the outcome of typing
Date > filename
into a linux terminal
in a linux terminal:
this will update the access and modification timestamps of the given filename
what is the outcome of typing
Touch existing-filename
into a linux terminal
The OS is also able to optimize this efficiently since the output of one command can be written to main memory and as soon as data starts to arrive the other command can start to consume it without the need for the first command to finish execution
how can the operating system
optimize pipelining
the shell used on this was named sh (bourne shell) as was written by stephen bourne
what was the shell used on UNIX systems called and who created it
what is the outcome of typing
Rm filename -f
into a linux terminal
in a linux terminal:
this will suppresses the prompt confirming removal of write protected files and overrides the write protection. in turn deleting the file
what is the outcome of typing
Cp my-file my_directory
into a linux terminal
in a linux terminal:
this will copy the file my-file into the directory my-directory
this is a file that contains the paths of available shells on the linux system
describe the linux
/etc/shells
file
when this occurs the operating system will set:
- the input stream as the keyboard
- the output stream as the terminal window
when a terminal is opened what are the default input and output streams configured by the operating system
give a description of the linux
mv
command and how it works
in a linux terminal:
This is used to move files and directories. If the source file given is moved to the same location this command then renames the file using the destination
• it prompts a user to type a command line
• it deals with editing within the line, accepting the line when Enter is pressed
• some special characters are picked out and handled specially, such as:
◦ quotation marks preserve spaces but are themselves stripped out
◦ > and ◦ wildcards such as * cause filenames to be expanded
• the completed command line is broken into pieces (tokens) by spaces
• the first token on the line is taken as the command
• if the command is built-in, then:
◦ the corresponding action is taken
• otherwise the file system is searched for a matching filename
• if a matching file is found, then:
◦ the type of file is determined
◦ if the file is a script, then:
– the script commands are interpreted recursively line by line
– until the end of the file
◦ if the file is an executable program:
– a system call obtains a chunk of memory from the memory management module
– a system call loads the contents of the program from the file system into that memory
– the remainder of the command-line arguments are copied to it
– a final system call is made to execute the program, relinquishing control of the processor through a context switch
– until the program ends and a context switch returns control to the shell
• else if no matching file is found, report an error
This process is then repeated.
how the linux cli operates
(come back to this at the end of the module)
this will redirect the STDOUT (standard output) of the command to a given file.
- If the file contains content it will be overwritten
- if the file does not exist it will be created
in a windows and linux terminal what is the (>) used for and 2 considerations to take into account before its use
in a linux terminal:
this will make a new directory with the name as the value given
what is the outcme of typing
Mkdir value
into a linux terminal
this can be used to give STDIN (standard input) to a command from a file for example
in a windows or linux terminal what does the (
in a linux terminal:
this will tell you the file type of the filename you have given
what is the outcome of typing
File filename
into a linux terminal
what is the outcome of typing
Ls -l
into a linux terminal
in a linux terminal:
this will output detailed information about the contents of the directory
note
- if the first character of a line is a (-) it represents a file
- if the first character of a line is a (d) it represents a directory
Because linux was developed from UNIX many of the linux shells maintain traditions from UNIX such as syntax this in turn has kept compatibility alive between linux systems
also many of the linux shells are derivitives of the unix sh shell although they will contain many new features
why are commands from UNIX seen in linux
what is the outcome of typing
Touch non-existing filename -c
into a linux terminal
in a linux terminal:
this will find no file and will also not create a new file. execution ends silently
this linux shell
- is a widely used shell in linux distributions
- maintains compatibility with the original sh shell
- maintains compatibility with the original sh shell
give three points about the linux:
Bash (bourne again shell)
what is the linux
find
command used for
in linux terminal:
This is used to search for files in a directory
this is a file that contains information about the systems processor
describe the linux
/proc/cpuinfo
file
this is an accronym for:
bourne again shell
what does
bash
stand for
give 3 reasons as to why many OSs share the same commands which may also have the same or similar functionality
the reason this occurs are
- Developers have been influenced by UNIX and so the UNIX commands and syntax still exist
- Open source software means that a software can be built and then intergrated easily to another OS. Since many cli commands are external programes this is how this is achieved
- compliance with POSIX
give an overview description of what
recursion
is
This is where a function or process calls itself. It is used with many shell commands for actions such as searching through directories
example
function look_for_key(box) {
for (item in box) {
if (item.is_a_box()) {
look_for_key(item);
} else if (item.is_a_key()) {
console.log(“found the key!”)
}
}}
what is the > symbol used for
this is used to redirect the STDOUT (standard out stream) of a command to a file
describe what
POSIX (Portable Operating System Interface)
is
this is a set of standards and utilities maintained by IEEE that aims to maintain compatibility between operating systems. in turn meaning that an application can be run on either OS
The standards can define common APIs as well as how certain operating system tasks tasks should be handled.
Many OSs have some compliance with this
this will redirect the STDOUT (standard output) of a command to a given file.
- If the file contains content it will be preserved and the output will be appended to the end of the files content
- if the file does not exist it will be created
in a linux or windows terminal what does the (>>) achieve and what are 2 considerations before its use
in a linux or windows terminal what does the (>>) achieve and what are 2 considerations before its use
this will redirect the STDOUT (standard output) of a command to a given file.
- If the file contains content it will be preserved and the output will be appended to the end of the files content
- if the file does not exist it will be created
in a linux terminal:
this will search for the text pattern ‘sat’ while ignoring letter cases in the file named ‘datefile’
what is the outcome of typing
Grep ‘sat’ -I ‘datefile’
into a linux terminal
in linux this command is used when we would like to switch user accounts this includes logging in to the root account. this command is known as (switch user)
describe the linux
su
command
why are commands from UNIX seen in linux
Because linux was developed from UNIX many of the linux shells maintain traditions from UNIX such as syntax this in turn has kept compatibility alive between linux systems
also many of the linux shells are derivitives of the unix sh shell although they will contain many new features
in a linux terminal:
this will output detailed information about the contents of the directory
note
- if the first character of a line is a (-) it represents a file
- if the first character of a line is a (d) it represents a directory
what is the outcome of typing
Ls -l
into a linux terminal
what is the
root account
on linux
this is effectively the administrator account. this account has full control over the system and can carry out any commands
give an answer to each of these points concerning
nano
- what is it
- under what license is it released
- what would be one appropriate situation for using this
- what is it - This is a simple text editor that can be executed and ran inside the terminal
- under what license is it released - It is released under the GNU general public license meaning that end users can run, study, share and modify the software
- what would be one appropriate situation for using this - Linux has many configuration files written in plain text and using an editor such as this is the recommended approach to take when editing such files
in linux this is called a
tilde and points / references your home directory
what is the name and purpose of the ~ symbol in linux
the syntax is
Grep ‘string’ options ‘file or files’
what is the syntax for
grep
in a linux terminal:
This is used to move files and directories. If the source file given is moved to the same location this command then renames the file using the destination
give a description of the linux
mv
command and how it works
in a linux terminal:
this will find no file and will also not create a new file. execution ends silently
what is the outcome of typing
Touch non-existing filename -c
into a linux terminal
what does
POSIX
stand for
this is an accronym for
Portable Operating System Interface
in linux terminal:
This is used to search for files in a directory
what is the linux
find
command used for
when this occurs:
- the command - is not aware of anything being different or used
- the shell/terminal - will interpret that this has been used and send the appropriate commands to the OS
- the OS - will receive notification/commands from the shell and switch the STDOUT/STDIN appropriately
when using redirection or piping what are each of these aware of
- the command
- the shell/terminal
- the OS
2 options in linux that provide this are
-i - known as interactive will prompt the user before each action
-v - known as verbose will print to screen confirmation messages
linux commands are executed silently. meaning that unless there is an error or STDOUT then no feedback is given.
what are 2 options that can provide feedback/security
give 2 points about the linux
Dash (debian almquist shell)
this linux shell:
- is an extremely lightweight shell
- maintains compatibility strictly with the sh shell (can be used in place of the sh shell. this maintains compatibility with older scripts that may call sh)
give a description of the linux
touch
command
what is the outcme of typing
pwd
into a linux terminal
in a linux terminal:
this prints the current working directory
does the sh shell exist on linux
this can be called by scripts on linux but is not strictly available on linux.
instead it is available to call but is symbolically linked to the dash shell
this command is used by default to remove files. it however can also be used to remove directories in such a case the -r (recursive) option must be used
give a description of the
rm
command and how it handles directories
the reason this occurs are
- Developers have been influenced by UNIX and so the UNIX commands and syntax still exist
- Open source software means that a software can be built and then intergrated easily to another OS. Since many cli commands are external programes this is how this is achieved
- compliance with POSIX
give 3 reasons as to why many OSs share the same commands which may also have the same or similar functionality
describe the linux
grep
command
Standing for ‘global regular expression print’. is a tool for finding a given text pattern in a given text.
Text can be pipelined into this command or can be held inside a file
give a description of the
rm
command and how it handles directories
this command is used by default to remove files. it however can also be used to remove directories in such a case the -r (recursive) option must be used