Week 2 - Command Line Flashcards

1
Q

What is the top-level directory?

A

The ‘root’ directory, indicated with ‘/’.

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

What is an absolute path?

A

A path that starts from the root directory (/) and specifies the exact
location of a file or directory
▪ Example: Command: cd /etc/passwd

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

What is a relative path?

A

A path that starts from your current working directory and
specifies the location of a file or directory relative to it
▪ Current Directory: /home/user → Command: cd Downloads

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

What is a command option?

A

Options Overview: Predefined values that modify the behavior of a command. Typically, single characters after a hyphen (-) or words after two hyphens (–). Some newer commands accept word options → Example: ls –long

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

What is a command argument?

A

Arguments:
▪ Parameters that follow the command to specify targets or options
▪ Example: cd /bin

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

What are multiple commands?

A

Multiple Commands:
▪ Separate commands with semicolons (;) and press Enter after the last command
▪ Example: pwd ; date ; ls

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

cd

A

Change directory:
cd . - Stays in the current directory.
cd.. - Moves up one level.

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

cd ~

A

Returns to the home directory.

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

file

A

Outputs the type of content in the file. Example: ASCII text

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

cat

A

Output the contents of a file.

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

To navigate to the Downloads directory, which is inside your home directory,
what would you type?

A

cd ~/Downloads

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

ls -l

A

list the files in the working directory in long format.

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

ls /bin

A

List the files in the /bin directory. (Can be used for other directories.)

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

ls -a

A

List all files, including hidden files.

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

ls -r

A

Reverse the output order of the string.

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

ls -S

A

Sort by file size.

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

ls -r

A

Sort by modification time. (Newest first)

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

ls -d D*

A

Lists all directories that begin with the letter D. Without (-d) it would also display all the contents within that directory.

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

What are the 3 file types shown with the ls.

A

(-) plain file, (d) directory, (l) symbolic link

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

What is a hard link?

A

They are directory entries that reference the exact same underlying data. The data in a file is specified by its inode. Each file on a file system points to an inode but there’s no requirement that each file point to a unique inode. The where hard link reference counts come from the inode.

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

File Globbing

A

Using wildcards to match filenames based on patterns.

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

What does ls -d ????? do?

A

Lists all files in the current directory that are exactly five characters long.

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

What does ls * do?

A

Lists all files and folders including subdirectories.

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

What does this command do?
mv file1.txt file2.txt

A

Uses the move command to rename a file. If file2 does not exist, file1 is renamed to file2. If file2 exists, it is overwritten with the contents of file1.

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

What does this command do?
mv file1 file2 dir1/

A

Moves file1 and file2 into dir1. If dir1 does not exist, an error occurs

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

Explain:
mv dir1 dir2

A

If dir2 does not exist, dir1 is renamed to dir2. If dir2 exists, dir1 is moved into dir2 as a subdirectory.

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

Explain this wildcard:
Data???

A

Any filename that begins with the characters “Data” followed by exactly 3 more characters

28
Q

Explain this wildcard:
[abc]*

A

Any filename that begins with “a” or “b” or “c” followed by any other characters

29
Q

Explain this wildcard:
[[:upper:]]*

A

Any filename that begins with an uppercase letter. This is an example of a character class

30
Q

Explain this wildcard:
BACKUP.[[:digit:]][[:digit:]]

A

Another example of character classes. Any filename starting with “BACKUP” followed by exactly two numerals

31
Q

Explain this wildcard:
*[![:lower:]]

A

Any filename that does not end with a lowercase letter

32
Q

What does the ‘less’ command do?

A

Displays large text files, pausing after each page.
b: page back
q: exit to the shell

33
Q

Explain this command:
mkdir dir1 dir2 dir3

A

Creates three directories: dir1, dir2, and dir3

34
Q

Explain this command:
cp file1.txt /backup/

A

Uses the copy command to duplicate file1.txt to the /backup/ directory.

35
Q

What is the ‘rm’ command used for?
Ex. rm test.txt

A

Remove - deletes files or directories.

36
Q

Explain this command:
cp file1 file2
cp -i file1 file2

A

Copies the contents of file1 into file2. If file2 does not exist, it is created; if it does exist, it is overwritten without warning.
Can add (-i) to prompt for confirmation before overwriting.

37
Q

rm -r dir1

A

Removes directories and their content recursively. The directory does not have to be empty.

38
Q

Explain this command:
cp -R dir1 dir2

A

Copies the contents of dir1 into dir2.
If dir2 does not exist, it is created.
If dir2 exists, dir1 is copied as a subdirectory within dir2.

39
Q

rm -r dir1

A

