Linux for DevOps and Developers
Complete Linux for developers and DevOps engineers
Table of contents
- History of Linux
- Linux basic commands
- Some advance commands
History of Linux
In 1964, Bell laboratory started a project at New Jersey. Project was to create a multitasking and multiuser operating system And in 1969 they withdrawed that project. But Dennis Ritchie(developer of C language) and Ken Thompson did not give up on this project. This project was UNIX.
In 1969, Dennis Ritchie and Ken Thompson started on this project again. They made a OS called UNICS.(Uniplexed Information & computing services)
After sometime it called as UNIX. This was open source project.
In 1975, a new version of unix introduced- UNIX version 6. This was so popular at that time. So many companies made their versions using this open source unix operating system.
Examples:
Flavours of UNIX
In 1991, There was a student Linus Torvalds. Linux began in 1991 as a personal project by Finnish student Linus Torvalds: to create a new free operating system kernel. The resulting Linux kernel has been marked by constant growth throughout its history. Since the initial release of its source code in 1991, it has grown from a small number of C files under a license prohibiting commercial distribution to the 4.15 version in 2018 with more than 23.3 million lines of source code,
Linus Torvalds studies UNIX OS and MINIX(developer by Andrew Tenenbaum) and developed a kernel called LINUX.
In between 1991 and 1995 there was a movement going on Free software movement- GNU.
Linux is a kernel.
As we know an OS is a mix of kernel and softwares. So OS was developed using linux kernel and GNU softwares.
Many companies created their own version of OS using linux kernel.
Examples:
Linux is a kernel not O.S Linux is not a Unix derivative, it was written from scrath. A linux distribution is the linux kernel and a collection of softwares that together create an OS.
Linux features
File System Hierarchy
Top level root directory
- /root
Home directory for root user. - /home
Home directory for other users. - /boot
Contains bootable files for linux. >POST: Power on Self Test - /etc
Contains all configuration files. - /usr
by default softwares are installed in this directory. - /bin
(binary)Contains commands used by all users. - /sbin
(system binary)Contains commands used by only root user. - /opt
Optional application software packages. - /dev
Essential device files, include terminal devices, usb or any deviice attached to the system.
Linux basic commands
- cat :- we can create or see the content but can't edit the file.
- touch :- create empty file,create multiple empty files.
- vi/vim :- it's an editor
- nano :- it's also an editor
$ cat > file.txt
>ctrl+d to exit
$ touch file1.txt file2.txt file3
$ vi files.txt
$ nano file5.txt
$ sudo su
super user do switch user
The cat command is one of the most universal tools, yet all it does is copy standard input to standard output.
we can make use of cat command for following tasks:
- create file- creating single file
bash $ cat > file.txt # check content of file $ cat file.txt
- Concatenate file- to add more than one file into a single file(We can't edit file but we can concatenate something in existing file)
bash $ cat >> file.txt
- Copy files- To copy the content of file1 into file2
bash $ cat file1 file2 > all.txt
- Create an empty file
bash $ touch file.txt
- create multiple empty files
bash $ touch file1 file2 file3
- Change all timestamp of a file
bash $ touch file.txt
- Update only access time of a file, modify time of file
bash $ touch -a file.txt #change access time $ touch -m file.txt #change modify time
Time Stamp
- Access Time(last time when a file was accessed)
- Modify Time(last time when file was modified)
- Change Time(last time when file metadata was changed)
How to check time stamp of file
$ stat file.txt
- A programmer's text editor
- It can be used to edit all kinds of plain text, it is specially useful for editing programs. Mainly used for unix programs.
bash $ vi file.txt
- :w -- To save
- :wq or :x -- To save & quit
- :q -- To quit
- :q! -- force quit not save
$ nano file.txt
For quit - ctrl+X
$ mkdir dir1
# Create directory inside a directory
$ mkdir dir1/dir2/dir3
$ ls
# also hidden files
$ ls -a
$ cd dir1
# go back parent dir
$ cd ..
$ pwd
# print working directory
$ cp file1 file2
$ cp file.txt dir1/dir2/
$ mv file dir1
$ mv file1 file3
$ mkdir .dir1
$ touch .file.txt
# remove file
$ remove file.txt
# remove the specified dir
$ rmdir dir1
# remove both parents and child dir
$ rmdir -p
# remove all the parents and subdirectories along with verbrox
$ rmdir -pv
# remove even non-empty file and directory
$ rm -rf
# Remove non-empty dir including parents and subdirectory
$ rm -rp
# remove empty directories
$ rm -r
# to see head content of any file
$ head file.txt
# last content of file
$ tail file.txt
# more content
$ more file.txt
# Check history
$ history
Some advance commands
- hostname
- ifconfig, cat /etc/os-release
- yum install httpd
- yum remove httpd
- yum update httpd
- service httpd start
- service httpd status
- chkconfig httpd on
- chkconfig httpd off
- which
- whoami
- echo
- yum list installed
$ hostname
$ ifconfig # check ip address
$ cat /etc/os-release # which os version
yum is a package, yellowdog updatter modified used to install softwares or uninstall softwares or packages. httpd will install apache also
$ yum install httpd
# remove package
$ yum remove httpd
# update package
$ yum update httpd
$ service httpd start
$ service httpd status
# automatically start httpd when open computer
$ chkconfig httpd on
$ chkconfig httpd off
# find location of package, installed or not
$ which terraform
$ whoami
# print on screen
$ echo Hello
- for finding specific content
# find root in /etc/passwd directory
grep root /etc/passwd
- sort file content or data in alphabetical sorting format
sort filename.txt