3.2 Commanding the Command Line Flashcards

1
Q

You can use the command ls -S to list files by __________.

A

You can use the command ls -S to list files by filesize.

By default, ls simply lists out the files in the current directory. The -S option modifies that behavior to list by size, largest first.

The syntax for the above command:
○ ls is the command.
○ -S is the option.

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

What does this command do?

head -n 4 logfile.txt

A

This command previews the first four lines of logfile1.txt.

By default, head displays the top 10 lines of a file.

The option -n changes the number of lines displayed.
○ -n requires a parameter specifying the number of lines.
○ Parameters provide additional details on how to modify a command’s default behavior.

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

IT and security professionals can learn and manage options with a valuable resource known as _______ pages.

A

IT and security professionals can learn and manage options with a valuable resource known as manual (man) pages.

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

What does the wc line do?

A

wc command allows you to count the number of lines, words, characters, and bytes of each given file or standard input and print the result.

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

What does this command do?

wc -w *

A

This will run the word count command for all the files in the current directory with a single command.

To run the word count command against all the files, you have to use a wildcard: *. (Wildcards will be covered in more detail in the next lesson.)

The command will be :

wc -w *

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

The ________ command searches for files and directories with one command.

A

The find command searches for files and directories with one command.

By default, find will search through the current directory and the subdirectories within that current directory.

However, find does not look at the contents within a file, only the file name or directory name.

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

What does this command do?

find -type f

A
  • This command finds all files in our current directory and its subdirectories.
  • We use the option -type and the required parameter f for files.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does this command do?

find -type f -name log.txt

A

This example will find a specific file.

We use the option -name to search for an exact match of the specified parameter, log.txt.

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

What will this command do?

find -type f -iname log.txt

A

This example will find the files called log.txt
(lowercase) or LOG.TXT (uppercase) in our current directory and its subdirectories.

To find a specific file with case insensitivity, we change the -name option to -iname.

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

Explain this command?

find /root/desktop -type f -iname log.txt

A

This examples uses find to search for a file located in another directory. Specifically, we’re looking for the case insensitive log.txt in the /root/desktop directory.

We place the desired directory after the find command and before the the -type option.

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

Explain this command?

find /root/desktop -type f -iname log.txt

A

This examples uses find to search for a file located in another directory. Specifically, we’re looking for the case insensitive log.txt in the /root/desktop directory.

We place the desired directory after the find command and before the the -type option.

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

Explain this command?

find -iname recipe -a -iname peanut

A

Uses a wildcard to search for filenames with the words “recipe” and “peanuts”

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

What does grep stand for and what does it do?

A

grep (global regular expression print) is a
command to search for data inside of files.

grep is a command-line command to find a data point inside of a file.

One of the most used commands

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

What does grep stand for?

A

grep (global regular expression print) is a
command to search for data inside of files.

One of the most used commands

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

We can use ________ command to search a file or multiple files for a specific data point.

A

grep

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

Explain what this command does?

grep -i bob *.txt

A

This grep command is used to find a case-insensitive specific data point.

Specifically, this command finds the lines where the user bob or BOB exists within all .txt files.

17
Q

Explain this command:

grep bob *.txt

A

In this example, we are using grep to find a specific data point within multiple files.

We are using grep to find where bob exists within in all .txt files.

a. bob is the specific data point being searched for.
b. *.txt is the wildcard. * indicates that it will search through all
files that end with .txt.

The command will display all the .txt files where the value of bob was found, followed by the lines where it was found.

18
Q

Explain this command:

grep -il bob *.txt

A

This example uses grep to indicate that it should display the name of the file that contains the specified data point.

Specifically, this command outputs the file names of .txt files containing the user bob or BOB. It will only display the names of the files containing these users.

Note: -il are two separate options.

  • i is an option for grep indicating case insensitivity.
  • l is an additional option indicating to only return the file name.
  • i and l use a single hyphen.
19
Q

You can use the command ls -S to list files by __________.

A

You can use the command ls -S to list files by size.

By default, ls simply lists out the files in the current directory. The -S option modifies that behavior to list by size, largest first.

The syntax for the above command:
○ ls is the command.
○ -S is the option.

20
Q

IT and security professionals can learn and manage options with a valuable resource known as _______ pages.

A

IT and security professionals can learn and manage options with a valuable resource known as manual (man) pages.

21
Q

Explain this example:

A

In this example, we are using grep to find a specific data point within a single file.

22
Q

Explain this command:

grep -il bob *.txt

A

This example uses grep to indicate that it should display the name of the file that contains the specified data point.

Specifically, this command outputs the file names of .txt files containing the user bob or BOB. It will only display the names of the files containing these users.

Note: -il are two separate options.

  • i is an option for grep indicating case insensitivity.
  • l is an additional option indicating to only return the file name.
  • i and l use a single hyphen.
23
Q

The basic syntax to using grep to find information in a file is:

A
24
Q

True or False:

grep by default will return the whole line on which it finds the data point.

A

True

25
Q

Explain this command:

grep -i guavaberries *

A

grep -i guavaberries *

grep: = The command being run.
- i = An option for grep indicating case insensitivity.

guavaberries = The specific data point being searched for.

  • = A wildcard, indicating the command should search through all files in the current directory.
26
Q

Explain this command:

find -type f -iname recipe -a -iname peanut

A

find -type f -iname recipe -a -iname peanut

find: The command-line command.
- type: The option for specifying whether you’re searching for a file or a directory.
f: The required parameter for the -type option, indicating you’re searching for a file.
- iname: The option indicating you’re searching for a specific case-insensitive value.
* recipe*: The parameter specifying the value you’re searching for. The two wildcards indicate that the value of recipe can be located anywhere in the file name.
- a: The conditional statement that represents AND, which states that the next value must also be matched in the result.
- o can be used as an OR conditional, returning results that include either one of the specified values.
- iname peanut: The second value that needs to be found in a file name.