Terminal 101 Flashcards
learn basic terminal commands
man [command]
displays manual of specific commands
[command] –h
displays a short description of the command
pwd
prints working directory
cd
Changes directory.
[cd - ] to navigate back to the previous working directory
[cd, cd ~] to navigate to the home directory
[cd / ] to navigate to the root directory
[cd .. ] to navigate back of one directory
ls
Lists contents of current w.d
[-l] lists contents in a table format
[-t] lists contents based on the timestamp
*
Allows to select file or directory names based on patterns
[] all files
[b] all files starting with b
[b.txt] all files starting with b and ending with .txt
[[abc]] all files starting with a b or c
?
Allows for one char to have any value
cp
copies files or directories
[cp file1 file2]creates file2 and copies contents of file1 into it
[cp file1 file2 dir1] copies file1/2 into dir1
[cp dir1/* dir2] copies all files from dir1 to dir 2
[cp -r dir1/* dir2] copies all files and directories of dir1 into dir2
mv
Moves files and directories
[mv file1 file2]
- renames file1 to file2
- moves file1 to file2 (which is overwritten if already existing)
[mv file1 file2 dir1] moves file1/2 into dir1 (must already exist)
[mv dir1 dir2] moves all files from dir1 to dir 2 (dir1 is erased)
rm
Removes files or directories
[rm file1]
[rm -r dir1]
mkdir [directory_name]
creates directory in current w.d
touch [file_name]
Updates timestamp of the file
[touch -a file1] updates last access timestamp
[touch -m file1] updates last modified timestamp
-i & -n
[-i] adds a prompt to confirm the action before modifying a file
[-n] defines that no files can be overwritten
cat
Concatenates files
[cat file1] shows the contents of file1
[cat > file1] will create file1 + add contents through terminal prompt
[cat -n file1] prints file contents with line numbers
[cat file1 > file2] creates or overwrites file2 with contents of file1
[cat file1»_space; file2] appends contents of file1 to file2
[cat file1 file2 | sort > file4] sorts contents of file1 and file2 and appends to file4
uniq
removes duplicate files or contents