Linux basics part 1

25

Transcript of Linux basics part 1

Page 1: Linux basics part 1
Page 2: Linux basics part 1

LINUXLinux OverviewSHELLDirectory StructureBasic CommandsText Editor for linuxUser and Group ManagementPermissionsGRUBTAR file RPMNetworking (Assign IP)Hard Disk Management

Page 3: Linux basics part 1

LINUXLinux is an operating system based on UNIX, and was first introduced by Linus Torvalds commonly used in servers.

It is based on the Linux Kernel, and can run on different hardware platforms manufactured by Intel, MIPS, HP, IBM, SPARC and Motorola. Another popular element in Linux is its mascot, a penguin figure named Tux.

• It’s free and available in open source.

Open source: Open source is a platform that allows you to distribute your software, including source codes freely to anyone who is interested. People would then be able to add features and even debug and correct errors that are in the source code. They can make it run better by adding some new features and then redistributes these enhanced source code freely again. This eventually benefits everyone in the community.

Page 4: Linux basics part 1

SHELLThe shell is a program that takes keyboard commands and passes them to the operating system to carry out. Almost all Linux distributions supply a shell program from the GNU project called BASH.

BASH: the name “BASH” acronym for “Bourne Again Shell”. It was written by Steve Bourne as a replacement to the original Bourne Shell (represented by /bin/sh). It combines all the features from the original version of Bourne Shell, plus additional function to make it easier and more convenient to use. It has since been adapted as the default shell for the most system running shell.

Terminal Emulators: When using a graphical user interface we need another program called a terminal emulator to interact with the shell. It’s likely called simply “terminal” on our menu.Launch the terminal:

[root@localhost ~] #

This is called a shell prompt and it will appear whenever the shell is ready to accept input.

Page 5: Linux basics part 1

Directory Structure• /bin : normal command execution directory• /sbin : administrative command execution directory• /boot : boot loader directory it contains GRUB• /etc : configuration file directory• /proc : current process info directory• /media: external media device mount point• /mnt : network or local mount point• /opt : third party software installation directory• /usr : entire installation and own software installation

directory• /lost+found : recovery directory• /selinux : security directory• /var : log directory• /root : root user home directory• /home:normal user home directory

In Linux “/” work as a

drive, as C: in Windows

Page 6: Linux basics part 1

BASIC CommandsGenerally we use two prompts in Linux :1. # : root user (Administrative authentication)2. $ : normal user (restricted authentication)

# lsList command to show the content of directory

# ls -l To get detailed list of directory content

# ls -aTo get the list of all file/dir including hidden object.

# pwdPrint working directory

# mkdir <dirname>To create a directory

Structure of command in Linux:# <command> - <option> <arguments> [* always use “–” before option]

Page 7: Linux basics part 1

BASIC Commands

# mkdir -p <dir1>/<dir2>/<dir_n>To create parent directory

# mkdir <dir> <dir2> <dir_n>To create multiple directory

# touch <filename> To create a new file

# touch <file1> <file2> <file_n>To create multiple file

# cd <dir name>To change directory

# cd ..To close any directory

# cat <file name>To view the data of any file

Page 8: Linux basics part 1

BASIC Commands

# cat > <file name>To input data in file with input mode

# cat >> <file name>To input data in file with append mode

# rm -r <file/dir name>To delete file/dir

# rm -rf <file/dir name>To delete file/dir forcefully

# cp -rv <source> <destination>To copy file/dir and paste

# mv <source> <destination>To move/cut a file/dir and paste

# man <command name>To get the help of command

Page 9: Linux basics part 1

BASIC Commands

# <command name> --helpTo get brief details of command

# which <command name>To get the location of command execution

# who To get the info of logged-in user

# haltTo shutdown

# rebootTo restart

Page 10: Linux basics part 1

Text Editor

Text editor is a software to create or edit text files.Text editor can be GUI and CLI.

GUI text editor used in Linux:1. Gedit2. Leafpad

CLI text editor used in Linux:3. Vi4. Vim5. Nano6. emacs

VI (Visual Editor)vi or vim is a terminal text editor.

Commands:

# vim <file name>To create or edit existing file

Page 11: Linux basics part 1

Text Editor

There are three modes in vi editor1. Command mode (default mode)2. Insert mode3. EX mode

1. Command Mode (ESC) : It is used to do cut, copy, paste.

yy : to copy a line<num> yy : to copy multiple linesyw : to copy a worddd : to cut a lineD : to delete a line<num>D : to delete multiple lines<num>dd : to cut multiple linesdw : to cut a wordp : to paste

Page 12: Linux basics part 1

Text Editor

2. Insert Mode (to enter in insert mode press i or a)data input or edit mode.

3. EX mode (to enter in EX mode press ESC then SHIFT + : )This mode is used for file saving and quieting.: w : to save: q : to quit: wq : to save and quit: w! : to save forcefully: q! : to quite forcefully:/<find word> : to search any word:;%s/<find word>/<replace word>/g : to replace

any word: set nu : to set line number: set nonu : to unset line number

Page 13: Linux basics part 1

User Group Management

User : Users are the login account through which we can access the resources and features of an operating system.Group : Groups are the place where user accounts are placed for security and policy implementation.Important file locations:

/etc/passwd : users details file/etc/shadow : users encrypted password file/etc/group : groups details file

Commands:

# groupadd <group name>To create new group

