Lesson 5: Managing Files and Directories Flashcards

1
Q

What are the most common text editors?

A

vi (visual text editor, originally created for Unix, later cloned into FOSS versions)

Vim (default text editor in most distributions)

Emacs (flexible, powerful, and popular text editor used in Linux and Unix)

gVim (graphical version of the Vim editor)

gedit (powerful GUI-based text editor used in the GNOME desktop environment)

GNU nano (small, user-friendly text editor)

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

How would you work with display multiple files in multiple windows?

A

You can press Ctrl+W+V to create a vertical split, or press Ctrl+W+S to split the screen horizontally

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

In vi insert mode how do you inserts text to the left of the cursor?

A

use i

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

How do you enter insert mode in Vi?

A

type the letter “ i “ in command mode

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

In vi insert mode how do you adds text at the end of a line?

A

Use A

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

In vi insert mode how do you inserts text at the beginning of a line?

A

use I

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

What will result if you enter the following command “:!” in vi?

A

Executes the command and displays the result inthe Vim interface.

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

How do you enter execute mode in Vi?

A

you type : (colon) while in command mode

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

How do you delete a line in Vi?

A

In command mode type “ dd “ OR “ d “ in execute mode

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

What are motions and how do you use them?

A

Motions are single-key shortcuts that are used to navigate through files in command mode.

h Move left one character.
j Move down one line.
k Move up one line.
l Move right one character
^ Move to the beginning of the current line.
$ Move to the end of the current line.
w Move to the next word.
b Move to the previous word.
e Move to the end of the current word or to the end of thenext word if you are already at the end of the word.
Shift+L Move the cursor to the bottom of the screen.
Shift+H Move the cursor to the first line of the screen.(Line number)
Shift+G Move the cursor to the specified line number.
gg Move the cursor to the first line of the file.
Shift+G Move the cursor to the last line of the file.

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

What are editing operators and how do you use them?

A

Editing operators are tools that are used to manipulate text and can be used in combination with motions to edit multiple characters.

x Delete the character selected by the cursor.
d Delete text.ddDelete the current line.
p Paste text on the line directly below the cursor or directly above the cursor.
/{text string} Search through the document for specific text.
?{text string} Search backward through the document for specific text.
y Copy text or yy Copy the line directly above the cursor.
c{range of lines}c Begin a change in the specified range.
u Undo the latest change or U Undo all changes in the current line.
ZZ Write the file only if changes were made, then quit the Vim editor.

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

How do you enable line numbers in Vi?

A

run “: set number” in execute mode

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

Where can you change and set Vi preferences?

A

in the .vimrc file if does not show try vi ~/.vimrc to create and edit

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

How do you delete multiple lines in Vi?

A

in execute mode :start_line#,end_line#d

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

What does the count command accomplish?

A

A count is a number that multiplies the effect of keystrokes in Vim. an be used incombination with motions, operators, or both.

syntax for using a count with an operator and a motion is operator [count] {motion}

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

In Vi command mode what does / prompt you to do?

A

search context

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

In Vi command mode what does / prompt you to do?

A

search context

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

How do you search and replace a string in Vi?

A

/string/replace_string OR :%s/string/replace_string (to change for the entire doc)

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

How would you open a document and perform a search at the same time?

A

vi +/{search_string} doc_name

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

In Vi, if you type o from command mode, what will it do?

A

Enters insert mode start new line

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

In Vi, if you type a from command mode, what will it do?

A

Starts insert after cursor

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

When in vi execute mode, what does the e character do?

A

lets you edit another file

:e (new_file_name)

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

How do you open the GNU nano editor?

A

The nano command invokes the GNU nano editor.

syntax -> nano {file name}

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

What are some GNU nano, shortcuts and their functions?

A

Ctrl+G Open nano to the help screen.
Ctrl+X Exit nano or close the current “buffer” (e.g., the help screen itself).
Ctrl+O Save the currently open file.
Ctrl+J Justify the current paragraph.
Ctrl+R Insert another file into the current one.
Ctrl+W Search the file.
Ctrl+K Cut the currently selected line.
Ctrl+U Paste the line that was cut.
Ctrl+C Display the cursor’s position.
Ctrl+V to navigate to the next page and Ctrl+Y to navigate to the previous page.
Copying parts of text on a line requires you to “mark” the text you want to copy with the Ctrl+^ shortcut.
You then navigate your cursor to highlight the text you want to copy. Pressing Alt+^ copies the marked/highlighted text.

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

What are the most useful option for the ls command?

