Working at the Command Line Flashcards

1
Q

[cmd] pwd

A

print working directory - outputs the current directory that you’re in

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

[cmd] tty

A

prints the file name (because everything in linux is a file) of the terminal connected to the standard input. IE your current terminal.
Physical Terminal = tty1
Pusdo Terminal = pts/0

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

[cmd] who

A

Tells you who is logged onto the system.

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

[cmd] exit

A

logs you out of the current terminal.

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

[cmd] ip a s

(aka ip addr show)

A

prints all the current network interfaces and their IP information.

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

~

A

indicates the home directory

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

[cmd] ls

A

lists (non-hidden) files and directories in your current working dir.

NOTE: ls is aliased by default to ‘ls –color=auto”.

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

[cmd] ls -a

A

lists all files including hidden files.

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

[cmd] ls -F

A

shows the file type in the printed output. So dir files end in a / and symbolic links end in an @ and executables end in * — useful if your terminal doesnt support colors

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

/etc

A

this dir contains all the system/service configuration files.

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

configuration file

A

local file used to control the operation of a program but is static and cannot be an executable binary.

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

[cmd] ls -l

A

gives us a long listing of file types with metadata, which includes file type - permissions block - number of hard links - owner - group owner - size - date modified - name

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

[cmd] ls -r

A

reverses the order of the printed output

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

[cmd] ls -lrt

A

prints the long version, and reverses it based on time. Prints files but reversed based on time, so the oldest file will be listed first. (you can replace t with o to sort by owner)

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

[cmd] ls -h

A

puts the file size in a human readable format

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

[cmd] ls -d

A

lists the dir itself instead of the contents of the directory.

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

[cmd] $(cmd)

ie: ls -l $(tty)

A

anytime you put $() the command line will run the cmd in ()s first and then the output of that is used as the input of the other cmd.

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

[cmd] lsblk

A

lists the block devices (partitions) on the system. (which because everything is a file, these exist in the dev dir also)

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

[cmd] * at end

ie: ls -l /dev/sda*

A

wildcard character that represents 0 or more characters. ie: lists anything that follows including zero characters. so the printed result will be /sda, /sda1, and /sda2

20
Q

[cmd] ? at the end

A

same as * wildcard but only looks at a single character. so /sda and /sda20 wouldn’t be returned.

21
Q

[cmd] [12] at the end

ie: ls -l /dev/sda[12]

A

this is a wildcard array, so in the case of the example it would be looking for sda1 and sda2

22
Q

/dev directory

A

this is where the device files are stored.

23
Q

linux file types

A
- : regular file
d : directory
c : character device file (ie tty)
b : block device (ie sda)
s : local socket
p : named pipe
l : symbolic link
24
Q

[cmd] cat

A

The cat command is used for:

  • Display text file on screen
  • Create a new text file
  • Read text file
  • Modifying file
  • File concatenation
25
Q

[cmd] which

A

this command locates executables in the system. So you pass command names as arguments and it will return that commands file path.

26
Q

[cmd] cp

A

copies a file. *note must have read permissions on the file you want to copy and write permissions on the dir you are trying to copy to. The first argument is the file you’re copying the second is the location and name of the file you are copying to.

27
Q

ctrl+l

A

clears the screen

28
Q

[cmd] cp -i

A

the i option to the cp command takes you into interactive mode and warns you if you are about to overwrite an existing file

29
Q

[cmd] mv

A

allows you to move a file to a new location or rename a file. Works just like cp but moves instead of copies

30
Q

[cmd] rm

A

removes the file defined in the argument. Can also be used in interactive mode with -i option like cp and mv

31
Q

[cmd] mkdir

A

makes a new directory and takes the directory name and path as an argument. *NOTE all directories must already exist in the provided path argument or you will get an error that the dir cannot be created. (note: listing multiple arguments will create multiple dirs at a time)

32
Q

[cmd] mkdir -p

A

the -p option creates the parent directory even if it doesn’t already exist so that you will not get the “dir cannot be created” error that you would with just mkdir

33
Q

[cmd] rmdir

A

removes a dir. *NOTE will get a “failed to remove dir” error if the dir is not empty.

34
Q

[cmd] !rm

A

runs the last command that begins with the characters after the ! so in this case it will try to run your last rm cmd.

35
Q

[cmd] rm -rf

A

The -r option deletes recursively, and the f is forcibly, so unlike just a rmdir this will delete a dir and its contents.

36
Q

[cmd] touch

A

touch works the same way as mkdir but creates a file provided in the arg instead of a dir.

37
Q

[cmd] touch file{1..5}

A

the {1..5} will create 5 files named file1 - file 5.

38
Q

[cmd] cp -R

A

the -R option for the cp command means regression, so it will allow you to copy a dir and all its files to another dir.

39
Q

[cmd] tree

A

lists the file tree with all subfiles and sub directories of the dir provided in the arg. NOTE: tree is a separate yum package that may need to be installed.

40
Q

[cmd] mkdir -m

A

the -m option allows you to set permission on a dir when you create it.

41
Q

/etc/.

A

the . file in a dir is an actual file because everything in linux is a file, but it links back to the parent dir. So whenever you create a dir a dotfile linking to that dir is always created with it. The minimum hardlink count for a dir will always be 2, because you have the dir itself and the dotfile linking to it’s one set of metadata. (NOTE: Even though this is a file its of dir type because everything even dirs are a file in linux. )

42
Q

/etc/..

A

there will also be a file called .. in every dir that links to the metadata of the parent dir. So every time you create a sub dir in a dir the hardlink count will increase by one because of the .. file that is created that links back to it,. (NOTE: Even though this is a file its of dir type because everything even dirs are a file in linux. )

43
Q

[cmd] ls -i

A

the i option on the ls command shows you the metadata id (i node) of that file. This is what any link file like . or .. links to.

44
Q

[cmd] ln

A

makes a hard link from one file to another that are provided as arguments. Both files will show a hard link count of 2 and the i node number will be the same. Which means that these two files are actually the exact same file but they do not show as links in the file type (ie they aren’t type l) they are both individual regular files of type -

45
Q

[cmd] ln -s

A

the s option creates a symbolic link… it kinda works the same as a hard link but creates a separate file with type l and separate i node number and doesn’t affect the hard link count number.

46
Q

symlink vs hardlink

A

the advantage to symbolic links is that you can cross filesystem boundaries so for example a hard link cant be made from the boot dir to the home dir (you’d get a “invalid cross-device link” error, but a symbolic link can be because there is no dependance on the file system (ie you’re not sharing that same inode metadata that was generated on two different file systems).