When working in Linux machines, there are a few important commands to know when making and editing directories/files from the terminal.

Directory Commands

Command What it does Example
mkdir Creates a new directory. If path is not specified, new directory is created within working directory.
$ mkdir /path/to/Test 
# creates a directory named 'Test' along the specified path
rm -rf Deletes the target directory, including all files/directories within the directory.
$ rm -rf /path/to/Test
# deletes the 'Test' directory and its contents
cd Changes the current working directory. By default, /home/username/ is the working directory when opening a terminal or using the cd command without a path.
$ cd /path/to/Test
# changes the working directory to 'Test'
ls Prints out the contents, including files and directories, within a parent directory. If no path is specified, ls prints the contents of the working directory.
$ ls /path/to/Test
# prints the contents of 'Test'
cp -R Copies the contents of a source directory to a target directory.
$ cp -R /path/to/Source /path/to/Destination
# copies the contents of 'Source' to 'Destination'
mv Renames an existing directory.
$ mv Source Target
# renames a directory 'Source' to 'Target'
grep -ir Recursively searches files in a directory for a pattern.
$ grep -ir "test"
# displays all occurrences of the string "test" in the working directory

 

File Commands

Command What it does Example
touch Creates a new file. Can be of any type. If path is not specified, new directory is created within working directory.
$ touch test.txt
# creates a .txt file named 'test' in the working directory
vi Opens a specified file in the default UNIX text editor. If the file name does not exist, creates a file and opens in text editor. Basic vi commands can be found at the bottom of the article.
$ vi test.txt
# opens test.txt in a text editor
rm Deletes the target file.
$ rm test.txt
# deletes the 'test' file from the working directory
cp Copies contents of a file to another file or directory.
$ cp test.txt /path/to/Destination
# creates a copy of test.txt in the 'Destination' directory
mv Renames a file. If a directory is the destination, moves file to the directory.
$ mv test.txt /path/to/Target
# moves test.txt from current directory to 'Target'
cat Reads data from a file and prints the content. Can be used on multiple files
$ cat test.txt
# displays the contests of the 'test' file
grep Searches the specified file for a specific pattern. Useful for finding specific occurrences in files.
$ grep "test" test.txt
# displays all occurrences of the string "test" in test.txt
less Displays a file from the bottom up. Can scroll up through file contents.
$ less test.txt
# displays contents of test.txt, allows user to scroll up
more Displays file from top down. Can scroll down through file contents.
$ more test.txt
# displays contents of test.txt, allows user to scroll down

 

Other Useful Commands

Command What it does Example
clear Clears the terminal.
$ clear
screen Launches separate terminal windows within the same terminal manager. Useful for running processes that will take a large amount of time. Screen commands can be found at this: More Screen Commands
$ screen 
history Outputs a list of all past commands in the current terminal session
$ history

 

Vi Command Cheat Sheet