Linux Flashcards

1
Q

sudo !!

A

Runs the previous command, with sudo.

In general, the two exclamation marks refer to the previous command you just ran.

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

cd -

A

Returns to the previous working directory

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

pushd

popd

A

pushd changes into the new directory and pushes the current working directory to a stack.

popd brings one of the items out of the stack and changes into it

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

ctrl + z

fg

A

ctrl + z sends an app to the background, effectively minimizing it.
fg brings that app out.

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

ctrl + r

A

Searches through the commands previously ran. Pressing ctrl + r again will go to the next best match.

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

history

A

Shows the command history.

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

!

A

Runs a previously ran command from history. In the Linux world, the exclamation mark is often referred to as bing.

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

HISTCONTROL=ignoreboth

A

If you assign ignoreboth to this variable, your can prevent commands from showing up in history by adding a space in the beginning,

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

HISTTIMEFORMAT=”%Y-%m-%d %T “

A

If you assign “%Y-%m-%d %T “ to this variable, commands stored in the history will have a specific time assigned to them. This could be placed in .bashrc. The space at the end is for formatting.

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

cmatrix

A

A package and a command to show a Matrix-inspired screen saver sort of thing.

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

ctrl + u

A

Clears the line.

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

ctrl + a

A

Puts the cursor all the way to the front of the line.

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

ctrl + e

A

Takes the cursor to the end of the line.

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

What is the difference between changing commands with ; and &&?

A

When you chain commands with a semicolon, all the commands will run even if one or more of them fail.
On the other hand, when you chain commands with the double ampersand, if it encounters an error it will not run subsequent commands.

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

tail -f

A

Shows the content of a file (a log file for example) and updates if anything new is added to the file.

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

truncate -s 0

A

Sets the size of a file. If 0 is provided as the first argument, it will empty the file.

16
Q

column -t

A

Creates columns out on output. For example mount | column -t.

17
Q

Basic data streams in Linux

A
Standard output (stdout) and 1 is the number designation 
Standard input (stdin) 0
Standard error (stderr) 2
18
Q

echo $?

A

Gives us the return code for the previous command.
0: success
Anything else is considered an error.

19
Q

find /etc -type f 2> /dev/null

A

The find command is obvious.

What 2> /dev/null does is, it redirects all the errors to another file and prevents them from showing up in the output.

The > symbol is the redirect operator and it will override the file.
But if you use >> the output will be added to the end of the file.

2 is the designation number for stderr. If you don’t have a number designation, the default is 1 (which is stdout).

/dev/null is essentially a black hole, anything sent there will be lost forever.

20
Q

set -x

A

Prints out all the commands running for calculating the prompt.
After running that, run exec 2>zsh.err to get stderr into a file.

21
Q

grep –files-without-match “git” ~/.oh-my-zsh/themes/*

A

Shows file names that do not match a string.

22
Q

yes

A

prints a lot of output

Effectively taking up all the resources

23
Q

ps

A

Shows the running processes as part of this particular terminal session

The response is a table with the following format:
PID: the process id
TTY: the terminal that the process is running in. If the process is running as a part of a terminal, it’s going to show here. Otherwise it’s going to show a question mark.
TIME: how much time has the process been utilizing the CPU
CMD: the actual command that is running as part of that process

24
Q

ps -aux

A

This form of options is called UNIX style options, which includes a dash at the beginning followed by any number of letters. These letters each represent an option.

25
Q

Different styles of options a command can get

A

UNIX Style: ps -aux
BSD style: ps -aux
GNU style: ps –quick-pid

26
Q

ps x

A

See all processes running from the current user
There’s a STAT column. Each letter means:

s: the process is a process leader and not a child
S: the process is in an uninterruptable sleep and is waiting for user input
R: the process is actively running
T: the process has stopped. Just like we use ctrl + z to background a process

27
Q

ps -He

A

It shows a process hierarchy and process relationships

The H option formats the CMD column to format the parent-child relationships between the processes.

The e option tells the command to show all the processes that are running on this system.

28
Q

ps -axjf

A

Columns:

PPID: parent process id
SID: session-id
PGID: parent group process id
TPGID: the terminal session-id with which the terminal is associated. If there’s no terminal, a -1 is displayed
UID: user id. 0 will be root. 1000 is the first non-system user created

29
Q

ps aux

A

The most popular form of the ps command.

Shows CPU and memory usage. The start time as well.

30
Q

du -sh

A

shows a human-readable size for the current woking dir or a specified folder

31
Q

encode a value to base 64

A

echo -n | base64

32
Q

awk ‘{}’

A

runs a command on a file.

In general, the awk command runs a script on a file

33
Q

awk ‘{print $1}’

A

prints the first filed on a file (the columns should be divided by space, as it’s the default separator in awk)

34
Q

awk ‘{print $0}’

A

Prints the entire file, since the provided value for the column number is 0 and 0 represents the entire file

35
Q

awk ‘{print $1,$3}’

A

Prints the first and third fields of a file

36
Q

awk ‘{print $NF}’

A

prints the last filed of a file.

$NF means number of fields and it kinda works like arr.length

37
Q

awk -F’:’ ‘{print}’

A

changes the delimiter or separator string that awk uses (default is space)