GX3 The Power of the Command Line Flashcards

1
Q

3.1: Archiving Files on the Command Line

What command is used to create, extract, and manipulate archive files in Linux?

A

The tar command.

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

3.1: Archiving Files on the Command Line

How do you create a tar archive of a directory named mydir

A

tar -cvf mydir.tar mydir

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

3.1: Archiving Files on the Command Line

What do the common tar options mean?

A

-c → Create an archive
-v → Verbose (list files being processed)
-f → Specify archive file name
-x → Extract files
-t → List contents of an archive

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

3.1: Archiving Files on the Command Line

How do you compress a file using gzip?

A

gzip filename (creates filename.gz)

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

3.1: Archiving Files on the Command Line

How do you extract a .tar.gz archive?

A

tar -xvzf archive.tar.gz

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

3.1: Archiving Files on the Command Line

What commands are used to work with .zip files?

A

Create: zip archive.zip file1 file2

Extract: unzip archive.zip

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

3.2: Searching and Extracting Data from Files

How do you search for a specific word in a file?

A

Use grep. Example: grep “word” filename

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

3.2: Searching and Extracting Data from Files

What is the purpose of less?

A

It allows you to view a file one page at a time. Example: less filename

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

3.2: Searching and Extracting Data from Files

What command outputs the first 10 lines of a file?

A

head filename

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

3.2: Searching and Extracting Data from Files

What command outputs the last 10 lines of a file?

A

tail filename

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

3.2: Searching and Extracting Data from Files

How do you sort the lines of a file alphabetically?

A

Use sort. Example: sort filename

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

3.2: Searching and Extracting Data from Files

What command extracts specific columns from a file?

A

cut. Example: cut -d’,’ -f2 filename (extracts the second column using , as a delimiter)

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

3.2: Searching and Extracting Data from Files

How do you count the number of words, lines, or characters in a file?

A

Use wc. Example:

wc -l filename (line count)
wc -w filename (word count)
wc -c filename (character count)

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

3.2: Searching and Extracting Data from Files

What is I/O redirection, and how is it used?

A

> redirects output to a file (overwrite). Example: echo “Hello” > file.txt
> appends output to a file. Example: echo “World”&raquo_space; file.txt
< takes input from a file. Example: sort < file.txt

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

3.2: Searching and Extracting Data from Files

What are pipes (|), and how are they used?

A

Pipes allow output of one command to be used as input for another. Example: cat file.txt | grep “keyword”

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

3.3: Turning Commands into a Script

What is a shell script?

A

A shell script is a file containing a series of commands that can be executed together.

17
Q

3.3: Turning Commands into a Script

What is the shebang (#!)?

A

It defines the interpreter for a script. Example: #!/bin/bash

18
Q

3.3: Turning Commands into a Script

How do you create a simple shell script?

A

1.Open a text editor (e.g., nano script.sh)
2.Add #!/bin/bash at the top
3.Write commands
4.Save and give execution permission (chmod +x script.sh)
5.Run it (./script.sh)

19
Q

3.3: Turning Commands into a Script

How do you define a variable in a shell script?

A

MYVAR=”Hello” (No spaces around =)

20
Q

3.3: Turning Commands into a Script

How do you use command-line arguments in a script?

A

$1, $2, etc., represent arguments. Example: echo “First argument: $1”