Basic Linux Commands – Part 2

By | February 24, 2018

We are looking into some basics and advance Linux Command. This post is continuity of Linux Basic to Advance Commands – Part 1. In this Post, we will be covering the below commands.

  • uname
  • arch
  • uptime
  • cat 
  • touch
  • clear
  • history
  • poweroff
  • shutdown
  • reboot

1. uname

uname command will print your system information.  The only uname command will display the operating system of your machine. below are some options which we can use to get some additional information.

Options:

  • -a:  print all information about your operating system
  • -s:  print the kernel name
  • -n:  print the network node hostname
  • -r:  It will display the kernel release.
  • -v:  It will display the kernel version
  • -m: It will display the machine hardware name/Architecture
  • -o: It will display the operating system.

Example

[root@devopsage ~]# uname -a
Linux devopsage 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[root@devopsage ~]# uname -n
devopsage

[root@devopsage ~]# uname -s
Linux

[root@devopsage ~]# uname -r
3.10.0-693.17.1.el7.x86_64

[root@devopsage ~]# uname -v
#1 SMP Thu Jan 25 20:13:58 UTC 2018

[root@devopsage ~]# uname -m
x86_64

[root@devopsage ~]# uname -o
GNU/Linux

2. arch

This command is similar to the uname -m command. It displays the machine hardware or what we can call is architecture. It displays whether the server is 32 or 64-bit machine.

[root@devopsage ~]# arch
x86_64
[root@devopsage ~]#

3. uptime

This command gives you the information on how long the system has been running. It also gives information about the number of users logged in, date and time and the load average of a system for 1, 5 and 15 minutes.

[root@devopsage ~]# uptime
 10:53:17 up 49 min,  1 user,  load average: 0.00, 0.01, 0.05
[root@devopsage ~]#

4. cat

cat (concatenate) command is used to display the content of any files. using cat command we can also modify the content of any file and often create a new file.

[root@devopsage ~]# cat > devopsage   //write something and press ctrl+d to same the file.
welcome to devopsage
ctrl+d to save.

[root@devopsage ~]# ls -l
-rw-r--r--. 1 root root         21 Feb 24 10:58 devopsage

[root@devopsage ~]# cat devopsage 
welcome to devopsage

Few Options:

  • E:  Displays $ at the end of the line.
  • -n:  display the line number for the printed output

5. touch

touch command is used to create multiple empty files at a time. It also changes the timestamps of an existing file which usually changes the access and modification time of the existing file to the current date and time. We can also check whether we have write permission on any particular file or not, using the touch command.

Example: We will see how we can create multiple empty (0 KB files) files using touch command and will also see how we can change the timestamp of the existing file.

[root@devopsage ~]# touch file1 file2 file3
[root@devopsage ~]# ls -l
-rw-r--r--. 1 root root         21 Feb 24 10:58 devopsage
-rw-r--r--. 1 root root          0 Feb 24 11:08 file1
-rw-r--r--. 1 root root          0 Feb 24 11:08 file2
-rw-r--r--. 1 root root          0 Feb 24 11:08 file3

[root@devopsage ~]# touch devopsage
[root@devopsage ~]# ls -l
-rw-r--r--. 1 root root 21 Feb 24 11:09 devopsage
-rw-r--r--. 1 root root 0 Feb 24 11:08 file1
-rw-r--r--. 1 root root 0 Feb 24 11:08 file2
-rw-r--r--. 1 root root 0 Feb 24 11:08 file3

[root@devopsage ~]# touch test{1..5}
[root@devopsage ~]# ls -l
-rw-r--r--. 1 root root         21 Feb 24 11:09 devopsage
-rw-r--r--. 1 root root          0 Feb 24 11:08 file1
-rw-r--r--. 1 root root          0 Feb 24 11:08 file2
-rw-r--r--. 1 root root          0 Feb 24 11:08 file3
-rw-r--r--. 1 root root          0 Feb 24 11:14 test1
-rw-r--r--. 1 root root          0 Feb 24 11:14 test2
-rw-r--r--. 1 root root          0 Feb 24 11:14 test3
-rw-r--r--. 1 root root          0 Feb 24 11:14 test4
-rw-r--r--. 1 root root          0 Feb 24 11:14 test5

[root@devopsage ~]# touch -d "24 Feb 2018" devopsage

6. clear

clear command is used to clear the content of screen (clears the terminal screen). It clears the content and shows command prompt at beginning of the line

7. history

history command will display the history of the commands that you have used on that particular terminal. It is a very helpful command to keep a track of what command we have used so far.

[root@devopsage ~]# history -c // will clear history
[root@devopsage ~]# !100 // history shows what command is executed with line number, so by using !100, 100th line number command will get executed.

8. poweroff

This command will shutdown your machine.

9. shutdown

Same as poweroff, this will halt your Linux machine.

10. reboot

This command itself states that it will restart your machine.

Leave a Reply

Your email address will not be published. Required fields are marked *