Linux
Linux is a free, open source operating system, released under the GNU General Public License (GPL). Anyone can run, study, modify, and redistribute the source code, or even sell copies of their modified code, as long as they do so under the same license.
Linux has become the largest open sources software project in the world. Professional and hobbyist programmers from around the world contribute to the Linux kernel, adding features, finding and fixing bugs and security flaws, and providing new ideas—all while sharing their contributions back to the community.
What is an Operating System ?
An operating system is the software that directly manages a system’s hardware and resources, like CPU, memory, and storage. The OS sits between applications and hardware and makes the connections between all of your software and the physical resources that do the work.
What is Kernel ?
The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system. It is the portion of the operating system code that is always resident in memory, and facilitates "interactions" between hardware and software components. Kernel is regarded as the heart of any Operating System.
Linux and DevOps:
Linux offers the DevOps team the flexibility and scalability needed to create a dynamic development process. You can set it up any way that suits your needs. Rather than letting the operating system dictate how you work, you can configure it to work for you. There’s no greater freedom than that, and there is no better asset for DevOps teams then a Linux OS that supports the process at scale.
Basic Linux commands for DevOps:
Commands to create files:
cat, touch, vi/vim, nano
ctrl+d is used to exit command mode.
cat:
tac (to see content reversely) use "cat" to see content as it is.
cat >file1 (Add content in empty file)
cat >> file1 (Add more content in non-empty file)
cat file1 file2 >file (concatenate two files content into new file)
cat file1 >file2 (to copy content of file1 into file2)
touch: (Touch command's main purpose is Time stamp)
stat file1 (used to see time stamp of a file)
touch file1 (create file)
touch file2 file3 (create multiple files simultaneously)
touch -a (to change access time stamp)
touch -m (to change modify time stamp)
Vi editor:
vi file1 (Edit file1)
press i then insert data and then press esc & then
:w (to save)
:wq (to save & quit)
:q (quit)
:q! (no save, force quit)
nano editor:
nano fileb
ctrl+x (to leave) and then press Y
to update file content at end press ctrl+o and then ctrl+x
How to create a new directory:
mkdir dir1 (Create dir)
mkdir -p dir2/dir3 (To make nested directories)
mkdir dir5 dir6 (To create multiple directories simultaneously)
How to change directory:
cd dir2 (Change directory)
cd.. (To go back in parent directory/moves back 1 point)
use "pwd" (To check current location)
cd ../../.. (To move back 3 points)
How to create hidden files/directories:
touch .file1 (create hidden file)
mkdir .dir8 (create hidden directory)
ls -a (show everythings hidden/normal)
How to copy a file:
cp file1 file2 (file1 will overwrite file2)
How to cut & paste file:
mv file1 dir1 (Move file to dir)
Recommended by LinkedIn
mv dir1 dir2 (Move dir into dir)
mv file1 myfile (rename file name)
How to remove a file/directory:
rmdir dir1 (removes empty dir)
rmdir -p dir1/dir2 (remove both parent&child dir's)
rmdir -pv (removes all parent/subdir along with verbrose)
rm -rf (removes non-empty file & directory)
rm -rp (removes non-empty directories including parent/subdir)
rm -r (removes empty directories)
Miscellaneous:
hostname
hostname -i (to check ip)
ifconfig (display only ip address of linux machine)
cat /etc/os-release (to check os-version)
yum install httpd -y (Install apache server)
yum remove httpd (remove installed pkg)
yum update httpd (updates the required pkg)
yum list installed (Display list of installed pkg's)
service httpd start (To start the services of a pkg)
service httpd status (Check service status)
chkconfig httpd on (turn on services at run-level)
chkconfig httpd off (turn off services at run level)
which chef (check whether pkg is installed)
whoami (Shows user name like root user)
echo "Hello" (To display message on screen)
echo "welcome" >file1 (Saves content in file)
echo "hello" >>file1 (update file content)
echo >file1 (removes file content)
grep Ali /home/ec-user (search out name "Ali" in ec2-user)
sort (sort file content alphabetically)
less
more
head
tail
tree
Administrative Commands:
useradd sohaib (user added)
cat /etc/passwd (Check user is added or not ?)
groupadd techgf (Group added)
cat /etc/group (check group is created or not ?)
gpasswd -a sohaib techgf (add user in group)
gpasswd -M Ali, Ahmed techgf (add multiple users in group)
ln file1 backupfile1 (hardlink to create backup)
ln -s file1 softfile1 (softlink to create shortcut)
tar -cvf dirx.tar dirx (used for zipping)
gzip dirx.tar (used to compress)
gunzip dirx.tar.gz (used to uncompress)
tar -xvf dirx.tar (used to unzip/extract)
wget <url> (used to download pkg's)
Access modes/Permissions:
chmod 734 dirx (change permissions for owner,group & others by using digits)
chmod u=r,g=rwx,o=wx file1 (change permissions by using alphabets)
chown sohaib file1 (Change owner/user of file)
chgrp devops file1 (Change group of file)