Date: 14-Oct-2014 LINUX and Vi Editor Vinit S Bhosle

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
5 Basic utilities When a user logs in to the Linux operating system the directory that they will start in is their home directory. Most users will have.
Exploring the UNIX File System and File Security
Linux Linux File System.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Linux Commands LINUX COMMANDS.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
File System and Directory Structure in Linux. What is File System In a computer, a file system is the way in which files are named and where they are.
Brief introduction to UNIX A. Emerson CINECA, High Performance Systems.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
The file structure and related utilities CS240 Computer Science II.
Manage Directories and Files in Linux
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Unix Basics Chapter 4.
The UNIX development environment CS 400/600 – Data Structures.
Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
HKOI 2012 TRAINING INTRO TO LINUX /CUHK/SHB123]$ date Sat Feb 18 13:00:00 HKT 2012.
Chapter Two Exploring the UNIX File System and File Security.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Linux file system "On a UNIX system, everything is a file; if something is not a file, it is a process." Sorts of files (on a Linux system) Directories:
Manage Directories and Files in Linux. 2 Objectives Understand the Filesystem Hierarchy Standard (FHS) Identify File Types in the Linux System Change.
Chapter Two Exploring the UNIX File System and File Security.
1May 16, 2005 Week 2 Lab Agenda Command Line FTP Commands Review More UNIX commands to learn File name expansion - * Introduction of vi.
E X C E E D I N G E X P E C T A T I O N S Basic LINUX Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Directory structure:
1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
SUSE Linux Enterprise Desktop Administration Chapter 7 Manage Directories and Files.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
LINUX Zhengli Zhu, School of Life Sciences. Outline 1. ABC of Linux 2. Basic orers of Linux 3. Bash Programming.
Linux Administration – Finding You Way on the Command Line The Linux File Directory or Tree.
Linux 201 Training Module Linux Adv File Mgmt.
Tutorial of Unix Command & shell scriptS 5027
Quality Thought Technologies
Getting started with CentOS Linux
Linux 101 Training Module Linux Basics.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Linux file system "On a UNIX system, everything is a file;
Basic Commands ls cp ls –l (in detail format) echo ls –a
Some Linux Commands.
C151 Multi-User Operating Systems
Vi Editor.
Vim.
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Exploring the UNIX File System and File Security
Tutorial of Unix Command & shell scriptS 5027
Getting started with CentOS Linux
Linux Shell Script Programming
Linux Commands LINUX COMMANDS.
January 26th, 2004 Class Meeting 2
Be comfortable with Linux
Presentation transcript:

Date: 14-Oct-2014 LINUX and Vi Editor Vinit S Bhosle

Topics Covered 1.Introduction to Linux 2.File Structure 3.File System commands 4.File Permissions 5.Vi Editor and its modes 6.How to Enter Edit and Exit from Vi mode 7.Working around Vi

Introduction Linux creator– Linus Torvalds Its an Open Source Operating System Source Code Available. User can customized Kernel as per their needs.

File Structure /bin, /usr/bin, /usr/local/bin:- User executables /etc :- Configuration files /root, /home/users:- Home directories /var, /srv, /usr :- Server data /lib, /lib64, /usr/lib, /usr/local/lib:- Shared libraries /boot :- Kernel, Boot loaders /tmp:- Temporary files /proc, /sys :- System information /media, /mnt :- Mount points

Diagram

1. / – Root Every single file and directory starts from the root directory. Only root user has write privilege under this directory. Please note that /root is root user’s home directory, which is not same as /. 2. /bin – User Binaries Contains binary executables. Common linux commands you need to use in single-user modes are located under this directory. Commands used by all the users of the system are located here. For example: ps, ls, ping, grep, cp. 3. /sbin – System Binaries Just like /bin, /sbin also contains binary executables. But, the linux commands located under this directory are used typically by system administrator, for system maintenance purpose. For example: iptables, reboot, fdisk, ifconfig. Description

4. /etc – Configuration Files Contains configuration files required by all programs. This also contains startup and shutdown shell scripts used to start/stop individual programs. For example: /etc/resolv.conf, /etc/logrotate.conf 5. /dev – Device Files Contains device files. These include terminal devices, usb, or any device attached to the system. For example: /dev/tty1, /dev/usbmon0 6. /proc – Process Information Contains information about system process. This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid. This is a virtual filesystem with text information about system resources. For example: /proc/uptime

