Some Basic Linux Commands I Have Used During My Linux Journey – Part 5

Maybe you thought that the number of commands in the linux operating system would come to an end in the fourth part of this series, but it did not. There are many others I have learned while working on the linux commandline.

You might want to read our previous parts of this series.

The date command

The date command is used to display the system date on standard output. Open a new terminal console on your linux machine and run the following command.

date

Depending on the day you run it you should get a different output. I get the following.

Thu Jun 4 12:53:57 CEST 2015

Not only we get information about the date when using the date command but we also learn the correct time in the zone of our system. And of course the year too.

You can also output the date in  RFC 2822 format by using the -R option with the date command like shown in the following example which is being run on my machine.

date -R

When using the above command you should get an output similar to the following. I mean the same format.

Thu, 04 Jun 2015 13:00:45 +0200

The lsusb command

The lsusb command as the name suggests is used to list usb devices on your system. According to its manual page it displays information about USB buses in the system and the devices connected to them.

Running the following command just lists the USB buses on my system. It does not give me a detailed information but is useful when I want to know what devices are connected to them.

lsusb

And the output of the above command is shown below.

 Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
 Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
 Bus 001 Device 005: ID 1bcf:2883 Sunplus Innovation Technology Inc.

A more detailed output is displayed using the -v option which stands for verbose output. When using this option you will also get information on the descriptors for the device’s speed.

Run the following command on your system.

lsusb -v

The output of the above command is going to be very long so I am not going to post it in here. You should try the command and study it yourself for further learning or advancing your skills.

The arch command

The arch command can be very useful when you want to show the architecture of your machine on standard output. If you have ever used uname -a then you understand the purpose of the arch command then.

Run the following command to print the machine hardware name.

arch

And I get the following output.

x86_64

To find the version of the arch utility being used you can use the –version long option like shown in the following example.

arch --version

When running the above command I get the following output.

 arch (GNU coreutils) 8.13
 Copyright (C) 2011 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
 Written by David MacKenzie and Karel Zak.

To get help while using the arch command then use the –help long option like shown in the following example.

arch --help

The following output is displayed on my console when  running the above command.

 Usage: arch [OPTION]...
 Print machine architecture.

 --help display this help and exit
 --version output version information and exit

 Report arch bugs to bug-coreutils@gnu.org
 GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
 General help using GNU software: <http://www.gnu.org/gethelp/>
 For complete documentation, run: info coreutils 'arch invocation'

Unfortunately the arch tool does not support other options.

The cal command

The cal command is used to display a simple calendar on the standard output. To show a calendar on your console just run the following command.

cal

And you should a get nicely traditional calendar which highlights the current date. Mine is shown below.

 June 2015
 Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
 14 15 16 17 18 19 20
 21 22 23 24 25 26 27
 28 29 30

To turn off highlighting of today which is on by default then you should use the -h option like shown in the following example.

cal -h

Now you will not get the today highlighted, I mean anytime you run the above command.

Use the -y option to display the calendar for a specific year.

cal -y 2016

The above command will display the all calendar for the year 2016.

The file command

The file command is used to determine what a file contains before you view it. In short words when using the file command it will examine the file for you and tell its kind. As an example take the following command shown below.

file test.txt

Running the above command on my system gives me the following output.

test.txt: ASCII text

And if you would like to output mime strings rather than traditional ones then use the -i option like shown below.

file -i test.txt

I get the following output.

test.txt: text/plain; charset=us-ascii

You can also print specific elements out of the long mime string. For example to print the mime type run the following command.

file --mime-type test.txt

I get the following output when running the above command.

test.txt: text/plain

What about printing out the mime encoding? It is very simple! The –mime-encoding can be used in this case like shown in the following example.

file --mime-encoding test.txt

Whe running the above command I get the following output.

test.txt: us-ascii

To learn more about the file command  you know what to do. In case you don’t just run the following command.

man file

The ls /bin command

I am sure you know about the ls command. It is used to list the files inside a directory. The ls /bin command can be used to list the files inside the /bin directory of your system.

The ls -l /bin command

The ls -l /bin command lists the files inside the bin directory in the long format. The -l option stands for long output which is very useful to use when you want detailed stuff.

The hdparm -i /dev/sda command

The hdparm -i /dev/sda command is used to show information about the disk /dev/sda. Run the following command on your console to get a better understanding.

hdparm -i /dev/sda

I get the following output when running the above command.

 /dev/sda:
 Model=ST9500325AS, FwRev=0005HPM1, SerialNo=5VE436TP
 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
 BuffType=unknown, BuffSize=8192kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=976773168
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes: pio0 pio1 pio2 pio3 pio4
 DMA modes: mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5
 AdvancedPM=yes: unknown setting WriteCache=enabled
 Drive conforms to: unknown: ATA/ATAPI-3,4,5,6,7
 * signifies the current active mode

The head -n1 /etc/issue command

The head -n1 /etc/issue command is used to show the name and the version of distribution which powers your linux machine. Running this command on my system like shown below gives me some nice information about the Ubuntu version I am using.

head -n1 /etc/issue

And the name and version of the machine being used is shown below.

Ubuntu 12.04.4 LTS \n \l

The last reboot command

If you want to know the date and time of the last reboot of your machine then you should use the following command.

last reboot

When running the above command I get the following output.

wtmp begins Tue Jun 2 03:04:39 2015

The free command

The free command is used to display the amount of free and used memory on your system. For example to display information on my used and free ram I just use the free command like shown below.

free

And I get a nice readable output like shown below.

 total used free shared buffers cached
 Mem: 3929724 3708236 221488 0 44712 1947924
 -/+ buffers/cache: 1715600 2214124
 Swap: 0 0 0

To make it human readable make use of the -m option which is being used to display the amount of ram in MB.

free -m

And the output produced by the above command is very human readable. It is shown below.

 total used free shared buffers cached
 Mem: 3837 3627 209 0 43 1913
 -/+ buffers/cache: 1670 2167
 Swap: 0 0 0

Conclusion

In this part we took a look at some very practical linux commands I have learned all this time as a linux user. In the next part I will compile and explain some new useful commands for you guys.