Table of contents
Finally, I decided to start writing blogs to have systematic notes saved somewhere so that I can access them anytime, and at the same time, sharing my learning can help others, too.
So, in this blog, I'll be sharing whatever I've learned about operating system, and linux commands and what are the important and most basic linux commands that you should be familiar with as a developer.
What is Operating System?
An operating system is a program that acts as an interface between the computer user and computer hardware, and controls the execution of programs.
Things that a software needs to be considered as a Operating System
- Kernel - establish communication between user level application and hardware, decide state of incoming processes, control disk management, control memory management, control task management.
- File System - Data structure that an operating system uses to store and retrieve data in the memory.
- User Interface(CLI(Command line Interface) or GUI(Graphical user interface))
- Should be able to manipulate data based on commands
What happens when you start your computer?
When you start your computer, the operating system executes the softwares that are there in the BIOS(Basic Input Output System). The BIOS chip tells it to look in a fixed place, usually on the lowest-numbered hard disk (the boot disk) for a special program called a boot loader (under Linux the boot loader is called Grub or LILO). The boot loader is pulled into memory and started. The boot loader’s job is to start the real operating system.
Most common Operating Systems
- Windows(Majorly derived from other operating systems)
- Macintosh(UNIX based)
- Linux(UNIX based)
Why developers should use Linux
- UNIX based Operating System
- It is open source
- Supports almost all programming languages
- Offers vast range of applications and tools that are developer friendly
- Terminal is superior to command prompt(cmd) in windows
- Bash Scripting
- SSH
History of Linux
In 1969, a team of developers of Bell Labs started a project to make a common software for all the computers and named it as 'Unix'. It was simple and elegant, used 'C' language instead of assembly language and its code was recyclable. As it was recyclable, a part of its code now commonly called 'kernel' was used to develop the operating system and other functions and could be used on different systems. Also its source code was open source. In 1991, Linus Torvalds a student at the university of Helsinki, Finland, thought to have a freely available academic version of Unix started writing its own code. Later this project became the Linux kernel.
Working with Linux Terminal
Linux shell of "Terminal"
So, basically, a shell is a program that receives commands from the user and gives it to the OS to process, and it shows the output. Linux's shell is its main part. Its distros come in GUI (graphical user interface), but basically, Linux has a CLI (command line interface).
Opening the terminal
To open the terminal, press Ctrl+Alt+T in Ubuntu, or press Alt+F2, type in gnome-terminal, and press enter. In Raspberry Pi, type in lxterminal. There is also a GUI way of taking it, but this is better!
Managing the size of the terminal
To increase the size of the terminal, press ctrl + shift + '+' To decrease the size of the terminal, press ctrl + '-'
Basic Linux terminal commands
Hello world in terminal(echo) :
To print anything in the console just write echo and then the phrase you want to print. To print Hello, world just write $ echo Hello, world!
pwd :
Use the pwd command to find out the path of the current working directory (folder) you’re in. The command will return an absolute (full) path, which is basically a path of all the directories that starts with a forward slash (/). An example of an absolute path is /home/username.
ls :
The ls command is used to view the contents of a directory. By default, this command will display the contents of your current working directory.
- ls -R will list all the files in the sub-directories as well
- ls -a will show the hidden files
- cd- (with a hyphen) to move to your previous directory If you want to see the content of other directories, type ls and then the directory’s path. For example, enter ls /home/username/Documents to view the content of Documents.
cd :
To navigate through the Linux files and directories, use the cd command. It requires either the full path or the name of the directory, depending on the current working directory that you’re in.
Let’s say you’re in /home/username/Documents and you want to go to Photos, a subdirectory of Documents. To do so, simply type the following command: cd Photos.
- cd .. (with two dots) to move one directory up
- cd to go straight to the home folder
- cd- (with a hyphen) to move to your previous directory
Here is an example of pwd, cd and ls commands being used :
clear :
Just write 'clear' command to clean out the terminal
comments :
In Linux terminal, comments are written just after a # For example, if we write '#This is a comment' in the terminal if won't do anything.
mkdir & rmdir :
Use the mkdir command when you need to create a folder or a directory. For example, if you want to make a directory called “DIY”, then you can type “mkdir DIY”. Remember, as told before, if you want to create a directory named “DIY Hacking”, then you can type “mkdir DIY\ Hacking”.
- To generate a new directory inside another directory, use this Linux basic command mkdir Music/Newfile
- use the p (parents) option to create a directory in between two existing directories. For example, mkdir -p Music/2020/Newfile will create the new “2020” file.
Use rmdir to delete a directory. But rmdir can only be used to delete an empty directory. To delete a directory containing files, use rm.
touch :
The touch command is used to create a file. It can be anything, from an empty txt file to an empty zip file. For example, “touch new.txt”.
file :
Used to list types of all the files from mentioned directory.
gedit :
To start gedit from the command line, type gedit and hit Enter. The gedit text editor will appear shortly. It's an uncluttered and clean application window. You can get on with the task of typing up whatever you're working on
cat :
Use the cat command to display the contents of a file. It is usually used to easily view programs.
Here is an example using touch, file, gedit, and cat commands:
history :
When you’ve been using Linux for a certain period of time, you’ll quickly notice that you can run hundreds of commands every day. As such, running history command is particularly useful if you want to review the commands you’ve entered before.
cp :
Use the cp command to copy files from the current directory to a different directory.
man :
Loads the manual or info of a command. To see manual of any command, type man and then the command. For example man cp gives manual of cp command which looks like: