By Des Nnochiri

 

Even if the Linux distribution that you’re using has a GUI (Graphical User Interface), it’s likely that the bulk of your work will involve shell commands, entered via a command line terminal. Basic shell programming, application development, and the more complex aspects of network monitoring and administration will all proceed from the foundation of Linux shell commands, which are used to perform a wide range of functions.

 

In this article, we’ve assembled a core set of the essential commands that you’re likely to need in the Linux environment.

 

The Linux Command Line Interface (CLI)

 

To access the Linux shell, you must first open the terminal before entering the command line interface (CLI).

 

If you’re working in Ubuntu, press Ctrl+Alt+T or press Alt+F2, type in gnome-terminal, and press Enter. In the Raspberry Pi environment, type in lxterminal.

 

Note that the command line environments of all Linux operating systems function in lower case. This stems from the core principle of making Linux as easy to use as possible. File, folder, and directory names created by a user may contain upper case (capital) letters, but the underlying system itself responds to lower case command line syntax.

 

This restriction has consequences if you’re in the habit of using mixed upper and lower case lettering in file names. Unless you specify the qualifier -i (the “negate case lock” parameter), file names containing capital letters won’t show up in any file or directory listings that you call for. For example, the command:

 

locate sunsetthunder.mp3

 

won’t locate the file SunsetThunder.mp3 unless you use -i:

 

locate -i sunsetthunder.mp3

 

 

Consulting the Manual (man)

 

 

(Image source: Maker Pro)

 

 

Described by some as “the meta command of the Linux CLI”, the manual (or man) command displays information about the Linux command that you specify, essentially displaying a reference manual for that chosen command. For example, entering:

 

man cd

 

will display information concerning the cd command described below.

 

The List Command

 

Used for viewing files, folders, and directories, the list command (ls) will display all of the major directories filed under a given file system. E.g.:

 

 

(Image source: Geek University)

 

will return all the folders stored in the overall applications folder. If no directory has been specified, the command will display the contents of the working directory.

 

Changing Directory (cd)

 

The cd command allows the user to switch or change between different file directories. The screenshot below illustrates an example of using this syntax in Ubuntu.

 

 

(Image source: Geek University)

 

To change the current working directory, you have to specify the path of the directory that you would like to access.

 

Creating a New Directory (mkdir)

 

The “make directory” or mkdir command does exactly what it says. To create a new directory, you must specify its name. If you don’t specify a path, the new directory will be created inside the working directory. The screenshot below illustrates the use of the mkdir command in conjunction with the list command (ls).

 

 

(Image source: Geek University)

 

Creating Files (touch)

 

The touch command is used to create a new file. It may be used for files of all kinds – the file type must therefore be specified in the syntax. For example:

 

 

(Image source: Maker Pro)

 

will create a new (blank) text file, named new.txt.

 

Locating Files (locate)

 

As seen previously, the locate command may be used to search for specific files within a folder or directory. In addition to the -i parameter (which tells Linux to search for the file, irrespective of its combination of lower case and capital letters), you may use asterisks (*) as wildcards to widen your search criteria.

 

 

(Image source: Maker Pro)

 

Moving Files (mv)

 

The mv or “move” command is the Linux CLI equivalent of a drag-and-drop operation in Windows or macOS. It lets you move a file to another folder or directory.

 

The first part of the command identifies the file or application to be moved, while the second specifies the destination directory for the application or file.

 

 

(Image source: Maker Pro)

 

Removing Files and Directories (rm)

 

Used without a modifier, the rm or “remove” command deletes the specified folder or directory, and all the files that it contains. The syntax “rm -r” must be used to delete only the directory.

 

 

(Image source: Maker Pro)

 

Removing Empty Folders (rmdir)

 

A less powerful variant of the “remove” command, rmdir is used to remove directories with no files or applications in them.

 

The pwd Command

 

You can invoke the pwd command to find out where in the Linux environment you currently are. “pwd” stands for “print working directory”, and the command output displays the name of the current working directory.

 

 

(Image source: Geek University)

Specifying Text Output (echo)

 

Used to output text to the screen, the echo command can also assist in moving (usually text-based) data into a file.

 

 

(Image source: Geek University)

 

To create a new text file or add to an existing one, type echo, followed by the text string that you wish to append. E.g.:

 

echo hello, today is tuesday >> new.txt

 

The two triangular brackets (>>) are used to indicate the end of your text string.

 

Displaying User Information (whoami)

 

To discover and display the identity of the currently logged in user, the whoami command may be invoked.

 

 

(Image source: Geek University)

 

Clearing the Screen (clear)

 

If your command line display is becoming cluttered—or you simply want to start over with a fresh slate—typing “clear” will wipe the screen and take you back to the start prompt of whichever directory you are currently working in.

 

If you’d like to delve deeper into the world of the Linux command line, the Search Data Center at TechTarget has a resource that it calls 80 Linux commands you’ll actually use, which includes all of the above commands and numerous others.

 

Share →

Leave a Reply

Your email address will not be published.

(ec2)