Learning the command line is fun and quite challenging at the same time. You have to memorize a lot of commands to be able to use it effectively. But here are some of the most basic and most widely used commands that you should learn if you want to use a UNIX like operating system like linux or mac os.
ls command is used to list all of the files and folders on a certain directory.
ls- Will print all the files in the current directory.
ls ~- Will print all the files and folders in
cd command or the change directory command. This command will let you navigate from folder to folder within your system.
cd <destination path>
cd ~- Will bring you to the
cd ../- Will bring one step outside your present working directory. Say you are in
~/john, then this command will bring you to
~/. You can use trailing
../to go outside of a directory multiple times. E.g.
The make directory or
mkdir is just "Create a new folder" command. It's that simple.
mkdir <folder name>
mkdir not-porn- Will create a folder called not-porn.
mkdir ~/Documents/school-stuff/home-work/not-porn- You can also create a folder in a certain path. In this example,
mkdirwill create a not-porn folder in
touch command is a quick way of creating an empty file.
touch my-body.html- This will create a my-body.html file in your present working directory.
touch ~/Documents/codes/my-body.htmlSame with
mkdir, you can also specify the path or location of your file.
If you can create of course could also remove files and files from your terminal. The
rm command will help you do that.
rm <path|directory name|file name>
rm memes-link-collection.txt- Will delete the file
rm ~/Documents/codes/my-body.html- Removes the file my-body.html from
rm -r folder-name- Deleting a folder is a little different from deleting a file. If you want to delete a folder you should pass the flag/argument
-rwhich means recursive. This is required to delete the folder and everything inside it.
Some folders or files are protected by strict permissions, because maybe those files and folders are system owned. To understand how UNIX permission works, you can check this article.
The copy command.
cp <origin> <destination>
cp carl-homework.txt john-homework.txt- You just copied Carl's homework as john-homework.txt.
cp ~/Documents/cats/cat-1.jpg ~/Documents/cats-backup- Here we create a copy of cats-1.jpg to ~/Documents/cats-backup.
cp -r ~/Documents/cats ~/Documents/new-folder- Like the removing of folder above, you must also use the
-rto copy a folder and everything inside it to a new location. This sample will copy the cats folder from ~/Documents to ~/Documents/new-folder
The move files/folder command. This will... move a file to a new destination.
mv <origin> <destination>
mv ~/Documents/cats/dog.png ~/Documents/dogs- This will move the dog.png from the
~/Documents/catsfolder to where it belongs. The
mv ~/Documents/llama ~/Documents/dogs- This will move the llama folder inside the dogs folder. (Where it belongs :D)
mv command can also be used to rename a folder.
mv ~/Documents/porn ~/Documents/homework- Here you just renamed porn to homework. Nice.
The `clear` will just clear the terminal.
See? It's cleared now.
Congrats! You can now use the basic terminal commands.