7. /var – Variable Files var stands for variable files. Content of the files that are expected to grow can be found under this directory. This includes — system log files (/var/log); packages and database files (/var/lib); s (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp); 8. /tmp – Temporary Files Directory that contains temporary files created by system and users. Files under this directory are deleted when system is rebooted. 9. /usr – User Programs Contains binaries, libraries, documentation, and source-code for second level programs. /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel /usr/lib contains libraries for /usr/bin and /usr/sbin /usr/local contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2 Description

10. /home – Home Directories Home directories for all users to store their personal files. For example: /home/john, /home/nikita 11. /boot – Boot Loader Files Contains boot loader related files. Kernel initrd, vmlinux, grub files are located under /boot For example: initrd.img generic, vmlinuz generic 12. /lib – System Libraries Contains library files that supports the binaries located under /bin and /sbin Library filenames are either ld* or lib*.so.* For example: ld so, libncurses.so /opt – Optional add-on Applications opt stands for optional. Contains add-on applications from individual vendors. add-on applications should be installed under either /opt/ or /opt/ sub-directory. Description

14. /mnt – Mount Directory Temporary mount directory where sysadmins can mount filesystems. 15. /media – Removable Media Devices Temporary mount directory for removable devices. For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer 16. /srv – Service Data srv stands for service. Contains server specific services related data. For example, /srv/cvs contains CVS related data. Description

File System commands pwd - report your current directory cd - change your current directory ls -list contents of directory cp - copy mv - move (or rename) rm -delete file(s) mkdir -make a directory mkdir -p /home/vinit/test(Creates a sub directory) rmdir -remove an empty directory man man command gives you help on that command.

ls command ls - list directory contents Usage : ls [OPTIONS] [FILE] OPTIONS -l Use a long listing format -a Do not ignore entries starting with. (for e.g.forward) -h Print sizes in human readable format (e.g., 3K 389M 3G) -d List directory entries instead of contents -R List subdirectories recursively -r Reverse order while sorting -S Sort by file size -t Sort by modification time -1 List one file per line Mostly used options in ls ls -l, ls –la, ls -1, ls -lh, ls -ltr, ls -lS

File Permissions There are 3 kinds of users in linux : UGO UGO : user, group and others. r - Read permissions w - Write permissions x - Execute permissions rwx = 111 in binary = 7 rw- = 110 in binary = 6 r-x = 101 in binary = 5 r-- = 100 in binary = 4

Permission Diagram

