0% found this document useful (0 votes)
24 views

Linux Introduction

Uploaded by

dhananjay patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Linux Introduction

Uploaded by

dhananjay patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Linux Essentials

Linux Origins

• 1984: The GNU Project and the Free


Software Foundation
– Creates open source version of UNIX utilities
– Creates the General Public License (GPL)
– Software license enforcing open source
principles
• 1991: Linus Torvalds
– Creates open source, UNIX-like kernel,
released under the GPL
Linux Distributions
• Linux Distributions:
– Redhat
– Suse
– Mandrake
– Caldera
– Ubuntu
– Debian etc
• Shell is an interface between user and OS
• Kernel is the core of OS. It receives requests
called system calls from programs and initiates
processes that carryout these requests
Logging in to a Linux System

• Tw o t y p e s o f l o g i n s c r e e n s : v i r t u a l
consoles (text-based) and graphical logins
(called display managers)
• Login using login name and password
• Each u s e r has a h o me d i r e c t o r y f o r
personal file storage
• Everything is a file (including hardware)
Switching between virtual consoles

• A typical Linux system will run six virtual


consoles and one graphical console
• Switch among virtual consoles by typing:
Ctrl-Alt-F[1-6]
• Access the graphical console by typing
Ctrl-Alt-F7
The root user

• The root user: a special administrative


account
• Also called the superuser
• Do not login as root unless necessary
• sudo command runs command as root
Running Commands

• Commands have the following syntax:


command options arguments
• Each item is separated by a space
• Multiple commands can be separated by ;
● date - display date and time
● cal - display calendar
Getting Help

• Don't try to memorize everything!


• Many levels of help
– whatis
– command --help
– man and info
Help Manuals
• Displays short descriptions of commands
• Often not available immediately after
install
$ whatis cal
cal (1) - displays a calendar
• The --help Option
– Displays usage summary and argument list
– Used by most, but not all, commands
– date –-help
The man Command
• Provides documentation for commands
• Every command has a man "page“
• While viewing a man page
– Navigate with arrows, PgUp, PgDn
– /text searches for text
– n/N goes to next/previous match
– q quits
• Pages are grouped into "chapters"
– Collectively referred to as the Linux Manual
– man [<chapter>] <command>
– The info Command Similar to man, but often more in-depth
– info [command]
Browsing the Filesystem

• Files and directories are organized into a


single-rooted inverted tree structure
• Filesystem begins at the root directory,
represented by / (forward slash)
• Names are case-sensitive
• Paths are delimited by /
Some Important Directories
• Home Directories: /root,/home/username
• User Executables: /bin, /usr/bin, /usr/local/bin
• System Executables: /sbin, /usr/sbin, /usr/local/sbin
• Other Mountpoints: /media, /mnt
• Configuration: /etc
• Temporary Files: /tmp
• Kernels and Bootloader: /boot
• Server Data: /var, /srv
• System Information: /proc, /sys
• Shared Libraries: /lib, /usr/lib, /usr/local/lib
• pwd - Displays the current working
directory
• touch - create empty files
• mkdir creates directories
• rmdir removes empty directories
• rm -r recursively removes directory trees
• Names are case-sensitive
• MAIL, Mail, mail, and mAiL
Absolute and Relative Pathnames

• Absolute pathnames begin with a forward


slash /
• Relative pathnames do not begin with a
slash
Changing Directories

• cd changes directories
• To an absolute or relative path:
– cd /home/joshua/work
– cd project/docs
• To a directory one level up:
– cd ..
• To your home directory:
– cd
• To your previous working directory:
– cd -
Copying & moving Files and Directories

• cp - copy files and directories


• mv - move and/or rename files and
directories
• Usage:
cp/mv [options] file destination
• More than one file may be copied at a
time if the destination is a directory:
cp/mv [options] file1 file2 dest
Users, Groups and Permissions
• Every user is assigned a unique User ID number (UID)
– UID 0 identifies root
• Users' names and UIDs are stored in /etc/passwd
• Users are assigned a home directory and a program that
is run when they log in
• Users cannot read, write or execute each others' files
without permission
• Every user in a Linux system belongs at least to one
group
• Users are assigned to groups
• Each group is assigned a unique Group ID number (gid )
• GIDs are stored in /etc/group
Permission Types
• Four symbols are used when displaying
permissions:
• r: permission to read a file or list a directory's
contents
• w: permission to write to a file or create and
remove files from a directory
• x: permission to execute a program or change
into a directory and do a long listing of the
directory
• -: no permission (in place of the r, w, or x)
• File permissions may be viewed using ls -l
Changing Permissions - Symbolic
Method
• To change access modes:
– chmod [-R] mode file
• Where mode is:
– u,g or o for user, group and other
– + or - for grant or deny
– r, w or x for read, write and execute
• Examples:
– ugo+r: Grant read access to all
– o-wx: Deny write and execute to others
Changing Permissions - Numeric
Method
• Uses a three-digit mode number
– first digit specifies owner's permissions
– second digit specifies group permissions
– third digit represents others' permissions
• Permissions are calculated by adding:
– 4 (for read)
– 2 (for write)
– 1 (for execute)
• Example:
– chmod 640 myfile
The Seven Fundamental Filetypes

