+ All Categories
Home > Documents > UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which...

UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which...

Date post: 22-Dec-2015
Category:
Upload: martin-clark
View: 248 times
Download: 8 times
Share this document with a friend
Popular Tags:
47
UNIX/LINUX OPERATING SYSTEM
Transcript
Page 1: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

UNIX/LINUX OPERATING SYSTEM

Page 2: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

UNIX/LINUX Commands

Linux Commands

A command is a program which interacts with the kernel to provide the environment and perform the functions called for by the user.

A command can be: a built-in shell command; an executable shell file, known as a shell script; or a source compiled, object code file.

The shell is a command line interpreter. The user interacts with the kernel through the shell. You can write ASCII (text) scripts to be acted upon by a shell.

It reads the terminal input and translates the commands into actions taken by the system. The shell is analogous to command.com in DOS.

Page 3: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

UNIX ShellLinux Commands

The original shell was the Bourne shell, sh.

Every Unix platform will either have the Bourne shell, or a Bourne compatible shell available.

The default prompt for the Bourne shell is $ (or #, for the root user).

Another popular shell is C Shell. The default prompt for the C shell is %.

Page 4: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Shell ProgrammingLinux Commands

You can write shell programs by creating scripts containing a series of shell commands.

The first line of the script should start with #! which indicates to the kernel that the script is directly executable.

You immediately follow this with the name of the shell, or program (spaces are allowed), to execute, using the full path name. So to set up a Bourne shell script the first line would be: #! /bin/sh

The first line is followed by commands#!/bin/bashcd /tmpmkdir t

You also need to specify that the script is executable by setting the proper bits on the file with chmod, e.g.:

$ chmod +x shell_script

Page 5: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

LINUX COMMANDSLinux Commands

File Management and Viewing Help, Job and Process Management Network Management System Management User Management Miscellaneous

Page 6: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Command StructureLinux Commands

Command <Options> <Arguments>

Multiple commands separated by ; can be executed one after the other

Page 7: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Help Facilities for CommandsLinux Commands

To understand the working of the command and possible options use (man command)

Using the GNU Info System (info, info command)

Many tools have a long−style option, `−−help', that outputs usage information about the tool, including the options and arguments the tool takes. Ex: whoami --help

Page 8: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

PipesLinux Commands

An important early development in Unix was the invention of "pipes," a way to pass the output of one tool to the input of another.

eg. $ who | wc −l

By combining these two tools, giving the wc command the output of who, you can build a new command to list the number of users currently on the system

Page 9: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

QUESTIONS?

Page 10: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Listing the Content of a DirectoryIntroduction to Linux

ls is used to list the contents of a directory.

If the command ls is written with parameter –l then the command lists contents of the working directory with details. Example:

$ ls –l

Page 11: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Moving in DirectoriesIntroduction to Linux

cd try_it Changes the directory to try_it pwd Prints present working directory (e.g. /home/smith/try_it) cd .. Move to superior directory pwd : Prints /home/smith cd /home The absolute path pwd : Prints /home cd The system is returned to the user home directory pwd : Print /home/smith

Page 12: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Make DirectoryIntroduction to Linux

The command mkdir test

makes new directory test (the path is given relative) as a subdirectory of the current directory.

Page 13: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Remove DirectoryIntroduction to Linux

The command rmdir your_dir

removes directory your_dir if it is empty.

The command rm –rf is used to delete a non empty directory

Page 14: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Copy FileIntroduction to Linux

The command cp file_1 file_2

copies file_1 to file_2. The both files must be in the same working directory. If they are in various directories, the path must be given.

Page 15: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Rename and/or Move the FileIntroduction to Linux

The command mv file_1 file_2

moves file_1 to file_2

The both files must be in the same working directory.

If they are in different directories, the path must be given.

The file_1 is removed from the disk.

Page 16: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Remove FileIntroduction to Linux

The command rm file_a

removes the file_a from the system

If you use wildcard. For example

rm h*c

you will remove all files beginning with h and ending with c which are in working directory.

If you write

rm *

you will erase all files from your working directory.

Page 17: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Access Permission of File/Directory

Introduction to Linux

The ownership of the file or directory can be changed using the command

chown <owner> <file/directory name>

The group of the file or directory can be changed using the command

chgrp <group> <file/directory name>

The permissions of the file can be changed using chmod command

chmod -R ### <filename or directory>

-R is optional and when used with directories will traverse all the sub-directories of the target directory changing ALL the permissions to ###.

Page 18: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Access Permission of File/Directory

Introduction to Linux

The #'s can be: 0 = Nothing

1 = Execute2 = Write3 = Execute & Write  (2 + 1)4 = Read5 = Execute & Read (4 + 1)6 = Read & Write (4 + 2)7 = Execute & Read & Write (4 + 2 + 1)

Page 19: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

QUESTIONS?

Page 20: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux File Management and Viewing

Linux Commands

find Find files (find <start directory> -name <file name> -print)

Ex: find /home –name readme -print (Search for readme starting at home and output full path.)

“/home" = Search starting at the home directory and proceed through all its subdirectories

"-name readme" = Search for a file named readme "-print" = Output the full path to that file

locate File locating program that uses the slocate database. Ex: locate –u to create the database, locate <file/directory> to find file/directory

Page 21: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux File Management and Viewing

Linux Commands

File viewing and editing

vi Editor with a command mode and text mode. Starts in command mode.

gedit GUI Text Editor

tail Look at the last 10 lines of a file.

Ex: tail -100 <filename> (looks at last 100 lines)

head Look at the first 10 lines of a file. (head <filename>)

Page 22: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux File Management and Viewing

Linux Commands

cat View a file

Ex: cat filename

grep List all files with the specified expression. (grep pattern <filename/directorypath>)

Ex: ls –l |grep sidbi : List all lines with a sidbi in them.

Ex: grep " R " : Search for R with a space on each side

sleep Delay for a specified amount of time.

sort Sort a file alphabetically.

uniq Remove duplicate lines from a sorted file.

wc Count characters, words and lines in a file. (wc –c/w/l <filename>).

Page 23: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Network Management CommandsLinux Commands

ping Send ICMP ECHO_REQUEST packets to network hosts. (ping <remote-host-name/ip>)

ssh Secure Login (ssh <remote system name/ip>)

telnet User interface to the TELNET protocol, setting up a remote console session. (telnet <remote system name/ip>)

tcpdump Dump traffic on a network. Prints out headers of packets that match the boolean expression. (tcpdump eth0)

traceroute Print the route that packets take to the specified network host. (traceroute <remote system name/ip>)

Page 24: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

System Management CommandsLinux Commands

shutdown If your system has many users, use the command shutdown -h +time ‘<message>`, where time is the time in minutes until the system is halted, and message is a short explanation of why the system is shutting down.

Ex: # shutdown -h +10 'We will install a new disk. System should be back on-line in three hours’.

passwd Set a user's pass word. (passwd, passwd <username>)

Page 25: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

System Management CommandsLinux Commands

su Single user login. (su -)

who Display the users logged in.

whoami Print effective user id.

Page 26: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux Job & Process Management

Linux Commands

Linux Process Management

ps Get the status of one or more processes.

PPID-parent process ID ; PID-process ID

Eg: ps ax |more to see all processes including daemons

Eg : ps –ef | grep <process>

top The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel

Page 27: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux Job & Process Management

Linux Commands

Linux Process Management

kill Ex: "kill 34" - Effect: Kill or stop the process with the process ID number 34.

killall Kill processes by name.

pid Find the process ID of a running program

Page 28: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

QUESTIONS?

Page 29: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

SYS ADMIN TASKSLinux System Administration

Setting the Run LevelSystem ServicesUser ManagementNetwork SettingsScheduling JobsBackup and RestoreAdding and Removing software/packagesMonitoring the system (general, logs)

Page 30: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Init RunlevelsLinux System Administration

The following runlevels are defined in Linux:

0 - halt (Do NOT set initdefault to this)1 - Single user mode2 - Multiuser, without Network (The same as 3, if you do not have networking)3 – Text Mode4 - unused5 – Graphical Mode6 - reboot (Do NOT set initdefault to this)

Page 31: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Init RunlevelsDesktop Configuration

The default runlevel for a system to boot to is configured in /etc/inittab.

id:5:initdefault:

In GUI: Applications System Settings Server Settings Services

Generally, Linux operates in runlevel 3 or 5.

Page 32: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux Services

Linux System Administration

There are 113 deamons, each for a service or application. Some examples are:

httpd : Apache Web server

mysqld : MySQL server

named : DNS server

network : Networking

nfs : Network File Share

ntpd : NTP (Network Time Protocol) server

Page 33: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux Services

Linux System Administration

Start/Stop boot time services in /etc/rc.d/rc3.d or /etc/rc.d/rc5.d

All services startup scripts which start with S will start at boot time and all startup scripts which start with K will not start at boot time. The number after S or K is the priority.

K95kudzu

K96pcmcia

S56xinetd

S60vsftpd

Use

service <service name> start/stop/restart

to start, stop or restart a service from command line

Page 34: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.
Page 35: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Creating a new User AccountLinux System Administration

Add an entry in /etc/passwd and /etc/shadow file (use next uid and suitable gid). You will have to create the user directory and assign a password to the user

Use useradd or adduser command to create a new user (useradd –g <group> -d <home directory> -c <comment> -s <shell> login-name) and groupadd to create a new group (groupadd group-name). You will have to assign a password (passwd login-name)

In GUI: Applications System Settings Users and Groups

Page 36: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.
Page 37: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

/etc/passwd and /etc/shadow File

Linux System Administration

/etc/passwd Holds user account info

Included fields are: Login name

User Id (uid)

Group Id (gid)

General Comment about the user

Home Directory

Shell /etc/shadow Contains the encrypted password information for users' accounts and optionally the password aging information.

Page 38: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Removing a User AccountLinux System Administration

userdel –r <username>

Remove login id from /etc/passwd & /etc/shadow file and delete home directory

Use GUI to Delete the user

Page 39: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

QUESTIONS?

Page 40: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux Network Configuration

Linux System Administration

/etc/resolv.conf Tells the kernel which name server should be queried when a program asks to "resolve" an IP Address.

nameserver 172.31.1.1

search cc.iitk.ac.in iitk.ac.in

/etc/sysconfig/network Indicates networking is enabled (NETWORKING=yes) and provides information on hostname, gateway and nis domain.

NETWORKING=yes

HOSTNAME=webhome.cc.iitk.ac.in

GATEWAY=172.31.1.250

Page 41: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Linux Network Configuration

Linux System Administration

/etc/sysconfig/network-scripts/ifcfg-eth0 Network configurations like boot protocol (static/dhcp), ip address, netmask, network address, broadcast address etc.

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=static

IPADDR=172.31.1.40

NETMASK=255.255.0.0

BROADCAST=172.31.255.255

NETWORK=172.31.0.0

GATEWAY=172.31.1.250

Page 42: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.
Page 43: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Scheduling Jobs: CronLinux System Administration

Cron is a program that enables you to execute a command, or a script with a sequence of commands, at a specified date, time or at set intervals.

Add the job script in /etc/cron.hourly or /etc/cron.daily or /etc/cron.weekly or /etc/cron.monthly to schedule a job

Page 44: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Backup & RestoreLinux System Administration

Backup the user area or configuration file

Use tar to take backup on a different disk or tape

Backup can be scheduled using cron

Backup: tar –zcvf <tar filename> <Directory Tree to be backedup>

Restore: tar –zxvf <tar filename> <file to be recovered>

Backup should be occasionally checked by restoring it

Backup Policy: Full Backup every weekly/fortnightly and incremental backup every day

Page 45: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Adding & Removing SoftwareLinux System Administration

Download a binaryDownload the source code and compile on the system (download, untar, configure, make, make install, make uninstall)Use RPM - Redhat Package Manager and install rpms www.rpmseek.com & www.rpmfind.net can be used to search and download rpms (i386 Binary RPMs or SRC RPMs)For Binary rpms: rpm [options] rpm-file(rpm –qa, rpm –ivh, rpm –Uvh, rpm -e)Where -q= query, -a= all, -i=install, -v=verbrose, -U= upgrade, -h= hash, -e= eraseFor Source rpms: rpmbuild –rebuild rpm-source-fileCompiled binary rpms will be available at /usr/src/redhat/RPMS/i386 which can be installed

Page 46: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

Monitoring the SystemLinux System Administration

Monitor Disk Usage (df)

Monitor CPU and Memory utilization (top)

Monitor process/services (ps, pgrep)

Monitor logs (/var/log/messages)

GUI Tool (Applications System Tools System Performance)

Page 47: UNIX/LINUX OPERATING SYSTEM. UNIX/LINUX Commands Linux Commands A command is a program which interacts with the kernel to provide the environment and.

QUESTIONS?


Recommended