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
within this utility:
- up/down arrow keys - can be used to navigate the text
- spacebar - is used to view the next page
- h - is used to get help about the utility
- q - is used to quit the utility
regarding the linux
less utility
what do each of these actions achieve
- up/down arrow keys
- spacebar
- h
- q
what is the outcome of typing
mv my-file my-file2
into a linux terminal
in a linux terminal:
this will rename the file my-file to my-file2
this is made possible because most commands will use text as thier input and output.
this means that commands can be used flexibly with each other since they are all using text format
what makes pipelining between commands possible
regarding the linux
less utility
what do each of these actions achieve
- up/down arrow keys
- spacebar
- h
- q
within this utility:
- up/down arrow keys - can be used to navigate the text
- spacebar - is used to view the next page
- h - is used to get help about the utility
- q - is used to quit the utility
what is the outcome of typing
Cat file1 file2 file3
into a linux terminal
in a linux terminal:
this will print each of the given files to the terminal in the given order
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!”)
}
}}
give an overview description of what
recursion
is
in a linux terminal:
this will navigate you to the directory/path entered
what is the outcome of typing
Cd path
into a linux terminal
what is the outcome of typing
Nano filename
into a linux terminal
in a linux terminal:
this will open the file in the nano text editor ready for reading and editing
this is effectively the administrator account. this account has full control over the system and can carry out any commands
what is the
root account
on linux
this directory contains linux configuration files
describe the linux
/etc
directory
what is the outcome of typing
Sudo su root
into a linux terminal
this will switch the shell to the root account and give the user full control of the system.
root can be omitted since linux will assume root
This can be dissected into several parts
- The username
- The hostname
- The current directory
- Privilege. $ for normal privileges, # for superuser privileges
example
pi@raspberry:~ $
- The user is called pi
- The computer name / hostname is raspberry
- They are in the home directory
- They have normal privileges
what are the 4
parts of a linux prompt
what are the 4
parts of a linux prompt
This can be dissected into several parts
- The username
- The hostname
- The current directory
- Privilege. $ for normal privileges, # for superuser privileges
example
pi@raspberry:~ $
- The user is called pi
- The computer name / hostname is raspberry
- They are in the home directory
- They have normal privileges
how do you switch between shells on a linux system
achieving this is simply a case of entering the shell name into the termial
give 2 points about the linux:
Zsh (z shell)
this linux shell:
- is compatible with bash but offers more customisation
- macOS has recently replaced bash with this shell
this is an abbreviation of
‘global regular expression print’
what does
grep
stand for
what does
bash
stand for
this is an accronym for:
bourne again shell
what is the outcome of typing
Cat file1 file2 file3 > file4
into a linux terminal
in a linux terminal:
this will concatenate each of the files given and then redirect the output to the file given
how can the operating system
optimize pipelining
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
what is the outcome of typing
Find /etc -name ‘*.conf’
into a linux terminal
this will search in the /etc directory for any files that have a name ending with ‘.conf’
in a linux terminal:
this will print each of the given files to the terminal in the given order
what is the outcome of typing
Cat file1 file2 file3
into a linux terminal
achieving this is simply a case of entering the shell name into the termial
how do you switch between shells on a linux system
in a linux terminal:
this will copy the file my-file into the directory my-directory
what is the outcome of typing
Cp my-file my_directory
into a linux terminal
in a linux or windows terminal what is the ( | ) used for
know as the pipeline. this allows you to redirect or ‘pipe’ the STDOUT (standard output stream) of one command to the STDIN (standard input stream) of another command
what is the outcme of typing
Mkdir value
into a linux terminal
in a linux terminal:
this will make a new directory with the name as the value given
what is the outcome of typing
File filename
into a linux terminal
in a linux terminal:
this will tell you the file type of the filename you have given
what is the syntax for
grep
the syntax is
Grep ‘string’ options ‘file or files’
this will search in the /etc directory for any files that have a name ending with ‘.conf’
what is the outcome of typing
Find /etc -name ‘*.conf’
into a linux terminal
this linux shell:
- uses similar loops, conditionals and expressions to the language C
give a point about the linux
Csh (c shell)
describe the linux
su
command
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)
these are:
. - this points to the directory itself
.. - this points to the parent directory
what are the 2
hidden directories that every linux directory will have
in a linux terminal:
this will rename the file my-file to my-file2
what is the outcome of typing
mv my-file my-file2
into a linux terminal
what is the outcome of typing
Cd path
into a linux terminal
in a linux terminal:
this will navigate you to the directory/path entered
describe the linux
less
command and a use case
This is a pager utility that allows you to view voluminous data either line by line or a page at a time.
If a command outputs a lot of data then piping it into this will help you read and navigate the text
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
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
give a point about the linux
Csh (c shell)
this linux shell:
- uses similar loops, conditionals and expressions to the language C
in a windows and linux terminal what is the (>) used for and 2 considerations to take into account before its use
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
when using redirection or piping what are each of these aware of
- the command
- the shell/terminal
- the OS
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 a terminal is opened what are the default input and output streams configured by the operating system
when this occurs the operating system will set:
- the input stream as the keyboard
- the output stream as the terminal window
in a linux terminal:
this will remove the given directory but only ever if it is empty
what is the outcome of typing
Rmdir directory
into a linux terminal
how can we quickly view the available shells on a linux system via the terminal
this can be achieved by entering
cat /etc/shells
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
Rm filename -f
into a linux terminal
this command will concatenate files and print on the standard output
give a description of the linux
cat
command
- 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
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
This is a pager utility that allows you to view voluminous data either line by line or a page at a time.
If a command outputs a lot of data then piping it into this will help you read and navigate the text
describe the linux
less
command and a use case
how the linux cli operates
(come back to this at the end of the module)
• 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.
describe the linux
/etc/shells
file
this is a file that contains the paths of available shells on the linux system
in a linux terminal:
this will move the file my-file into the directory my_directory
what is the outcome of typing
mv my-file my_directory
into a linux terminal
what does
grep
stand for
this is an abbreviation of
‘global regular expression print’
in a linux terminal:
this will open the file in the nano text editor ready for reading and editing
what is the outcome of typing
Nano filename
into a linux terminal
what is the outcome of typing
Touch non-existing filename
into a linux terminal
in a linux terminal:
will create a new file with the name of the given filename
what is the outcome of typing
mv my-file my_directory
into a linux terminal
in a linux terminal:
this will move the file my-file into the directory my_directory
in a linux terminal:
will create a new file with the name of the given filename
what is the outcome of typing
Touch non-existing filename
into a linux terminal
describe the linux
/proc/cpuinfo
file
this is a file that contains information about the systems processor
describe the linux
/etc
directory
this directory contains linux configuration files
what was the shell used on UNIX systems called and who created it
the shell used on this was named sh (bourne shell) as was written by stephen bourne
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
describe what
POSIX (Portable Operating System Interface)
is
this is an accronym for
Portable Operating System Interface
what does
POSIX
stand for
what is the outcome of typing
Cd ..
into a linux terminal
in a linux terminal:
this will take you back to the parent directory
give a description of the linux
touch
command
This linux command allows a single command to be executed with root privileges
describe the linux
sudo
command
in a linux terminal:
this prints the current working directory
what is the outcme of typing
pwd
into a linux terminal
what makes pipelining between commands possible
this is made possible because most commands will use text as thier input and output.
this means that commands can be used flexibly with each other since they are all using text format
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
does the sh shell exist on linux
this linux shell:
- is compatible with bash but offers more customisation
- macOS has recently replaced bash with this shell
give 2 points about the linux:
Zsh (z shell)
give a description of the linux
file
command and how it works
this will determine the type of a file
it works by performing three test on the file to determine its type / content. The first test to complete successfully is output in the terminal
give three points about the linux:
Bash (bourne again shell)
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
what does
dash
stand for
this is an accronym for
debian almquist shell
this will determine the type of a file
it works by performing three test on the file to determine its type / content. The first test to complete successfully is output in the terminal
give a description of the linux
file
command and how it works
what is the outcome of typing
Ls -a
into a linux terminal
in a linux terminal:
this will display all directories including any hidden ones
this is an accronym for
debian almquist shell
what does
dash
stand for
in a windows or linux terminal what does the (
this can be used to give STDIN (standard input) to a command from a file for example
in a linux terminal:
this will take you back to the parent directory
what is the outcome of typing
Cd ..
into a linux terminal
this will switch the shell to the root account and give the user full control of the system.
root can be omitted since linux will assume root
what is the outcome of typing
Sudo su root
into a linux terminal
in a linux terminal:
this will display all directories including any hidden ones
what is the outcome of typing
Ls -a
into a linux terminal
know as the pipeline. this allows you to redirect or ‘pipe’ the STDOUT (standard output stream) of one command to the STDIN (standard input stream) of another command
in a linux or windows terminal what is the ( | ) used for
describe the linux
sudo
command
This linux command allows a single command to be executed with root privileges
this can be achieved by entering
cat /etc/shells
how can we quickly view the available shells on a linux system via the terminal
what is the outcome of typing
Date > filename
into a linux terminal
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 are the 2
hidden directories that every linux directory will have
these are:
. - this points to the directory itself
.. - this points to the parent directory
what is the outcome of typing
Rmdir directory
into a linux terminal
in a linux terminal:
this will remove the given directory but only ever if it is empty
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 2 points about the linux
Dash (debian almquist shell)
in a linux terminal:
this will concatenate each of the files given and then redirect the output to the file given
what is the outcome of typing
Cat file1 file2 file3 > file4
into a linux terminal