Command Line Flashcards
1
Q
Remove files
A
rm file
2
Q
Remove directory
A
rmdir directoryname/path
Only removes empty directories
3
Q
change Directory
A
cd “DirectoryName/Sub”
4
Q
rename file
A
mv filename1 newfilename
put it in the same directory and it will rename the file
5
Q
list directory contents
A
ls
6
Q
remove directory with all contents
A
rm -r directoryname
7
Q
remove write-protected directory or file
A
rm directoryname -r -f
8
Q
How to find all text that contains “demo” in a file showing the line number
A
grep “demo” -n filename.txt
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
- -t sorts the listing in order of date created/modified with the most recent first
- | head -2 pipes the output of ls to limit to the first 2 items
Bonus: ls -tp | grep -v / | head -2
- -p appends the special char to directories “/”
- grep -v / inverts the grep search to items that don’t contain “/”
- head -2 only show the first to items
10
Q
What does the sudo command mean
A
sudo is short for super user do