# useradd <user name>To create new user

Page 14: Linux basics part 1

User Group Management# passwd <user name>To create or change user password

# useradd -g <primary group> -G <sec group1> <sec group2> <username>To create a user with specific primary group and secondary group.[-g : Primary group, -G : Secondary group]

# usermod -g <groupname> <existing name>To modify primary group name

# usermod -G <groupname1>,<groupname2> <existing user name>To change or modify secondary group

# useradd -d “directory name with location” <user name>To give a new home directory

# useradd -c “comment” -g <groupname> <username>To give comment for a user

# usermod -c “comment” <user name>To change or modify user comment

Page 15: Linux basics part 1

User Group Management

root : x : 0 : 0 : root : /root : /bin/bash

root : user namex : link to shadow file0 : user ID0 : Group (primary) IDroot : comment of user/root : home directory of user/bin/bash : user shell

# useradd -s /sbin/nologin <username>To create no-login user

# userdel -r <user name>To delete user

# groupdel <group name>To delete group (firstly delete group members)

Page 16: Linux basics part 1

PermissionsIt is used to implement access control on objects (files and dir) of operating system.

There are three permission in Linux1. Read r 42. Write w 23. Executex 1

# ls -l or llTo check the permissions of any file/dir

# chmod UGO <file/dir>To give or change permissions

# chmod -R UGO <file/dir>To give or change permissions of sub file/dir (parent file/dir)

Each objects (file/dir) have three pairs of permissionsLike: rwx rwx rwx

user group others

Page 17: Linux basics part 1

Permissions# chmod -R <user>:<group> <file/dir>To change the ownership

Default permission

Root User:File : 644Dir : 755User home dir : 700

Normal User:File : 664Dir : 775

Page 18: Linux basics part 1

GRUBIt is the boot loader for the linux. GRUB is short for GNU Grand Unified Boot Loader.Location of Grub file is :

/boot/grub/grub.conf : Original file/etc/grub.conf : shortcut file

We can reset boot user password using two methods:1. Single user mode (Using grub menu)2. Rescue mode (Using linux DVD)

# grub-md5-crypt : to create encrypted password

Page 19: Linux basics part 1

TAR (Tap Archiver)It is used for making TAR and compressed file. It is like making zip file and rar files in windows. It also considered as backup and restore method.

Commands:

# tar -cvf <output.tar> <input folder>To create a tar file

# tar -tvf <filename.tar>To check the contents of tar file

# tar -xvf <filename.tar>To extract the contents of tar or compressed file

# tar -zcvf <output.tar.gz> <input.tar>To create compressed tar file

# tar -jcvf <output.tar.bz2> <input.tar>To create compressed .bz2 tar file

Page 20: Linux basics part 1

RPM (Redhat Package Manager)RPM is used to install packages in Redhat Linux OS. The extension of Redhat Linux package is .rpm like .exe in windows.

Note: RPM command do not resolve dependency packages automatically.

Commands:

# rpm -ivh <packagename.rpm>To install package

# rpm -e <software name>To uninstall package/software

# rpm -qa To get the list of all installed software

# rpm -qa grep <keyword>To get the list of installed software using filter

# rpm -qi <softwarename>To get info of all installed software

Page 21: Linux basics part 1

RPM (Redhat Package Manager)

# rpm -ql <software name>To get the list of file/dir copied to system and its location by package

# rpm -qf <file/dir name>To know the responsible package name of file/dir

# rpm -ivh --force --nodeps --aid <package name>To install any package forcefully

Page 22: Linux basics part 1

Networking

It is assign used to assign IP address in our OS.

We can assign IP in two ways1. Temporary IP setting

2. Permanent IP setting (using manual and DHCP)

Commands:# ifconfig

To check the IP address and interface

# ifup <interface name>To enable LAN interface

# ifdown <interface name>To disable LAN interface

# hostnameTo check the hostname of computer

Page 23: Linux basics part 1

Networking# hostname <newhostname>

To change the hostname

# ifconfig <interface> <ipadress>To assign IP

# route add default gw <gateway IP>To assign gateway IP

# vim /etc/resolv.confnameserver <DNS1 IP>nameserver <DNS2 IP> : to assign DNS IP

:wq

Temporary IP setting

Permanent IP setting# system-config-network

To assign IP, Netmask, Gateway, Hostname, DNS1, DNS2 etc.# service network restartTo restart the service of network

Page 24: Linux basics part 1

NetworkingImportant Files:

/etc/sysconfig/network-scripts/ifcfg - <interface>This file contains IP, Netmask, Gateway, MAC etc

/etc/sysconfig/networkThis file contains hostname /etc/resolv.confThis file contains DNS IP /etc/hosts

Local DNS entry file

Page 25: Linux basics part 1

Harddisk ManagementIt is used to configure and maintain HDD partitions, volumes and file system in Linux OS.

Commands used in HDD management# fdisk -l

# fdisk <hdd file name>To enter in HDD management mode

Commands used in HDD management mode:: m : for all command and details

To check the partition table and HDD details

: p : for print current partition table: n : to create new partition or volumes: t : to change file system table: l : to list file system hex code: d : to delete a partition: w : to save and quit: q : to quit without saving

# mkfs.ext4 <partition_name>To format Linux partition

After any changes

done using fdisk

command, Restart is

compulsary

# mkfs.vfat <partition_name>To format windows partition in Linux