This is a compilation of commands you can use in terminal to help you navigate & manipulate files and directories. Some terminology to know beforehand:
- Options change the behaviour of a command. It will still do what the command does on its own, but in a slightly different way. There is always a space between the command and the option. The option will always begin with a -.
- Arguments is a value you pass to a command. You will have spaces between the command and arguments.
- Directory can be thought of as another word for folder. The working directory is the folder you are currently in.
Command | Options1 | Arguments | Description | Examples |
---|---|---|---|---|
pwd |
none | Shows the current working directory | ||
ls |
none | Lists files and directories in the current working directory | ||
ls |
-a |
Also lists hidden content (those beginning with .) | ||
ls |
-l |
Lists the long format2 of the contents of a directory | ||
ls |
-t |
Lists contents by date modified | ||
cd |
directoryname/ | Changes directory to the selected directory | ||
cd |
.. |
Changes to parent directory | ||
mkdir |
directoryname | Makes new directory with given name | ||
touch |
filename.txt | Makes new file with given name and extension | ||
cp |
content to copy | Copies the selected content. Can also include the directory to copy it to with a space after the content to be copied | ||
cp |
* directoryname/ | Copies all files in working directory to selected directory | ||
cp |
m*.txt directoryname/ | Copies files that begin with m and end with .txt to the selected directory | ||
mv |
filename.txt directoryname/ | Moves the selected file(s) to the selected directory | ||
mv |
filename1.txt filename2.txt | Renames the filename1 (which is a file that is you already have) to the new filename2.txt | ||
rm |
filename.txt | Removes or deletes the selected file | ||
rm |
-r |
directoryname/ | removes the selected directory, and all its child content |
- Options can also be combined. For example, you can use
-a
,-l
,-t
all together withls
as:ls -alt
. This willa
list all files (including hidden files),l
in long format, andt
sorted by date modified. - Long Format includes seven columns separated by spaces. The meaning of each column, in order is:
- Access rights
- Number of child directories and files
- The file owner eg. katbow
- The name of the group that owns the file
- The size of the file in bytes
- Date & time of last modification
- File or directory name