- Learn Linux Quickly
- Ahmed AlKabary
- 2040字
- 2021-06-11 18:43:43
A few simple commands
Congratulations on learning your first Linux command (date). Now let's keep learning more!
One would usually display the calendar after displaying that date, right? To display the calendar of the current month, you can run the cal command:

Figure 18 : The cal command
You can also display the calendar of the whole year, for example, to get the full 2022 calendar, you can run:

Figure 19: The cal command for the year 2022
You can also specify a month, for example, to display the calendar of February 1993, you can run the command:

Figure 20: The cal command for February 1993
You now have a lot of output on your Terminal. You can run the clear command to clear the Terminal screen:

Figure 21: Before clear
This is how your Terminal will look after running the clear command:

Figure 22: After clear
You can use the lscpu command, which is short for List CPU, to display your CPU architecture information:
elliot?ubuntu-linux:-$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 61
Model name: Intel(R) Core(TM) i5-5300U CPU? 2.30GHz Stepping: 4
CPU MHz: 2294.678
BogoMIPS: 4589.35
Hypervisor vendor: KVM
Virtualization type: full
Lid cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA nodeO CPU(s): 0
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr
You can use the uptime command to check how long your system has been running. The uptime command also displays:
- The current time.
- The number of users that are currently logged on.
- The system load averages for the past 1, 5, and 15 minutes.
elliot?ubuntu-linux:-$ uptime
18:48:04 up 4 days, 4:02, 1 user, load average: 0.98, 2.12, 3.43
You might be intimidated by the output of the uptime command, but don't worry, the following table breaks down the output for you.

