Basic Unix commands that you should know
This command is used to view the list of files and directories in a particular directory.
ls - Display all the files and directories inside the current path.
ls <path> - Display the files and directories inside the specified path.
ls -1 - Display all files and directories, with each entry in a separate line.
This command is used to create an empty file(s).
touch file1.txt - Create a new file named file1.txt.
touch file1.txt file2.txt file3.txt - Create three files named file1.txt, file2.txt and file3.txt.
This command is used to create a new directory.
mkdir newfolder - Create a new directory named newfolder.
mkdir newfoler2 newfolder3 - Create two directories named newfolder2 and newfolder3.
mkdir newfolder4/newfolder5 - Create a directory called newfolder5 inside the newfolder4 directory. If the parent directory in a path doesn't exist (for example, newfolder4 here), then the terminal will throw an error. In order to create parent directories too while executing mkdir, we need to use the
-p flag like
mkdir -p newfolder4/newfolder5
This command prints the path of your current working directory, starting from the root directory.
pwd - Print the current working directory path.
This command is used to navigate the file system by switching the current working directory.
cd folder2 - Switch your working directory to a folder called folder2, present inside your current working directory. You can verify the path of your new working directory by using the
cd .. - Switch your working directory to the parent directory of the current working directory.
cd - Switch your working directory to the root (or home) directory.
This command is used to delete empty directories.
rmdir newfolder - Delete a directory called newfolder. Note that this command can only delete empty directories. If you wish to delete a non-empty directory, use the
-rf flag like
rmdir -rf newfolder
This command is used to exit the terminal window (or tab).
exit - This will close the current terminal window (or tab).
This command is used to get a history of the previously run commands
history - This will give a list of all the previous commands run on the machine.
Additionally, for quickly cycling through recent commands, you can press the UP or DOWN arrow keys as well.
This command is used to clear your terminal screen of previous commands run and their outputs. Note that this only clears the screen and does not delete the command history.
clear - Clear the terminal screen.
This command is used to peek at the contents of a file in the terminal without opening it.
less <file-name> - Show the contents of the file. You can press the space bar key to proceed to next section of the contents.