A
  • l Display a long list including the permissions, number of hardlinks, owner, group, size, date, and file name.
  • F Display the nature of a file, such as * for an executable file and /for a directory.
  • a Display all files present in the directory, including the files whosenames begin with a period ( . ).
  • R Recursively display all subdirectories.
  • d Display information about symbolic links or directories rather than the link’s target or the contents of the directory.
  • L Display all files in a directory, including symbolic links.
  • h show file sizes in human readable formate

syntax of the ls command is ls [options] [file/directory names]

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

How do you change the time of access or modification time of a file to the current time, or to a specified time?

A

Use the touch command

syntax of the touch command is touch {file names}

useful: intesting permissions or in simply creating files that will later be processed by someapplication.

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

What are some commands to view files?

A

cat (concatenate) - frequently used to display the contents of small text files, as it does not havea screen scrolling capability.

more (allows you to scroll through but unable to scroll back up)

less (allows you to scroll through files, allows you to use search commands)

head (show first 10 lines) unless you specify head -n (#of_pages)

tail (shows last 10 lines) unless you specify tail -n (#of_pages)
-f (follows changes)

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

What command can display, combine, and create text files?

A

The cat command, short for concatenate, frequently used to display small text files.

syntax -> cat [options] {file names}

Options:

  • n Precede the output with its respective line number.
  • b Number the lines, excluding the blank lines.
  • s Suppress output of repeated empty lines.
  • v Display non-printing characters as visible characters, other than tabs, new lines, and form feeds.
  • e Print a $ character at the end of each line, prior to the new line.
  • t Print tabs as ^I and form feeds as ^L
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

How do you copy a file?

A

cp (source) (destination)

try coping var/log/messages

30
Q

How do you move files and directories to other locations?

A

Use the mv command

syntax -> mv [options] {file/directory name to move} {file/directory name destination}

31
Q

How do you rename a file or directory?

A

Use the command mv

syntax is mv [options] {old file/directory name} {new file/directory name}

32
Q

How do you copy a folder and all of its contents?

A

cp -r * (recurssive )

syntax -> cp [options] {file/directory name to copy} {file/directory name destination}

33
Q

How do you remove a file or folder?

A

Use rm

syntax of the rm command is rm [options] {file/directory names}

note: must use the -R option to recursively remove files, subdirectories, and the parent directory itself

34
Q

How do you remove a folder when there’s stuff in it?

A

rm -rf (to force it)

35
Q

How do you display a line of text on the terminal>

A

Use the echo command or printf

syntax of the echo command is echo {string}

printf, similar to echo, but provides the user with much more control over how the output is formatted.

36
Q

What command would you use to search a specific location for files and directoriesthat adhere to some search criteria.?

A

Use find command. It recursively searches the directory structure, including any subdirectories and their contents, beginning with the search location you enter.

syntax -> find [options] {search locations} {search criteria} [actions]

. searched current directory
~ searched home directory
/ searches disk (root)

  • type option enables you to specify the type of object you’re looking for, such as d for directory or f for file. The -name option is where you specify the name of theobject you’re looking for.
37
Q

How do you opt out bad return/ errors when using find?

A

find (location) (resource.txt) 2>/dev/null

38
Q

How do yo specific how far deep find should go in directories?

A

Use find -maxdepth

39
Q

How would you search for a command and display it’s complete path?

A

whereis (command) OR which (command)

note. that the whereis command is used to display various details associated with a command syntax-> whereis [options] [directory name] {file name}

  • b Search only for binaries.
  • mSearch only for manual sections.
  • sSearch only for sources.
  • uSearch for unusual entries.
40
Q

What is the function of the type command?

A

tells you what type of executable or what type of function a command happens to be

41
Q

Explain common RegEx wildcards characters (dashes, brackets,)

A

RegEx (regular expressions)
man 7 regex

Wildcard
[ ] -
.
*
[?] How do we use regular expressions to search for data?
grep
Description
List of possible values Range of values
Any single character
Any number of characters Begining of line
^
$
`` Or ( ) Sub-expressionorslice
\ Escape character
42
Q

if looking for something that contains wildcards characters

A

escaping the character search true literal character you put back slash before it

43
Q

What are the two modes of “Globally Search a Regular Expression and Print” OR grep?

A

Fixed string (fgrep) and extended regular expression (egrep)

egrep command is essentially the same as the grep -E command. However,egrep is deprecated, as grep -E is the preferred syntax.

44
Q

What search tool allows you to search the contents of a file for a particular string of text?

A

grep, syntax of the grep command is grep [options] {search pattern} {file names}

command options:

-E {pattern}Match a pattern as an extended regular expression(ERE).-F {pattern}Match a pattern as a list of fixed strings.-f {file name}Match patterns contained in the specified file.-iIgnore casing.-vOutput only lines that don’t match the providedpattern.-cOnly print the number of matching lines, not the linesthemselves.-lOnly print the file(s) that have matching lines, not thelines themselves.-oOnly print the matching part of a line, not the entireline.

45
Q

How do you use grep to search a a directory in order to locate a certain file?

A

ls -l | grep {string}

46
Q

What command translates a string of characters?

A

The tr command

syntax of the tr command is tr {character 1} {character 2}where {character 1} is the character to be replaced.

predominantly usedto change the case of letters in a file. This command acts only on a stream ofcharacters and does not accept file names as arguments

47
Q

What is the wc command?

A

word count command, used to count the number of lines, words, andcharacters in a text file.

syntax of the wc command is wc [options] {file names}

Options:

  • c Display the byte count.
  • m Display the character count.
  • l Display the newline count.
  • wDisplay the word count.
48
Q

How do you arranges the lines of text out from a file ?

A

use the sort command

syntax of the sort command is sort [options] {file names}

  • k {column numbers}Specify field values.
  • n Compare and sort lines based on the string numericalvalue.
  • r Sort fields in descending order. By default, the fieldsare sorted in ascending order.
  • t {delimiter}Separate one field from another.
49
Q

How would extract and view the specified lines of text from a file?

A

Use the cut command, syntax of the cut command is cut [options] {file names}

  • c Specify the number of the character to cut from each line.
  • d {delimiter}Separate one field from another.-f{field numbers}Specify the field numbers to cut on as separated by the delimiter.
  • s Suppress a line if the delimiter is not found.
50
Q

How do you merge lines from text files horizontally?

A

Use the past command

51
Q

How do you compare and see the difference between two files?

A

use the diff command, The syntax of the diff command is diff {file name 1} {file name 2}

usefulness: for comparing backup config files

  • b Ignore spacing differences.
  • I Ignore case differences.-tExpand tab characters in output lines.
  • w Ignore spacing differences and tabs.
  • c Display a list of differences with three lines of context.
  • u Output results in unified mode, which presents a more streamlined format.
52
Q

How do you performs pattern matching on files?

A

Use the AWK command

syntax of the awk command is awk [options] [‘patterns {actions}’] {file names}

awk scripts, you can provide patterns along with blocks of code:

/regular_expression/ - Retrieves all the records beginning with “a”,”b”, or “c”.Example: /[abc]/

relational_expression - Retrieves all the records whose first fieldcontains the value “abc” Example: $1 == “abc”

pattern_1 && pattern_2 - Retrieves all the records whose first fieldcontains the value “abc” and the second fieldcontains the value “01”Example: ($1 == “abc”) && ($2 == “01”)

pattern_1 || pattern_2 - Retrieves records that satisfy the condition thatthe first field contains the value “abc” or thesecond field contains the value “01” or both.Example: ($1 == “abc”) || ($2 == “01”)

pattern_1 ? pattern_2 : pattern_3 - If the first field in a record contains the value”10”, the fifth field is tested for its value. If thefifth record contains the value “20”, then therecord is printed. If the first field of a recorddoes not contain the value “10”, then the ninthfield of the record is evaluated. If the ninthrecord contains the value “30”, then the recordis printed.Example: $1 == “10” ? $5 == “20” : $9 == “30”

pattern_1, pattern_2 Prints a range of records, starting from the record whose first field contains the value “01”.The records will be printed until the awkcommand finds a record whose first fieldcontains the value “02”.Example: $1 == “01”, $1 == “02”

53
Q

What is sed and how would you use use sed?

A

stream editor command is a program that you can use to modify text files according to various parameters. general syntax of the sed command is sed {‘option/address/action’} {file names}

d Delete the lines that match a specific pattern or line number.
-n,p Print only the lines that contain the pattern.
s Substitute the first occurrence of the string in the file.
s,g Globally substitute the original string with the replace mentstring for each occurrence in the file.

54
Q

How would you work with display multiple files in multiple windows?

A

You can press Ctrl+W+V to create a vertical split, or press Ctrl+W+S to split the screen horizontally

55
Q

How do you open the GNU nano editor?

A

Use the nano command

syntax -> nano {file name}

56
Q

How do you open the GNU nano editor?

A

Use the nano command

syntax -> nano {file name}

57
Q

How do you perform a quick search for any specified string in file names and paths?

A

locate command performs a quick search for any specified string in file names and paths stored in the mlocate database

syntax -> locate [options] {string}

58
Q

How do you update the /var/lib/mlocate/mlocate.db database?

A

use the updatedb command.

note this command is also used to build a database of files based on the /etc/updatedb.conf file

59
Q

What does the /etc/updatedb.conf file consists of?

A

Consists of paths that should be excluded while building the database.

60
Q

How do you add a path that needs to be excluded while building the database (mlocate.db database)

A

Open the /etc/ updatedb.conf file

In the PRUNEPATH variable, specify the path that need not be included while building the database.

example: PRUNEPATH=”/etc” will exclude the /etc directory

61
Q

What’s the main difference between the locate and find command?

A

The locate command searches a database, so a failure to keep this database updated may produce outdated results. The find command, performs a live search of the file system.

62
Q

What are some options for when files are found using command such as locate?

A
  • print Displays the location of the files found.
  • exec Executes the command that follows.
  • ok Executes the command that follows interactively.
  • delete Deletes files found.
  • fprint Stores results in the target file.
63
Q

How do you change the time of access or modification time of a file to the current time, or to a specified time?

A

Use the touch command

syntax of the touch command is touch {file names}

useful: intesting permissions or in simply creating files that will later be processed by someapplication.

64
Q

How do you create a link to a file?

A

syntax of the ln command is ln [options] {target name} [link name]

options:

  • -backup Back up existing destination files.
  • f Remove existing destination files.
  • s Make symbolic links instead of hard links.
  • I Prompt to remove destination files.
  • v Print the name of a file before linking.

note that you can create a hard link or a symbolic link?

65
Q

Define stdin?

A

Standard input, or stdin, is a text stream that acts as the source for command input.

66
Q

Define stdout?

A

Standard output, or stdout, is a text stream that acts as the destination for commandoutput.

67
Q

Define stderr?

A

Standard error, or stderr, is a text stream that is used as the destination for errormessages.

68
Q

Define input/output Redirection?

A

Redirection is the process of accepting input data from a source other than the keyboard and sending output data to a destination other than the display device. Commonly used to accept input from files or send output to files using the stdin, stdout, and stderr streams.

69
Q

Explain several operators that are used to redirect input or output?

A

> Redirect the standard outputto a file.ls > file1.txtThe output of the ls command will beredirected to a file namedfile1.txt.»Append the standard outputto the end of the destinationfile.ls&raquo_space; file1.txtThe output of the ls command will beappended to a file namedfile1.txt.2>Redirect the standard errormessage to a file.ls file3.txt 2> errorfile.txtAssuming that file3.txt does notexist, the resulting errors will not bedisplayed on the screen, but they will beredirected to a file namederrorfile.txt.2»Append the standard errormessage to the end of thedestination file.ls file3.txt 2» errorfile.txtAssuming that file3.txt does notexist, the resulting errors will not bedisplayed on the screen, but they will beappended to a file namederrorfile.txt.&>Redirect both the standardoutput and the standarderror message to a file.ls file1.txt file3.txt &> errorfile.txtAssuming that file1.txt exists andfile3.txt does not, the resultingoutput and errors will not be displayedon the screen, but they will beredirected to a file namederrorfile.txt.

70
Q

What is Piping?

A

Piping is the process of combining the standard I/O streams of commands. The pipe operator (|)

71
Q

What is the xargs command?

A

The xargs command reads from standard input and executes a command for each argument provided. Commonly used with the find command to operate on each result that is found within the file or directory search.

syntax of the xargs command is command [options] [arguments] | xargs [options] {command}

Options:

  • I {replacement string}Consider each line in the standard input as asingle argument.-L {number of lines}Read a specified number of lines from thestandard input and concatenate them intoone long string.-pPrompt the user before each command.-n {number of arguments}Read the maximum number of argumentsfrom the standard input and insert them atthe end of the command template.-E {end of string}Represent the end of the standard input.-tWrite each command to the standard erroroutput before executing the command.
  • s {max size}Set the maximum allowable size of anargument list to a specified number ofcharacters.
72
Q

Explain the tee command

A

The tee command reads the standard input, sends the output to the default output device (the CLI), and also copies the output to each specified file. general syntax of the tee command is command [options] [arguments] | tee [options] {file names}

used with the -a option, tee appends the output to each output file instead ofoverwriting it.