Command Line Flashcards

1
Q

Remove files

A

rm file

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

Remove directory

A

rmdir directoryname/path

Only removes empty directories

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

change Directory

A

cd “DirectoryName/Sub”

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

rename file

A

mv filename1 newfilename

put it in the same directory and it will rename the file

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

list directory contents

A

ls

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

remove directory with all contents

A

rm -r directoryname

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

remove write-protected directory or file

A

rm directoryname -r -f

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

How to find all text that contains “demo” in a file showing the line number

A

grep “demo” -n filename.txt

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

Show the 2 most recently modified items in a directory

*Bonus to only show files and exclude directories

A

ls -t | head -2

  1. -t sorts the listing in order of date created/modified with the most recent first
  2. | head -2 pipes the output of ls to limit to the first 2 items

Bonus: ls -tp | grep -v / | head -2

  1. -p appends the special char to directories “/”
  2. grep -v / inverts the grep search to items that don’t contain “/”
  3. head -2 only show the first to items
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the sudo command mean

A

sudo is short for super user do

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