ls -l symbol File Type


- regular file
d directory
l symbolic link
b block special file
c character special file
p named pipe
s socket
Vi - Text Editor

• Use the three primary modes of vi and


vim
• Navigate text and enter Insert mode
• Change, delete, yank, and put text
• Undo changes
• Search a document
• Save and exit
Vi modes

• Three main modes:


• Command Mode (default): Move cursor,
cut/paste text, change mode
• Insert Mode: Modify text
• Ex Mode: Save, quit, etc
• Esc exits current mode
Modifying a File : Insert Mode
• i begins insert mode at the cursor
• Many other options exist
– A append to end of line
– I insert at beginning of line
– o insert new a line (below)
– O insert new line (above)
– k move cursor up
– j move cursor down
– h move cursor left
– l move cursor right
– 4yy yanks current line and 3 lines below
– dd is used to delete
– P or p is used to paste
– cc is used to cut
Saving a File and Exiting vim
Ex Mode
• Enter Ex Mode with :
– Creates a command prompt at bottom-left of
screen
• Common write/quit commands:
– :w writes (saves) the file to disk
– :wq writes and quits
– :q! quits, even if changes are lost
Undo & Search

• u undo most recent change


• U undo all changes to the current line
since the cursor landed on the line
• Ctrl-r redo last "undone" change
• Searching for a pattern (/pat and ?pat)
• Search and replace :%s/e/3/g
Pattern matching – The WILD CARDS

* - matches zero or more characters


? - matches any single character
[0-9] - matches a range of numbers
[abc] - matches any of the character in
the list
[^abc] - matches all except the
characters in the list
REDIRECTION
• Linux provides three I/O channels to programs
– Standard input (STDIN) - keyboard by default
• < Redirect STDIN to file
– Standard output (STDOUT) - terminal window by
default
• > Redirect STDOUT to file
– Standard error (STDERR) - terminal window by
default
• 2> Redirect STDERR to file

● File contents are overwritten by default. >> appends.


Example
• $ ls > myfiles
• $ date >> myfiles
• $ cat < myfiles
• $vi sname
– Vivek
ashish
zebra
babu

• $ sort < sname > sorted_names


• $ cat sorted_names
• $ tr "[a-z]" "[A-Z]" < sname > cap_names
• $ cat cap_names
Alias

• Aliases let you create shortcuts to


commands
# alias c=‘clear’
# alias dir=‘ls –l’
head and tail commands
• head: Display the first 10 lines of a file
– Use -n to change number of lines displayed
• tail: Display the last 10 lines of a file
– Use -n to change number of lines displayed
Compressing and Archiving files

• gzip and gunzip (.gz)


• bzip2 and bunzip2(.bz2)
• tar - standard Linux archiving command
Locate

• Queries a pre-built database of paths to


files on the system
– Database must be updated by administrator
– Full path is searched, not just filename
– Locate only finds files by looking up the
name in a database.
# locate stdio.h
# locate smb.conf
find

• Locate uses an internal database to look up


indexed files. This database needs to be
updated using the command 'updatedb' at
regular intervals, so that you'll get more
accurate results. Find just does a "normal"
search, ie. it just goes through the given
path(s) just when you want it to.
• Find command is used to search for files
• Find / -name a.out
• Find . –name “*.txt”
Grep (global regular expression print) :
searching for a pattern
• Grep scans its input in a pattern and
displays the lines containing the pattern.
– ^ represents beginning of line
– $ represents end of line
– “abc$” “^abc”
• # grep “sales” emp.lst display lines containing
the string sales from the file emp.lst
• # grep ‘john’ /etc/passwd
• # grep ‘^j’ /etc/passwd
• #grep root /etc/passwd | cut -d: -f7

You might also like