Table 1: uptime command output
You probably haven't heard about load averages before. To understand load aver-ages, you first have to understand system load.
WHAT IS SYSTEM LOAD?
In simple terms, system load is the amount of work the CPU per-forms at a given time.
So the more processes (or programs) running on your computer, the higher your system load is, and fewer processes running leads to a lower system load. Now, since you understand what a system load is, it's easy to understand load averages.
WHAT IS LOAD AVERAGE?
The load average is the average system load calculated over a given period of 1, 5, and 15 minutes.
So the three numbers that you see at the very end of the uptime command output are the load averages over 1, 5, and 15 minutes respectively. For example, if your load averages values are:
load average: 2.00, 4.00, 6.00
Then these three numbers represent the following:
- 2.00 --+: The load average over the last minute.
- 4.00 --+: The load average over the last five minutes.
- 6.00 --+: The load average over the last fifteen minutes.
From the definition of load average, we can conclude the following key points:
- A load average of value 0.0 means the system is idle (doing nothing).
- If the 1-minute load average is higher than the 5- or 15-minute averages, then this means your system load is increasing.
- If the 1-minute load average is lower than the 5- or 15-minute averages, then this means your system load is decreasing.
For instance, load averages of:
load average: 1.00, 3.00, 7.00
Shows that the system load is decreasing over time. On the other hand, load averages of:
load average: 5.00, 3.00, 2.00
Indicates that the system load is increasing over time. As an experiment, first take note of your load averages by running the uptime command, then open up your web browser and open multiple tabs, then rerun up-time; you will see that your load averages have increased. After that, close your browser and run uptime again, you will see your load averages have decreased.
You can run the reboot command to restart your system:
elliot?ubuntu-linux:-$ reboot
You can run the pwd command to print the name of your current working directory:
elliot?ubuntu-linux:-$ pwd
/home/elliot
The current working directory is the directory in which a user is working at a given time. By default, when you log into your Linux system, your current working directory is set to your home directory:
/home/your_username
WHAT IS A DIRECTORY?
In Linux, we refer to folders as directories. A directory is a file that contains other files.
You can run the ls command to list the contents of your current working directory:
elliot?ubuntu-linux:-$ ls
Desktop Documents Downloads Music Pictures Public Videos
If you want to change your password, you can run the passwd command:
elliot?ubuntu-linux:-$ passwd
Changing password for elliot.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
You can use the hostname command to display your system's hostname:
elliot?ubuntu-linux:-$ hostname
ubuntu-linux
You can use the free command to display the amount of free and used memory on your system:
elliot?ubuntu-linux:-$ free
total used free shared buff/cache available
Mem: 4039732 1838532 574864 71900 1626336 1848444
Swap: 969960 0 969960
By default, the free command displays the output in kilobytes, but only aliens will make sense out of this output.
You can get an output that makes sense to us humans by running the free command with the -h option:
elliot?ubuntu-linux:-$ free -h
total used free shared buff/cache available
Mem: 3.9G 1.8G 516M 67M 1.6G 1.7G
Swap: 947M OB 947M
That's much better, right? The -h is short for --human, and it displays the output in a human-readable format.
You may have noticed that this is the first time we ran a command with an option. The majority of Linux commands have options that you can use to change their default behavior slightly.
You should also know that command options are either preceded by a single hyphen (-) or a double hyphen (--). You can use a single hyphen if you are using the abbreviated name of the command option. On the other hand, if you are using the full name of the command option, then you need to use a double hyphen:
elliot?ubuntu-linux:-$ free --human
total used free shared buff/cache available
Mem: 3.9G 1.8G 516M 67M 1.6G 1.7G
Swap: 947M OB 947M
As you can see, the previous two runs of the free command yielded the same output. The only difference is that the first time, we used the abbreviated command option name -h, and so we used a single hyphen. In the second time, we used the full command option name --human, and so we used a double hyphen.
You have the freedom of choice when it comes to using the abbreviated command option names versus the full command option names.
You can use the df command to display the amount of disk space available on your system:
elliot?ubuntu-linux:-$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1989608 0 1989608 0% /dev
tmpfs 403976 1564 402412 1% /run
/dev/sda1 20509264 6998972 12445436 36% /
tmpfs 2019864 53844 1966020 3% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 2019864 0 2019864 0% /sys/fs/cgroup
/dev/loop0 91648 91648 0 100% /snap/core/6130
tmpfs 403972 28 403944 1% /run/user/121
tmpfs 403972 48 403924 1% /run/user/1000
Again you may want to use the human-readable option -h to display a nicer format:
elliot?ubuntu-linux:-$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 395M 1.6M 393M 1% /run
/dev/sda1 20G 6.7G 12G 36% /
tmpfs 2.0G 57M 1.9G 3% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/loop0 90M 90M 0 100% /snap/core/6130
tmpfs 395M 28K 395M 1% /run/user/121
tmpfs 395M 48K 395M 1% /run/user/1000
Don't worry if you can't understand everything you see in the output, as I will ex-plain everything in detail in the following chapters. The whole idea of this chapter is to get your feet wet; we will pe deep later with the sharks!
The echo command is another very useful command; it allows you to print a line of text on your Terminal. For example, if you want to display the line Cats are better than Dogs! on your Terminal, then you can run:
elliot?ubuntu-linux:-$ echo Cats are better than Dogs!
Cats are better than Dogs!
You might be asking yourself, "How on earth is this useful?" Well, I promise you that by the time you finish reading this book, you would have realized the immense benefits of the echo command.
You can spend a great amount of time on your Terminal, punching in commands. Sometimes, you may want to rerun a command, but you may have forgotten the name of the command or the options that you have used, or you are simply lazy and don't want to type it again. Whatever the case may be, the history command will not let you down.
Let's run the history command and see what we get here:
elliot?ubuntu-linux:-$ history
1 date
2 blabla
3 cal
4 cal 2022
5 cal feb 1993
6 clear
7 lscpu
8 uptime
9 reboot
10 pwd
11 ls
12 passwd
13 hostname
14 free
15 free -h
16 free --human
17 df
18 df -h
19 echo Cats are better than Dogs!
20 history
As expected, the history command displayed all the commands that we ran so far in chronological order. On my history list, the lscpu command is number 7, so If I want to rerun lspcu, all I need to do is run !7:
elliot?ubuntu-linux:-$ !7
lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 61
Model name: Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
Stepping: 4
CPU MHz: 2294.678
BogoMIPS: 4589.35
Hypervisor vendor: KVM
Virtualization type: full
Lid cache: 32K
L1i cache: 32K
12 cache: 256K
13 cache: 3072K
NUMA node0 CPU(s): 0
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr
UP AND DOWN ARROW KEYS
You can scroll up and down on your command line history. Every time you hit your up arrow key, you scroll up one line in your command history.
You can also reverse and scroll down with your down arrow key.
You can use the uname command to display your system's kernel information. When you run the uname command without any options, then it will print just the kernel name:
elliot?ubuntu-linux:-$ uname
Linux
You can use the -v option to print the current kernel version information:
elliot?ubuntu-linux:-$ uname -v
#33-Ubuntu SMP Wed Apr 29 14:32:27 UTC 2020
You can also use the -r option to print the current kernel release information:
elliot?ubuntu-linux:-$ uname -r
5.4.0-29-generic
You can also use the -a option to print all the information of your current kernel at once:
elliot?ubuntu-linux:-$ uname -a
Linux ubuntu-linux 5.4.0-29-generic #33-Ubuntu SMP
Wed Apr 29 14:32:27 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
You can also run the lsb_release -a command to display the Ubuntu version you are currently running:
elliot?ubuntu-linux:-$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
Finally, the last command you are going to learn in this chapter is the exit command, which terminates your current Terminal session:
elliot?ubuntu-linux:-$ exit
A COOL FACT
You may have already observed by now that Linux command names pretty much resemble what they do. For instance, the pwd command liter-ally stands for Print Working Directory, ls stands for List, lscpu stands for List CPU, etc. This fact makes it much easier remembering Linux commands.
Congratulations! You made it through the first chapter. Now it's time for your first knowledge check exercise.
- ExtGWT Rich Internet Application Cookbook
- Java程序設計與開發
- Python 3.7網絡爬蟲快速入門
- Angular UI Development with PrimeNG
- 單片機C語言程序設計實訓100例:基于STC8051+Proteus仿真與實戰
- Learning ArcGIS Pro 2
- 深入理解Java7:核心技術與最佳實踐
- 軟件項目管理實用教程
- Python期貨量化交易實戰
- Practical Microservices
- 虛擬現實建模與編程(SketchUp+OSG開發技術)
- Extending Docker
- 精益軟件開發管理之道
- Splunk Essentials
- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)