Getting around in Command Line: Beginners Guide

Luke Wickens
4 min readNov 15, 2020

--

I think we can all agree, on the face of it, the command line looks intimidating. When you think of the command line you’re probably imagining a Holywood film where someone is frantically typing away on the keyboard and the screen moves faster than Formula One car. Or, dare I say it, you think of The Matrix with all the binary code glowing a virulent shade of lime green. However, it's time to brush aside those preconceptions and shine a light on what is one of the most useful tools in the software developer arsenal.

Photo by Markus Spiske on Unsplash

Command: pwd

pwd’ or print working directory. This basically shows you the current directory or where you are on the map that is your computer system.

Command: ls

‘ls’ or list. This command will show you the current files and folders at your current location.

ls -a’ : (list all) Shows all files and folders, including hidden ones in your current directory. These are usually preceded by a period (.).

ls -l’ : (list long) Shows you more information about each file and folder (such as what permissions the file has).

Command: cd

cd’ stands for change directories. This is the main tool for moving around your computer system in the command line.

cd [name]’: Go to the specified directory [name].

cd ..’ : Go one directory up (back to the previous directory).

cd /’ : Go to the root directory. The root directory is the first or top-most directory in a hierarchy. If you think of a tree, the root directory is the trunk where all branches originate from.

cd ~’ : Go to the user directory. The user directory is the primary location for you to store and manage your personal files.

Command: clear

As Ronseal would say, “it does exactly what it says on the tin”. This command will clear any text from your command line console.

Command: open (Mac)/ start (Windows)/ xdg-open (Ubuntu)

Pretty straight forward. This command will open the file that you specify after the open command.

Command: mkdir

‘mkdir’ or make directory will create a new folder/directory in the location that you are currently in. You specify the name after the command and that tells the command line what to call the new directory.

Command: touch

The ‘touch’ command is used to create files. ‘touch’ is followed by the name and extension of the file you want to create.

Examples:

touch new_file.txt’ Creates a new text file called new_file.

touch directory.rb’ : Creates a new ruby file called directory.

Command: cat

If you want to read a file from the terminal, ‘cat’ is used to display the contents of the file. ‘cat’ is followed by the name of the file (including extension) that you wish to view.

Command: mv

The ‘mv’ or move command is quite versatile, in that it can do more than just what it appears to do on the surface. Not only can it move a file from one directory to another, but it can also rename that file as well.

‘mv file1.txt file2.txt’ : This renames file1.txt to file2.txt. This works with all other file types as well. The first file named is the one that we are going to perform the operation on, the second is what we wish it to become.

mv file1.txt new_folder/file1.txt’ : This moves file1.txt into the new_folder directory. The new_folder directory, in this instance, is contained within the current directory (or ‘pwd’) of the user. The file can also be renamed at this point as well (e.g. ‘mv file1.txt new_folder/new_file_name.txt’).

Command: cp

cp’ or copy allows the user to copy a file from one location to another location or to the same location but with a new name. The ‘cp’ command is followed by the name of the file you want to move and then the new location, including a new name if desired. This is similar to the ‘mv’ command.

Command: rm

The ‘rm’ or remove command allows the user to delete/remove a specified file. This will not however work on directories that have files/folder in. In order to delete those, you must use ‘rm -R’. It is always a good idea when removing things from the system to use ‘rm -i’ which stands for “remove interactive”. This will prompt the user to confirm they wish the delete the specified file. This adds an extra layer of protection from deleting something incorrectly.

Command: sudo

Do you remember before in the ‘ls -l’ command description when I mentioned file permissions? Well, on some files/directories, you may not have permission to modify or change the folder in the way you wish to. This is due to the r/w/x permissions (read/write/execute) limiting the user based on the constraint applied. However, all is not lost! You can become a SuperUser and leave the pesky problem of permissions behind. By using the ‘sudo’ command before any other command activates the SuperUser mode. You will have to input an administrator password in order to do this. Don’t worry if it looks like nothing is happening when you type the password in, it is.

Photo by Etienne Girardet on Unsplash

…And that's it!

These are the basic commands that you will need in order to navigate the command line effectively. Have a play around creating, deleting, renaming, and moving files around and you’ll be able to see how powerful a tool the command line is.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Luke Wickens
Luke Wickens

Written by Luke Wickens

Solidity Full Stack Dev. Cat Lover. Eater of Cheese. https://github.com/lbw33

No responses yet

Write a response