Removes directories and their content recursively. The directory does not have to be empty.

40
Q

What does the ‘touch’ command do?

A

Creates an empty file if it does not exist; updates timestamps of an existing file.

41
Q

What does the ‘type’ command do?

A

Shows what type of command will be executed for a given name. Ex. ‘type rmdir’

42
Q

What does the ‘which’ command do?

A

Finds the location of an executable command. Ex. ‘which rmdir’

43
Q

What does the ‘man’ command do?

A

Displays the manual or help pages for a command. Ex. ‘man ls’

44
Q

What does the ‘env’ or ‘printenv’ command do?

A

Lists all the environment variables, such as:
HOME’: The current user’s home directory
▪ ‘ID’: The current user’s ID
▪ ‘LOGNAME’: The username of the user logged into the current session
▪ ‘OLDPWD’: The previous directory location
▪ ‘PATH’: Directories where executable commands are located
▪ ‘PS1’: The primary command prompt
▪ ‘PWD’: The present working (current) directory

45
Q

What is the ‘set’ command?

A

Without Arguments: It displays all shell variables and their values.
With Arguments: It can modify the behavior of the shell by enabling/disabling options.

46
Q

What is the ‘unset’ command?

A

Removes a specified variable.

47
Q

What is the PS1 variable?

A

It defines the primary command prompt in the shell. Ex. ‘PS1=’\u@\h:\w$ ‘
‘\u’: User name
‘\h’: Host name
‘\w’: Current directory
‘$’: Prompt symbol ($ for regular users, # for root)

48
Q

What is the PATH variable?

A

Contains a colon-separated list of directories where executable
commands are located. Directories are searched in the order listed when a command is called. Commands not in the PATH require a fully qualified path to run.

49
Q

What are environment variables and how can you set them?

A

You can set local, user-wide and system-wide environment variables used to pass dynamic values. Environment variables can be defined using either the ‘export’ or ‘set’ command.

50
Q

What does this command do: ‘export –p

A

Lists all current environment variables.

51
Q

Explain:
cmd 2> file

A

Override stderr so the output goes into the file specified.

52
Q

What are the methods for redirection in Linux?

A

▪ Standard Input (stdin or STDIN): command < input_file
▪ Standard Output (stdout or STDOUT): Redirection: command > output_file
* Standard Error (stderr or STDERR): Redirection: command 2> error_file

53
Q

Explain:
cmd &> file

A

Override both stdout and stderr so the output goes into the file specified.

54
Q

Explain:
cmd1 | cmd2

A

Override stdout from cmdl so it pipes into cmd2 as stdin.

55
Q

What is piping?

A

Routes the output of one command to another command (Symbol:|)

56
Q

What is a subcommand?

A

It uses the output of one command as an argument in another command.

57
Q

What is the cat command?

A

The concatenate command in Linux displays file contents. It reads one or multiple files and prints their content to the terminal. Cat is used to view file contents, combine files, and create new files.

58
Q

What does the ‘tail’ command do?

A

A filter command that displays the last part of text data. The default behavior will show the last 10 lines unless otherwise specified. Ex. cat /etc/passwd | tail -5 would show the last 5 lines of the passwd file.

59
Q

What is the grep command?

A

A filter command that searches files for lines containing a specific pattern.

60
Q

What is the sed command?

A

Stream EDitor. A filter command that edits file data in a non-interactive manner.

61
Q

Explain the command:
sed -i.bak ‘s/Unix/Linux/’ sample.txt

A

Replaces all instances of ‘Unix’ with ‘Linux’. Use -i to force it to write the file instead of just displaying the replaced value. Adding .bak makes a backup of the file before writing changes.

62
Q

What is the head command?

A

A filter command that displays the top part of text data. The default behavior will show the first 10 lines.

63
Q

Name four compression commands.

A

tar - merges files into one archive file (.tar).
gzip - creates a compressed file (.gz).
bzip2 - replaces the original file with a compressed file. (.bz2)
xz - compresses files (.xz).

64
Q

What are BREs?

A

Basic Regular Expressions are patterns designed to match sets of characters. These include simple patterns and metacharacters.

65
Q

What are EREs?

A

Extended Regular Expressions are patterns designed to match sets of characters. These support advanced features like ‘+’, ‘?’, and ‘{}’.

66
Q

What is /dev/null?

A

/dev/null in Linux is a null device file. This will discard anything written to it, and will return EOF on reading. This is a command-line hack that acts as a vacuum, that sucks anything thrown to it. Its size will always be zero. Since it is not an executable file, we cannot use piping using | operator to redirect to /dev/null. The only way is to use file redirections (>,&raquo_space;, or <, «).