Bash Flashcards

1
Q

Shell

A

A (possibly interactive) command interpreter, acting as a layer between the user and the system.

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

Bash

A

The Bourne Again Shell, a Bourne compatible shell. It’s important to understand that BASH is only an interface for you to execute statements (using BASH syntax), either at the interactive BASH prompt or via BASH scripts.

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

interactive mode

A

A mode of operation where a prompt asks you for one command at a time.

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

non-interactive mode

A

execute scripts (list of commands) that are stored in a file. When a script is executed, all these commands are (generally) executed sequentially, one after another.

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

$ man

A

stands for “manual”. it opens documentation (so-called “man pages”) on various topics. You use it by running the command man [topic] at the BASH prompt, where [topic] is the name of the “page” you wish to read.

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

$ man bash

A

if you’re looking for information on BASH built-ins (commands provided by BASH, not by external applications) you should look in man bash instead. BASH’s manual is extensive and detailed.

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

$ help

A

Bash also offers a help command which contains brief summaries of its built-in commands

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

Bash commands

A

BASH reads commands from its input (which is usually either a terminal or a file). Each line of input that it reads is treated as a command — an instruction to be carried out.

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

$ ls

A
# List files in the current directory (no output, no files).
Command ls prints out the names of the files in the current directory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

$ touch a b c

A

Create files ‘a’, ‘b’, and ‘c’.

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

$ mkdir test

A

makes an empty directory called test

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

$ cd test

A

enter the test directory

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

#

A

character at the start of a word indicates a comment. Any words following the comment are ignored by the shell, meant only for reading.

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

touch

A

an application that changes the Last Modified time of a file. If the filename that it is given does not exist yet, it creates a file of that name as a new and empty file.

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

$ rm *

A

Remove all files in the current directory. rm is an application that removes all the files that it was given. * is a glob. It basically means all and in this case means all files in the current directory. Takes filenames as arguments (if our filenames have spaces and we do not quote them, Bash thinks each word is a separate argument)

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

$ echo

$ echo This is a test.

A

a command that prints its arguments to standard output (which in our case is the terminal). In the second line, echo takes the arguments “This”, “is”, “a”, “test” and prints them out one by one with a space in between. Extra spaces make no difference

17
Q

Do spaces matter in Bash commands?

A

Nope

18
Q

How can you add extra spaces to an echo command?

A

Using quotes! We can use quotes around a sentence to pass it along as a single argument (with extra spaces).

19
Q

arguments

A

These are additional words specified after the command (‘ls -l foo’ executes ls with two arguments).

20
Q

Quotes

A

The two forms of quotes, single and double (‘ and “), are used to group words and can protect special characters.

21
Q

tip about quotes

A

Always quote sentences or strings that belong together, even if it’s not absolutely necessary. This developed practice will reduce the risk of human error in the scripts. (e.g. quoting a sentence of an echo command).

22
Q

alias

$ alias nmapp=”nmap -Pn -A –osscan-limit”
$ nmapp 192.168.0.1

A

a way of shortening a command. An alias is a word that is mapped to a certain string. Whenever that word is used as a command name, it is replaced by the string before executing the command. Aliases are limited in power; the replacement only happens in the first word. To have more flexibility, use a function. Aliases are only useful as simple textual shortcuts.

23
Q

Alias

A

a word that is mapped to a string. Whenever that word is used as a command, it is replaced by the string it has mapped.

24
Q

Function

A

a name that is mapped to a set of commands. Whenever the function is used as a command, it is called with the arguments following it. Functions are the basic method of making new commands.

25
Q

Builtin

A

certain commands have been built into Bash. These are handled directly by the Bash executable and do not create a new process.

26
Q

Executable

A

a program that can be executed by referring to its file path (e.g. /bin/ls), or simply by its name if its location is in the PATH variable.

27
Q

!/bin/bash

alternative:
#!/usr/bin/env bash
A

hashbang, specifies that /bin/bash is to be used as the interpreter when the file is used as the executable in a command. When the kernel executes a non-binary file, it reads the first line of the file. If the line begins with #!, the kernel uses the line to determine the interpreter to relay the file to. The #! must be at the very start of the file, with no spaces or blank lines before it.

28
Q

$ chmod +x myscript

$ ./myscript

A
# Mark the file as executable.
# Now, myscript can be executed directly instead of having to pass it to bash.