20250413 Flashcards

1
Q

What does file?.sh match?

A

Files named file + 1 character + .sh (e.g., file1.sh, fileA.sh)

The ? wildcard matches exactly one character.

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

What does [abc]*.csv match?

A

Files starting with a, b, or c and ending in .csv (e.g., a_data.csv, c123.csv)

The brackets [] specify a set of characters.

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

What does [!x]* match?

A

Files that do not start with x (e.g., apple, test, but not xray)

The ! inside brackets negates the character set.

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

What does ???.log match?

A

Files with exactly 3 characters before .log (e.g., app.log, xyz.log)

The ? wildcard matches exactly one character.

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

What is the option in ls command to make it recursive?

A

-R

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

What does echo {bubble,quick,merge}sort.java return?

A

bubblesort.java quicksort.java mergesort.java

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

How to return file3 file4 file5 file6 file7 file8 file9 file10 file11 in Linux ?

A

echo file{3..15}

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

$LOGNAME

A

your login name, like fashouri

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

How to return your shell’s previous directory, prior to the last cd command?

A

$OLDPWD

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

What does $PATH return?

A

Your shell search path

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

What is the definition of $USER in Linux?

A

$USER: Current effective user (from shell environment)

Represents the name of the user currently logged into the shell session.

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

What does $LOGNAME represent in Linux?

A

$LOGNAME: Original login name (from system login)

This variable reflects the user’s name as it was set at login.

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

How do $USER and $LOGNAME typically compare?

A

They’re usually the same, but can differ after sudo or su

$USER may change when switching users with sudo or su, while $LOGNAME remains constant.

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

What is an environment variable?

A

A key-value pair used by the operating system to configure behavior for processes.

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

How do you list all environment variables in Linux?

A

printenv

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

How do you view a specific environment variable, e.g., HOME?

A

echo $HOME

17
Q

How do you temporarily set an environment variable in Linux?

A

export VAR_NAME='value'

18
Q

How do you make an environment variable permanent?

A

Add export VAR_NAME='value' to ~/.bashrc or ~/.zshrc and run source ~/.bashrc or source ~/.zshrc.

19
Q

Where are permanent environment variables commonly set for Bash?

A

~/.bashrc or ~/.bash_profile

20
Q

Does export VAR_NAME=value persist after you close the terminal?

A

No, it’s only temporary for that session.

21
Q

What does the PATH environment variable do?

A

Specifies directories where executable programs are located.

22
Q

How do you remove an environment variable for the current session?

A

unset VAR_NAME

23
Q

What is the command to reload a shell configuration file after editing it?

A

source ~/.bashrc (or the appropriate file like ~/.zshrc)

24
Q

What happens when you run cat < file.txt?

A

The contents of file.txt are passed into stdin of cat

25
How do you redirect only `stderr` to a file in Linux?
Use `2>` (e.g., `command 2> error.txt`)
26
How do you combine `stdout` and `stderr` into the same file?
`command &> output.txt`
27
What does the command `ls not_a_file 2> error.txt` do?
Redirects the error message (stderr) to `error.txt`
28
How do you redirect only `stdout` to a file in Linux?
Use `>` or `1>` (e.g., `command > output.txt`)
29
How do you append both stdout and stderr to the same file in Linux?
`command &>> file.txt` — this appends both outputs to file.txt correctly.
30
How to append stderr to a file?
`command 2>> file.txt`