The Linux command line: what is and what you can do with it

command line udev

Getting the command line idea

google_plustwitterFacebooktumblrreddit

Anyone that has got involved in the Linux world has heard at least once of the command line. Still some people don’t quite know what it is and what can it be used for, the truth is that the command line can be used to accomplish many things. This post will make an overview of the command line; such as what it is, some background and examples of things it can be used for.

What is the Linux command line?

The command line is a text based interface (or a simply a program) someone can use in order to interact with its system and perform operations. There are tons of operations a user can do with a command line interface, some of them more oriented towards the operating system like retrieving information from a driver, while others more user space oriented like moving a file from one place to another. In the examples section of this post we’ll check some of these.

Some background: the shell

Now, if we talk about the Linux command line the term shell will show up eventually. In the early days, the shell was the interface programmers had to talk to Unix systems, it was their command line. Later the Unix Shell became a building block that opened the doors for other derivative work. In 1989 the GNU project released Bash (the Bourne Again Shell), this shell implemented functional improvements for programming and interactive use.

gnu and tux

By 2016 we have various shell options (like bash, dash, ash ..) which we can use to accomplish from very simple to complex tasks. If you are running right now a Linux distro on your PC you have at your disposal some programs that will allow you to interact with the command line, e.g: Terminal and XTerm on Ubuntu. It will depend on your Linux distro which shell you’ll have as default.

Examples of command line uses

Considering which kind of Linux user you are there a tons of things you can use the command line for; day to day tasks, system administration, software developing are just a few. Lets check some examples (Hint: If you are running Linux open a terminal program so can try the commands by yourself):

Home navigation

Most terminals programs will have home as the current directory when you open them. Home (or /home/user) is the place where you can store your files, lets check this three shell commands and lets use them to navigate the home directory

pwd: print working directory

ls: lists information about files (in current directory by default)

cd: change directory

~$ pwd
/home/bluepenguin
~$ ls
Desktop Documents Downloads Music Pictures Public Videos
~$ cd Documents
~$ pwd
/home/bluepenguin/Documents

Create text documents

From simple on-the-go commands to command line editors like nano or Vim you can use them to create text files

cat: concatenate file(s), or standard input, to standard output

~$ # Hashtags are used for comments.
~$ # After writing end process with ctrl+c
~$ cat > sample-file.txt
1 2 3
^c
~$ #Now lets see what we have
~$ cat sample-file.txt
1 2 3
google_plustwitterFacebooktumblrreddit

Launch programs

Using the command line you can launch other programs, such as Evince to open PDF files

Evince: the GNOME Document Viewer

~$ evince some.pdf

Get social: Tweet

Run any of the available command line twitter clients and start tweeting

rainbowstream command line

rainbowstream twitter

Check system info

There is a wide set of commands for seeing how a Linux system is doing

free: prints used and free memory

dmesg: prints the kernel ring buffer

~$ free -h
             total       used       free     shared    buffers     cached
Mem:          5,8G       4,3G       1,5G       222M       515M       1,7G
-/+ buffers/cache:       2,1G       3,7G
Swap:         6,0G         0B       6,0G
~$ dmesg | head
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 4.4.0-38-generic (buildd@lgw01-22) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) 57~14.04.1-Ubuntu SMP Tue Sep 6 17:20:43 UTC 2016 (Ubuntu 4.4.0-38.57~14.04.1-generic 4.4.19)
[    0.000000] Command line: BOOT_IMAGE=/vmlinuz-4.4.0-38-generic root=/dev/mapper/ubuntu--vg-root ro quiet splash vt.handoff=7
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Legacy x87 FPU detected.

Create & run shell scripts

Instead of running individual commands you can group them, apply control flow logic and create powerful scripts that the shell then will interpret

~$ ./some-pro-script

Compile & run programs

You can use the toolchain that came with your distribution (e.g: GCC) or use any other one you have

//hi.c
#include <stdio.h>
void main() {
    printf("Hi\n");
}
~$ gcc hi.c -o hi
~$ ./hi
Hi

Run other interpreters

Run python (interactive mode)

~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

The command line, use or not to use?

You may be wondering if you should learn the command line in depth, the answer partly depends on what kind of user are you. If you spend most of your time in social media and don’t care about how your computer works probably not. If you are into the software world, as enthusiast or as a professional you should consider it. The command line becomes a powerful tool for the ones who know how to make the most out of it, a great benefit is that it can help getting your workflow more centralized and if needed piped.

google_plustwitterFacebooktumblrreddit

Code more proficiently staying up to date

100% Privacy - Blue Penguin List - 0% Spam

1 Trackback / Pingback

  1. New command line material - Blue Penguin List

Leave a Reply

Your email address will not be published.


*