The pwd command stands for "print working directory" and will return your location in the file system, such as /usr/share or /home/matthew. This is useful if you forget where you are.
When used alone, the ls command lists all of the files and directories contained in your current directory. You can also use ls to list the contents of a directory you have not navigated to by adding the directory location after the command, like this: ls etc/python.
The cd command changes your working directory to a directory you specify. For example, cd /var/log takes you to the log directory that is contained in the var directory.
The touch command creates an empty file using the filename you specify. Create a file now and then use cd to confirm that it was created in your current directory: touch examplefile.
The rm command removes a file. To delete the file you just created, enter: rm examplefile.
The mkdir command creates a directory. Create a directory now and then use cd to confirm that it was created in your current directory: mkdir exampledirectory.
The rmdir command removes a directory. To delete the directory you just created, enter: rmdir exampledirectory.
The mv command moves a file or a directory you specify to the location you specify. It is also used to rename files and directories. You can do both at the same time, if you like. For example, let's move a file named sample from our current working directory into an existing subdirectory called stuff while changing the name of the file to example: mv sample stuff/example.
The cp command copies a file or directory you specify to the location and new filename you specify. Let's use the same example: cp sample stuff/example. The difference between what happens here and what happened with mv is that with cp, the original file remains.
The man command displays the manual page for the command you specify. Every command I have mentioned in this short article can do much more than you have learned thus far. In fact, we have just scratched the surface. Most commands have options, called switches, available to modify the default behavior. For example, when you enter man ls and view the man page for that command, you will learn about incredibly useful options like ls -al which will list not only file and directory names, but also very useful metadata about each file and directory.
Subscribe to get latest updates