Relationship of Command: Getting Comfortable with Command Line Interface
The CLI or Command Line Interface is a vital tool in a programmers kit. In an age where most everything we work with is a Graphical User Interface (GUI), it can be easy to overlook CLI commands. The CLI uses text to process commands to a computer program. It might not be the most exciting way, but it is integral in quickly and efficiently getting a variety of things done. This article will illustrate some basic and must-know commands for any programmer. Let’s open up a terminal and take a look.
mkdir — This command is short for Make Directory. This is a useful way to create a folder on your Desktop or in any location you want. If no location is given it will create one in your current working directory.
ls — This is the List command. It will show all files in the current working directory if not directly specified. There are several arguments that ls will accept. ls -a will list all contents of a file, even hidden ones. ls -l will list all contents in long format. ls -t will generate a list based on the most recently modified files.
pwd — This command prints the name of your working directory.
cd — This is the Change Directory Command. This is used to navigate through the file tree. There are a couple arguments you can use with this command. You can specify the file name after cd to go to that exact file. You can also use cd .. to navigate up to the parent of the directory you are currently in.
touch — This command creates a file in your current working directory. (Note that mkdir creates a folder not a file).
clear — This command will clear the terminal.
tab — Pressing the tab key will autocomplete the current line you are typing if it is matching a file or folder in your current directory (this can be a real time saver).
up and down arrow — These keys will go through previously entered commands (also will save you a mountain of time).
GREP stands for “global regular expression print”
grep — This command will search for folders or files containing the specified text (it is case sensitive so be specific).
grep -i — This will search for the file or folder name but turn off case-sensitivity.
grep -R — This command searches all files in a directory and returns the files that match the query.
grep -IR — Searches all files and folders in a directory on returns only filenames with matched results.
Other Useful Commands
cp — This command is used to copy files or directories. Follow the cp command with the name of the file you want to copy then the name of the directory you want to copy it into.
uniq — This command takes a filename or standard input, printing out every line that is not duplicated (remember these are exact duplicates).
sort — This command takes a filename or standard input and prints it alphabetically.
rm — Stands for Remove. This command deletes a file.
rm -r — This command deletes a parent directory and all its files (use with caution).
mv — This command is used to move a file into another directory. Use mv followed by the name of the file, followed by the name of the directory you want to move the file into (make sure to follow the new directory name with a /).
env — This command returns a list of the environment variables of the current user.
Master the Command
These are just a few of the basic CLI commands. They are enough to get you comfortable with how to navigate through your directories and accomplish essential tasks. I encourage you to practice these in order to move on to some of the more advanced commands and concepts. Practice makes perfect.