Linux Command Line Introduction

Command Line Fundamentals

How come we have a command line? Isn’t that like, uh, so 1970s?

Just as cavemen learned to develop their skills from grunting and groaning to writing meaningful representations on the walls of caves, The computer world started off with the keyboard and the CLI (Command Line Interface). All action that happened on any system would be inherently text. Xerox’s PARC research center managed to invent the very first graphical user interface in the early 1980s, however, When Linux first came to be in 1991, most things were still text. True, Windows 3.0 was out, and MacOS had been with us since 1984 but the PC world was still dominated with text. MS-DOS still ran the PC show. Anyone who wanted to use their PC efficiently back in 1991 with a Microsoft machine, would use Windows to run their graphical programs like Aldus PageMaker and Lotus 1-2-3, but they would open an MS-DOS prompt box, or close Windows and drop to DOS, so that they could quickly rename a file or move it from one place to another. Sure, users could even then, click into the File Explorer, select the file(s) they wanted to rename or move and drag them to the relevant location, but a lot of people were finding that DOS was still quicker to use if you knew the commands. If you spent a few days learning the rudimentary commands of DOS, you could really use your PC efficiently, coupled with the graphical usefulness of Windows, you could cut workload down by a good deal. Even today, when using modern GUI O/S’s like Windows and Mac OS, I still finding myself going to Start going to Start>Run and typing in cmd or to access the command prompt to do something quickly.

Why do we still use the command line today?

Imagine the following scenario:
You have 300 files in a folder (call the folder ‘work’), and within that folder you have 2 other folders, one called ‘old’ and one called ‘new’. Your task is to separate the files in work to the new and old folder. You must put the files that are older than 1 month into old, and the files less than 1 month into new. In a graphical file manager, you would need to right click each of the 300 files separately to find out their creation date, and then move each of the files one by one into their relevant folder. This operation is seriously time-consuming.
How’s about the command-line option: type in one line at the shell, and the files are automatically sorted into each folder, determined by todays date. Sure, you would know that you would have to type
find /usr -ctime +30 -exec ls -ld {} \;‘ to get it to happen, but hey, it’s still faster than going through 300 files.
There are yet many other reasons that you may want to have a CLI, for example, a User Administrator has 3 dead (crashed) programs on 3 different workstations across a building. He has two choices: Go run around the building like a headless chicken and kill the programs manually at each workstation, or sit at his or her desk and SSH into each machine, using the CLI, killing each of the programs, finishing the job 20 times faster.

If you start to use Linux a lot, you’ll start to find it’s a lot easier just to issue a direct command instead of clicking on a bunch of different icons to do something you could do in one command at the CLI. In fact, even Microsoft have, as of 2017 stated that they ‘Love Linux’. They’ve brought the Bash shell via Ubuntu to the Windows desktop, and MacOS has has the bash shell built into it since the beginning of MacOS X. The reason for this? Because it’s where people get serious about being effective system administrators and programmers. If you fancy a career in being a system administrator then you should read the bottom of this article!

Some simple commands, you may recognise

GNU/Linux has a lot of commands, luckily though, you’ll probably only ever want to know around 10-15 of them for anything at the CLI.
You can find the files for these commands in folders like /bin and /usr/bin on your Linux box.
If you have used computers since at least the late 90s, then you will probably remember DOS, you’ll find that the syntax of DOS commands compared to UNIX commands are often similar, and even some of the commands themselves are the same. Have a look at this comparison table if you can remember any DOS commands:

DOS Command UNIX Counterpart What it does
dir ls Shows the files in the current folder
cls clear Clears the screen
type cat Shows the contents of a file, eg cat foo.txt
move mv Move a file from one place to another, eg: mv foo /home/
copy cp Copies a file, eg: cp /home/foo /users/foo
ren / rename mv The mv (move) command also doubles up for renaming
echo echo output (or echo) something to the screen

Some more commands, plus how to get help on almost any command

Here are a few more advanced commands, along with their explanations and one example for each:

Command Action Example
chmod Changes permissions for files chmod u=rwx myfile.txt
chown change the owner for a file or folder chown myuser /home/myfile.txt
chgrp change the group owner for a file or folder chgrp mygroup /home/myfile.txt
mv Moves or renames a file mv /home/me/myfile.txt /home/them/
grep searches text for results cat myfile.txt | grep “hello”
ls list the files in a folder ls -l
find finds files or file designators find /home -name “myfile.txt”
mount mounts a drive/block device for use mount /dev/cdrom /mnt/cdrom
ps Show the list of live processes ps ax | more
kill kill a process (running software) by process ID kill -9 12345
tar de facto Unix archiver tar zxvf myarchive.tar.gz
rpm The Red Hat Package manager, used to install, remove, upgrade and query RPM packages. rpm -Uvh mynewpackage.i386.rpm


Tux, The Linux Mascot
Tux Tip

If you ever need to know how to use a command, or just find out what a command does man (short for manual) is your friend. For example, by typing man ls, a comprehensive guide is given on using the ls command, what it’s purpose is and what it’s syntax is. For more information on using man, type man man.
There is not a better source for quick, easy to find information on almost every Linux command. The only times when man lets you down, is when you don’t know that a command that does a specific purpose exists, thus, you don’t know the name of the command, so you don’t know what manual page you want to ask man for. For this reason, I have started the lengthy process of creating a commands guide, that is easy to understand, although somewhat less verbose than manual pages themselves.

Now Learn More!

  • Get yourself started with the fundamentals of Linux System Administration on the command-line with the free Linux 101 presentation deck here at the Ultimate Linux Newbie Guide
  • Sign up to the Linux Foundation for official certification. Training courses are at your time and pace, remotely managed and are internationally recognised.

Some other helpful links:

Leave a Reply