Command Line / Shell Flashcards

1
Q

Terminal (or Terminal Emulator)

A

A program that accepts text based commands and can render text on the screen

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

Shells

A

Interpret the commands you type and execute them. Often referred to as “REPL”s:

Read - Read the commands you type

Evaluate - Evaluate those commands, usually by running other programs on your computer

Print - Print the output of those commands

Loop - Give you a new prompt to type another command and repeat

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

Command to print something

A

echo

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

Prefix when you want to use a variable in a terminal command

A

$

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

Command to see the commands you’ve typed in the past

A

history

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

Keys to use to quickly cycle through your command history

A

Up and Down arrows

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

Command to clear terminal screen

A

clear

OR

ctrl + l

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

Command to see the filepath of your current working directory

A

pwd

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

Command to see the contents of your current working directory or a downstream directory

A

ls

ls filepath

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

Command to see the contents of your current working directory (including hidden files)

A

ls -a

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

Command to move into (or down) a directory/filepath

A

cd filepath

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

Command to move back (or up) directories

A

cd .. (one directory)
cd ../.. (two directories and so on)

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

Command to move to home directory

A

cd ~

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

Absolute vs Relative Path

A

Absolute - Filepath that starts at the root of the filesystem

Relative - Filepath that takes into account your current directory

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

Command to view the contents of a file or files combined

A

cat filename (single file)

cat filename1 filename2 (multiple files)

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

Command prints the first or last n lines of a file (5 lines in this example)

A

head/tail -n 5 filename

17
Q

Command to view the contents of a file one page (or line) at a time

A

less filename

less -N filename (w/ line numbers)

Use spacebar to scroll down a page and “b” to scroll back up

18
Q

Key to press to exit out of the currently running process

A

“q”

19
Q

Command to create a new directory inside a current directory

A

mkdir directory_name

20
Q

Command to change filename

A

mv filename new_filename

21
Q

Command to move file

A

mv source_filepath destination_filepath

22
Q

Command to delete a file or empty directory

A

rm filename
rm -r directory_name

23
Q

Command to copy a file or directory from one location to another

A

cp filename destination_filepath/

cp -R current_directory new_directory

24
Q

Command to search for text in files

A

grep “example” filename (single file)

grep “example” filename1 filename2 (multiple files and so on)

25
Q

Command to search for text in current directory and all subdirectories

A

grep -r “example” .

26
Q

Command to find files and directories by name

A

find directory_path -name filename

” * “ character is a wildcard that matches anything, if you’re trying to find filenames that contain a specific word

27
Q

Command to see which user is logged in

A

whoami

28
Q

Command to print out the permissions of each file and directory in long format

A

ls -l

29
Q

How are permissions of an individual file or directory visually represented?

A

10 character string

-: Regular file -rwxrwxrwx
d: Directory drwxrwxrwx

First 3 characters are owner permissions
Middle 3 characters are group
Last 3 characters are public

30
Q

Command to change the permissions of a file or directory

A

chmod

chmod -R u=rwx,g=rwx,o=rwx DIRECTORY/FILENAME

31
Q

Shell Scripts

A

Text files that contain shell commands

End with .sh

32
Q

Command to change the owner of a file or directory and it requires root privileges

A

sudo chown -R root filename/directory