At first, everybody hated the command line. After years of experience, it became an acquired taste.
But why do developers like it? Well, the list is infinite, but here are a few important reasons:
The console is really simple: it’s a black screen that’s always expecting a command. After you type the desired command and press the
return key, the computer executes it and shows some feedback with the resulting output on the screen. A simple Question <> Answer interface.
But what is a command?
It is something like "print," or "show," or "delete," but abbreviated. For example, if you want to tell the console to list all of the files in a particular directory, you have to use the
ls command like this:
ls -l /path/to/directory
All commands have three parts: the utility, the flags, and the arguments. The utility always comes first. The other two parts have different rules, and, depending on which command you are using, you may not have to use any flags or arguments at all.
In this particular case, we use the
-l "flag" to specify that we want a "long" version of the list of files (with more details).
The last thing we have to add is the "argument." In this case, the "argument" will be the path of the directory from which we want to list the files from.
Your computer has files, directories and applications. Your command line is able to deal with the three of them. Use commands to move within the files and directories (like the
cd command). Every application that you install comes with a set of commands that become available at the moment you install the app (like the GIT command).
There are 4 important things to notice here:
.to refer to all the files and folders in the hierarchy.
..to refer to the parent directory.
/to navigate further down in the hierarchy directories.
Here is a small selection of the most used commands by a software developer.
The list command
the ls command is used for listing all the files and directories form the current position.
ls -l ./applications #show the files and folder inside "appications" #the -l is for asking a more detailed output information on the files.
The change directory command
Navigate between two different directories.
The move command?
Move a file to another folder or directory. Just like dragging a file located on a PC desktop to a folder stored within the "Documents" folder.
mv /path/to/file.txt /math/to/destination/file.txt
The remove command
This deletes files (not directories).
rm file1.txt file2.txt file3.txt file4.txt #removes all the four files rm -r dbstore/ #delete all the files and sub-directories recursively within the "dbstore" directory.
The make directory command
Makes a new directory. Just like making a new directory within a PC or Mac desktop environment, the mkdir command makes new directories in a Linux environment.
mkdir newdirectoryname #create newdirectoryname in the current directory. mkdir path/of/new/newdirectoryname #create newdirectoryname inside /path/of/new/
The remove directory command
It deletes a directory (not files).
rmdir mydirectory #remove mydirectory if its in the current directory. rmdir path/of/targetdirectory/mydirectory #remove mydirectory from "targetdirectory"
☝It will only remove empty directories, to empty all directory files use the rm command. Pro-tip: you can use
rm . to delete all of the files inside a directory simultaneously; use with caution.
The Copy File command
Don’t confuse this command with the clipboard copy functionality – it has nothing to do with it.
cp will copy an entire file and create a new one with whatever name you decide it should have.
cp path/to/file.ext path/to/new/file.ext #copy file.ext and create a new file.ext with the same content.
The find command
Finds a file in the given directory and with the given specifications.
find / -name game #find all files containing the exact name "game" that are inside the root folder. find . -name *.mp3 #find all files containing the extension "mp3" within the current directory and its parent.
These will help you save time and make less mistakes when typing:
uparrow and it will show you each command, one by one.
~key like this: cd ~
clearcommand to "clean" the current console (it is just a scroll, but a very useful one).
This is one of the things that you cannot avoid doing in the terminal. As a developer, you will have to edit files in the terminal more often than you think. That’s why you’d better be prepared to use either the VI Application or the Nano Application. We will talk about Nano and its commands (yes, here the text editor opens inside the command line and runs using commands).
It’s not really a command, actually the name of "Nano" is a text editor application.
When working with the command line, sometimes you will have to open a file to review it and even change it. For that, we use the "nano" command. Nano basically opens a text editor within the command line.
nano path/to/the/textfile.txt #open a text editor to start editing the content of textfile.txt #if textfile.txt does not exists it will create it!
When nano opens, it will show a top bar with the current version of the nano application; the name of the file being edited; and, a status telling you if the files were modified or not.
At the bottom, you will see the most often used commands to use nano, such as: quit, where is, help, etc.
☝This website has a ton of great mini-challenges to help you practice the command line: