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 |
rm -rf | Deletes the target directory, including all files/directories within the directory. |
$ rm -rf /path/to/Test |
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 |
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 |
cp -R | Copies the contents of a source directory to a target directory. |
$ cp -R /path/to/Source /path/to/Destination |
mv | Renames an existing directory. |
$ mv Source Target |
grep -ir | Recursively searches files in a directory for a pattern. |
$ grep -ir "test" |
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 |
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 |
rm | Deletes the target file. |
$ rm test.txt |
cp | Copies contents of a file to another file or directory. |
$ cp test.txt /path/to/Destination |
mv | Renames a file. If a directory is the destination, moves file to the directory. |
$ mv test.txt /path/to/Target |
cat | Reads data from a file and prints the content. Can be used on multiple files |
$ cat test.txt |
grep | Searches the specified file for a specific pattern. Useful for finding specific occurrences in files. |
$ grep "test" test.txt |
less | Displays a file from the bottom up. Can scroll up through file contents. |
$ less test.txt |
more | Displays file from top down. Can scroll down through file contents. |
$ more test.txt |
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