What is an Operating System?
It is a system that runs operating devices such as Computer, mobile, laptops, and so on..,
Essential things that decide an OS are:
Kernel: The core of any software it has complete control of the system
File system: A DataStructure or method that OS uses to store and retrieve data in the memory
User Interface: Any user interface like CLI (command line interface), GUI (graphical user interface)
It should be able to manipulate data based on commands
- Some known and common Operating systems :
- Windows
- macOS
- Linux
Here Linux and macOS are similar because they both use UNIX-based operating system
Now let us go deep into Linux,
Firstly, Why Linux?
We i.e. many developers use Linux OS because it is,
- Open Source
- Supports all the programming languages
- Terminal is superior to CMD
- Bash Scripting, and many likewise
It's ok for now but where do users work more in Linux OS?
It is in the Terminal, the Terminal is a text input and output environment that we commonly call a console. Here in the terminal when we give the input text, the terminal launches Shell which is the command line interpreter that evaluates the input text, and the respective task is done based on the given text.
Here, What is the text that is given?🤔
These text contains three basic elements: commands, options, and arguments.
Commands: It is the name or short name of the task you want to execute.
Options: These are the flag kind of things that modifies the command output. These options start with a single dash(-) or double dash(--).
Arguments: The ones which you want to pass as input to so specific tasks.
[command] -[options] [arguments]
Basic Linux commands:
- echo: This command takes the argument and prints the argument into the console
- pwd: This command prints the path of the current working directory
- #: This hashtag is used to make the given text a comment
- ls: This command lists all the directories which are in that current working directory. We can use tags such as -a which shows all the directories and files including hidden files. The other is -l which gives us brief information about all the files
- cd: This command is used to change from one directory to another directory
- mkdir:This command creates a new directory
- touch: This command creates a new file with the given extension
- gedit: If you want to modify a file you can use gedit this opens the file in another window, if you want to continue with CLI you can use vi
gedit
vi
- cat: This command shows the content which is in a particular file
tac: This command is same as cat just the content is shown in last to first
cp: This command copies the content of one file to another file, it also copies the files from one directory to another and directories from one to another
- mv: This command moves the content from one file to another and files from one directory to another
- rm: This command deletes the specified file, if you want to delete the directory you can use rmdir
- diff: This command prints the uncommon lines from two specified files in CLI
- history: This command gives us the complete history from when the terminal started recently
- sudo(super user do): This command gives us access to the root user, if we enter the password we'll get root access.
- df:This command displays disk filesystem information all the information this gives is in byte format which is not convenient to read, so we can use -h option the info comes in human-readable format
head:When there is huge data, let us assume that we want only top elements to be displayed.
Here this head command comes into place, it shows the top 10 lines of that specified data. If you want to display a specified number of lines you can use -n followed by the number of lines required as an option
- tail: Similar to head, this tail command shows the last 10 lines of that specified data
If there is a huge amount of data in a particular file and you want to see the content of that file but you don't want to mess up the console,
So to redirect that huge file into a separate window we use less command.
This opens up the specified file in a separate window which is for reading purpose and after reading we can exit that window by giving q key
When we observe ls -l, here the first part we see are like drw-r--r-- these are the file permissions. It is a 10 bits string kind of thing, those 10bits are divided into 4 parts
First 1 bit tells us the type of file for the directory it shows d and for a file of specific extension it shows -,
The next 3 bits are the user permissions followed by group permissions and then other permissions
File permissions
There are three basic permissions that a system can assign to a file those are read(r), write(w), and execute(x)
By default, the system assigns some permissions to the file but we can modify the permissions of the file by using the command chmode
We can give them two types
By maintaining that permission with +/-
Short keys used are u-user,g-group, and o-others and for permissions r-read,w-write,x-execute
By numerical representation
As the permission denotes like rwx here numbering system represents the same
- read(r): 4 (100)
- write(w): 2 (010)
execute(x): 1 (001)
Those numeric digits are the binary conversions of 100,010,001
The highest permission system can give to a file is 7 and the lowest is 0. Here highest comes by adding all 4+3+1 permissions and the lowest comes with all 0's
- grep(global regular expression print): This command searches the specified special pattern within an output and returns the matched elements.
- env: This gives us the list of environment variables. Basically, this gives us the files. The reason this gives files is that In Linux, everything is a file, even the commands
We can also create our own command using alias for that specific session, after closing that terminal we can't reuse that command
- ps: This command gives the list of all the processes which are running
- top: This gives us a detailed list of all the processes which are running in the system, this command is just the alias of ps aux but this gives us the real-time process details.
- kill: This command kills the specific process which is running it just needs PID as an argument
Networking commands
- ping: This command gives us the connectivity status of any website
- netstat(network statistics): This command shows all the ports and all incoming and outgoing connections of sub-system of Linux
These are all the basic commands of Linux. All this becomes handy when you practice and apply them.
Learning Resources
Linux Masterclass Course from Aproov Goyal(YouTube)
Essential Linux Commands for DevOps from Kubesimplify blog video