777(rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting. 755(rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users. 700(rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others. 666(rw-rw-rw-) All users may read and write the file. 644(rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change. 600(rw ) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Changing File Permissions Make a file readable : $ chmod 765 abc.txt 7 -> 111 -> rwx 6 -> 110 -> rw- 5 -> 101 -> r-x -rwx rw- r-x 1 vinit cccf 224 Oct 14 10:00 abc.txt OR $ chmod +w abc.xt $ chmod o+w abc.xt $ chmod g+x,o+w abc.txt

Changing File Ownership Change who owns a file: $ chown chown vinit:cccf abc.txt chown –R vinit:cccf test Change to which group the file belongs: $ chgrp chgrp cccf abc.txt

copy a directory and its contents to other hosts ID: $ scp -r copy a directory and its contents: $ cp -r Find a pattern in a directory and its subdirectories: $ grep -r Getting Recursive

Redirection Symbols >file Make file the standard output <file Make file the standard input >>file Make file the standard output, appending to it if already exists Redirecting output to a file with > Redirecting input from a file with <

Redirecting examples ls –l > abc.txt Redirects output to abc.txt sort < test.txt Accepts the input from test.txt mail -s “Test subject" <body.txt ls –l vinit.txt 2> error.txt Redirects error to error.txt ls –l vinit.txt 2>&1 error.txt Redirect output and error to error.txt ls –l &> file ls -l &>> test

Piping Pipes take the output of the first program and feed that output into the input of the next program. The output of a command can be piped to another command for further processing Also sometimes known as “filters”. Examples: ls –l | wc –l cat test.txt | more

Login using ssh ssh – remote login program $ ssh –l vinit mailhost.tifr.res.in $ ssh

Copy to remote machine : scp copy local to remote $ scp copy remote to local $ scp -p Preserves mode, time stamps -r Recursively copy entire directories. -v Verbose mode.

More commands grep - grep is global / regular expression / print grep –i vinit /etc/passwd find - search for files in a directory hierarchy report uniq lines find./ -name “*.txt” # Find *.txt files present directory date - date command prints or sets the system date and time date #Tue Oct 14 10:00:10 IST 2014 date -s “14 OCT :00:00" touch – creates the file if it doesn’t exists or changes date stamp to current if exists touch abc.txt #creates empty abc.txt ln - Reference to another file or directory ln –s abc.txt link.txt # creates symbolic link of abc.txt

More commands sort - sort lines of text files sort -nr # sorts according to first field uniq - report uniq lines uniq –c # display the uniq entries with count tee - read from standard input and write to standard output and files find / “abc*.*” 2>&1 | tee –a log.txt #finds files and displays output and erro and tees to log.txt tar – backup / archiving utility tar –cvf abc.tar /usr #create a tar file of /usr directory head - output the first part of files head -10 abc.txt #displays top 10 lines of abc.txt

More commands tail - output the last part of files tail -5 abc.txt # displays last 5 lines of abcd.txt tail –f maillog.log # displays continuously the new appending data. cat - concatenate files and print on the standard output cat a.txt b.txt >>z.txt #appends a.txt and b.txt to z.txt more – view the contents of a text file one screen at a time echo - display a line of text\ tr - translate or delete characters echo “Hello world” | tr '[a-z]' '[A-Z]' # will display HELLO WORLD expr - Evaluate an expression expr 5 \* 2 # multiplies 5 and 2

Starting vi Type vi at the shell prompt After pressing enter the command prompt disappears and you see tilde(~) characters on all the lines These tilde characters indicate that the line is blank

Vi modes There are two modes in vi – Command mode – Input mode When you start vi by default it is in command mode You enter the input mode through various commands You exit the input mode by pressing the Esc key to get back to the command mode

Entering text To enter the text in vi you should first switch to input mode To switch to input mode there are several different commands a - Append mode places the insertion point after the current character i - Insert mode places the insertion point before the current character

Entering text I - places the insertion point at the beginning of current line o - is for open mode and places the insertion point after the current line O - places the insertion point before the current line R - starts the replace (overwrite) mode

Editing text x - deletes the current character d - is the delete command but pressing only d will not delete anything you need to press a second key dw - deletes to end of word dd - deletes the current line d0 - deletes to beginning of line

Copy, cut and paste yy - (yank) copy current line to buffer nyy - Where n is number of lines p - Paste the yanked lines from buffer to the line below P - Paste the yanked lines from buffer to the line above

Undo and repeat command u - undo the changes made by editing commands. (dot or period) repeats the last edit command

How to exit from vi First go to command mode press Esc There is no harm in pressing Esc even if you are in command mode. Your terminal will just beep and/or or flash if you press Esc in command mode There are different ways to exit when you are in the command mode

How to exit from vi (command mode) :q is to exit, if you have not made any changes to the file :q! is the forced quit, it will discard the changes and quit :wq is for save and Exit :x is same as above command The ! Character forces over writes, etc. :wq!

Working around You can move around only when you are in the command mode. Arrow keys usually works. The standard keys for moving cursor are: h - for left l - for right j - for down k - for up

Working around w - to move one word forward b - to move one word backward $ - takes you to the end of line takes the cursor to the beginning of next line

Working around - - (minus) moves the cursor to the first character in the current line H -takes the cursor to the beginning of the current screen(Home position) L -moves to the Lower last line M -moves to the middle line on the current screen

Working Around ) - moves cursor to the next sentence } - move the cursor to the beginning of next paragraph ( - moves the cursor backward to the beginning of the current sentence { - moves the cursor backward to the beginning of the current paragraph

Working Around Control-d scrolls the screen down (half screen) Control-u scrolls the screen up (half screen) Control-f scrolls the screen forward (full screen) Control-b scrolls the screen backward (full screen). xG- to go at x line G- takes you to bottom line of file gg- takes you to first line

Creating a shell script using vi Create a directory class Change into class vi myscript.sh inside the file enter following commands clear echo "===========" echo "Hello World" echo "===========" sleep 3 clear echo Host is $HOSTNAME echo User is $USER

Creating a shell script using vi Save the file Change the permissions on myscript.sh chmod 700 myscript.sh Now execute myscript.sh./myscript.sh The./ mean right here in this directory!

THANK YOU