Basic guide on terminal commands
I remember when I first started using the command line, it felt like smoke and mirrors as I didn’t know where I was or what to do. It all seemed very confusing at the beginning but once I got the grip of it I couldn’t go back.
Here is a quick guide on simple terminal commands that can be handy when using a unix server or the terminal on your local machine.
Please note that this is just a quick guide!
Basic file handling on the terminal
- Returns a list of the files and folders on the current folder.
- Moves a file or renames it if the same folder is specified.
If you want to rename a file from the terminal called
foo.phpyou can rename it by moving it to the same folder using a different name
mv foo.php bar.php
This will rename the file
If you want to move a file to a different folder using the terminal you can just specify the folder on the second argument.
mv foo.php lib/foo.php
This will move the file
foo.phpto the lib folder.
- Copies a file from the terminal.
cp foo.php bar.php
If you would list (
ls) your files on the current folder you will find both
bar.phpwill be an exact copy of
- Deletes a file.
This will permanently delete a file. You can add -rf if you don’t want to get asked if you are sure.
IMPORTANT: Be careful when using this as any changes cannot be undone.
- Changes the read, write and execute permissions of a file or folder. You can find these on your FTP client under the file permissions information and it might look something like this:
chmod 664 foo.php
This will make the file writable only by it’s owner and read only for everyone else.
I could extend a lot more on the
chmodcommand but I will leave it for another time.
Basic Folder and Directory Terminal Commands
- Makes a new directory (folder).
This will create a new folder called foo on the current directory.
- Tells you the where you are at this specific point.
- On the previous example you can see the
cdcommand. This command means change directory, it is the way to navigate folders.
If you want to go to the home folder from the terminal you can just type:
You can also specify the full path of the folder where you want to go.
This will take you to the folder
viewsinside the folder
appand so on and so forth.
If you want to Go up a folder you can type:
This means change directory to the parent folder.
- This command opens the file specified with the default application in charge of opening the current file type.
At this point Sublime Text is my default text editor for
Typing this into the terminal will fire up Sublime Text and open
This also works with folders.
This will open the home directory.
NOTE: This only works on a local machine. There is not a current way of opening remote files this way.
This was a very short guide on some of the most basic unix commands that can be used on the terminal on a local machine or via ssh on a remote one.
Now days I cannot think of working without the terminal. It made my life so much easier as my workflow streamlined.
It really is easier that it looks. Why don’t you give it a go?