Fundamentals of Operating System
Most Important Linux Commands
Introduction
Linux is one of the most popular operating systems. So what is an operating system? An Operating System is nothing but a software program that acts as an interface between the hardware, the application software, and the users. The main aim of an operating system is to manage all the computer resources. So, we can say that the operating system gives a platform to the application software and other system software to perform their task.
Linux is an open-source operating system whose main component is Kernel (the central component which manages and provides all the operations of the hardware and the computer). Linux was developed by Linus Torvalds in the year 1994 and he developed Linux using some help from the UNIX operating system and the MINIX operating system.
Some of the features of Linux which make it one of the most widely used operating systems are:
- Linux is an open-source operating system, so its source code is available and we can make changes to the code according to our preference.
- Linux is comparatively more secure as viruses and hackers cannot easily attack Linux operating system.
- Linux is lightweight and the RAM consumption is very less as well.
- Linux provides simpler updates for all software, we can install the update using a single command (refer to the next section to learn more about the commands).
- Linux has multiple distributions for example Red Hat Linux, Fedora Linux, CentOS Linux, etc. hence, we can download any type of distribution according to our preference.
- The root user is a special or superuser in Linux operating system and has all the access to the system. A root user is shown using the
$
sign and a normal user is shown using the#
sign. - Linux file system is a tree-based structure consisting of files and directories. The folders are known as directories in the Linux operating system.
Most Important Linux Commands
As we have discussed that Linux is a lightweight, open-source, secure operating system. So, now let us learn about the various important Linux command.
1. Is command
The ls
command is used to list down the files and directories (folders) of the current directory. Here, ls
means list.
Command:
Command (view hidden files)
2. pwd command
The pwd
command is used to print the current working directory (path of the current directory). So, if we want to know where we are then we can use this command.
Command:
3. clear command
The clear
command is used to clear the screen or terminal, we can also press CTRL + D
.
Command:
4. history command
The history command is used to see all the commands used by us.
Command:
5. cat commandcat
or concatenate command is a universal command that helps us to read the data from the file and copy the standard input to the standard output.
Command (read or view file):
Command (create a file):
Command (add something to the end of a file):
Command (concatenate two files):
Some of the operations that we can perform using the cat command are:
- create a file.
- concatenate two or more files.
- copy the content of one file into another file.
- reverse the contents of a file.
Note:
- We cannot edit a file using the cat command.
- We generally use the
>
operator to copy all the contents of the left-side files to the right-side files. For example, in the commandcat file1 > file2
, the contents offile1
are copied tofiles2
.
6. touch command
The touch
command is used to create one or more than one empty files.
Command:
Command (to create an empty hidden file):
Some of the operations that we can perform using the touch
command are:
- create one or more empty files.
- change the timestamps of the file(s).
- update the access time of the file(s).
7. mkdir command
The mkdir
command stands for make directory. As the name suggests, the mkdir
command is used to create directories.
Command:
Command (to create a hidden directory):
Command (to create a directory (directory2) inside another directory(directory1):
8. cd command
The cd
command (change directory) is used to change the working directory to go to a certain directory.
Command:
Command (to get out of the current directory):
9. head and tail command
The head
and tail
command is used to view the first 10 lines and the last 10 lines of a file respectively. These commands are very useful if the content of a file is very large.
Command
10. copy command
The cp
or copy command is used to copy the contents of one file into another file.
Command:
11. move command
The mv
or move command is used to move one or more files and directories from one directory to another.
Command:
Note: We can use the same command to rename the files and directories. We just need to specify the old name at the place of source and the new name at the place of destination in the above command.
12. remove file command
The rm
command is used to remove the specified files.
Command (to remove empty and non-empty files):
13. remove directory command
The rmdir
command is used to remove the specified directories.
Command (to remove an empty directory):
Command (to remove both the parent and the child directory):
Command (to remove a directory if the directory is not empty, it can also delete the sub-directories):
14. hostname command
As the name suggests, the hostname
command is used to know the name of the host of the system.
Command:
15. IP address command
We can use the if config
command to know the IP address of the machine.
Command:
16. To know the operating system version
The version of the operating system is stored in the os-release directory present in the etc directory.
Command:
17. To update and install specific software
We can use the yum
command which stands for yellow dog updater modifier to install, update, remove and list down the software in the Linus operating systems.
Command (to install software):
Command (to list all the installed software):
Command (to remove the installed software):
Command (to upgrade package):
Note: The above command will update all the installed software. ****We can also specify the name of the software that we want to update.
18. To know the details of the current user
The whoami
command is used to know the details of the current user.
Command:
19. To sort the contents of the file
We can use the sort
command to sort the contents of the files in alphabetical order.
Command:
20. To add a user
To add a new user to the Linux operating system, we can use the useradd
command.
Command:
21. To add a group
To add a new group to the Linux operating system, we can use the groupadd
command.
Command:
22. To view the groups and users
We can use the following commands to view the groups and users of the Linux operating system.
Command (groups):
Command (users):
23. To zip and unzip the contents of a file
We can use the gzip
command to zip and gunzip
command to unzip files in Linux operating system.
Command (zip files):
Command (unzip files):
24. To change the access modes files
We can use the chmod
command to change the access permission of files and directories.
Command:
Refer to the image provided below to understand the access number used in Linux operating system.
[Image courtesy: Devopsschool.com].
Similarly, we can use the chown
and chgrp
commands to change the owner of files/directories and change the group of files/directories respectively.
25. To know the details of a command
To know the details of any command we can use the man command along with our desired command to know the details.
Command:
Some bonus commands
data
command: Thedate
command is used to print the current day, date, time, and time zone of the current window.cal
command: Thecal
command is sued to view the calendar of any month or year of our choice.grep
command: Thegrep
command is used to search for some content in a file.wc
command: Thewc
command is used to count the words in a word file.du
command: Thedu
command is used to know the disk usage of the system.df
command: Thedf
command is used to know the available disk space of the system.
Conclusion
Linux is one of the most popular operating systems which was developed by Linus Torvalds in the year 1994. Linux is comparatively more secure as viruses and hackers cannot easily attack Linux operating system. Linux has multiple distributions, such as Red Hat Linux, Fedora Linux, CentOS Linux, etc.; hence, we can download any distribution according to our preference. The source code of the Linux kernel is available and we can make changes to the code according to our preference.