KEMBAR78
Linux Commands - Basic commands for Beginners | PPTX
* 1
Linux Basic Commands
* 2
Operating System Concept
• An operating system (OS) is
a resource manager
• It is a set of software
routines:
– that allow users and
application programs to access
system resources
– in a safe, efficient and abstract
way
– CPU, memory, disks, modems,
printers network cards etc.
• A general operating system
architecture can be
understood by the figure
Users
Shell or GUI
Application
Programs
System Utilities
System Call Library
Operating System Kernel
Dual Processor with 2 GB RAM,
160 GB Hard Disk
* 3
Operating System Concept
• The kernel controls the hardware
• It provides functions like
– Handling of interrupts from the devices
– Allocation of memory to programs
– Sharing of CPU among the programs
• Basic kernel services are exposed to higher-level programs
through a library of system calls
• Application Programs and System Utility Programs
make use of system calls
– Launched using a shell/GUI
• The OS may differ from one another on the basis of:
– System calls
– System utilities
– User interface they provide
– Resource scheduling policies implemented by the kernel
* 4
A Linux Distribution
• A distribution comprises of:
– Kernel
• 2.6.9-89.0.11.EL.cernsmp
– System Utilities
• File copy, hard disk repair/defragment etc.
– GUI
• GNOME, KDE
– Application Programs
• Open office, evolution, firefox, gedit, gftp. konqueror,
evince, kdevelop, kview, emace, vim etc.
* 5
Typical Directory Structure
• Linux Filesystem is laid out in a hierarchical tree
structure.
• Top level directory is called root “/”
* 6
* 7
Summary: Directory Structure
• 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
* 8
Logging into a Linux System
• Two types of login screens
– virtual consoles (text-based)
– graphical logins (display managers)
• Login using login name and password
• Each user has a home directory for personal
file storage
* 9
Absolute & Relative Paths
• Absolute pathnames
– Begin with a forward slash
– Complete "road map" to file location
– Can be used anytime you wish to specify a file
name
• Relative pathnames
– Do not begin with a slash
– Specify location relative to your current working
directory
– Can be used as a shorter way to specify a file
name
* 10
Basic Linux Commands
• ls, listing files and directories
– ls –a
– ls –l
– ls -la
• clear, clears the screen
• echo, display a line or text
– echo “any text”, echo $HOSTNAME
• exit, exit the current session/shell
• file, determine file type
– file <file name/path>
* 11
Basic Linux Commands
• cd, change directory
– cd ..
– cd –
– cd ~/mydir
– cd /home/usman
– cd
• su, switch user, su – (complete user
environment)
• id, print user and group ids
• passwd, change password
– yppasswd
* 12
Basic Linux Commands
• man, manual pages
– man <command>
• info, information pages
– info <command>
• command --help, basic help by author
– ls --help, man --help
• pwd, present working directory
* 13
Basic Linux Commands
• cp, copy files and directories
– cp [options] file destination
• More than one file may be copied at a time if the
destination is a directory:
– cp [options] file1 file2 destination
• If the destination is a directory, the copy is placed
there
• If the destination is a file, the copy overwrites the
destination
• If the destination does not exist, the copy is renamed
* 14
Basic Linux Commands
• mv, move and/or rename files and directories
– mv [options] file destination
• More than one file may be moved at a time if
the destination is a directory:
– mv [options] file1 file2 destination
• In mv also, the destination works like cp
• mkdir, creates directories
– mkdir <directory name/path>
• rmdir, removes empty directories
– rmdir < directory name/path>
* 15
Basic Linux Commands
• touch, create empty files or update file
timestamps
– touch <file name/path>
• rm, remove files
– rm [options] <file name/path>
– rm -i file (interactive)
– rm -r directory (recursive)
– rm -f file (force)
• rm –r, recursively removes directory trees
– rm –rf <directory name/path>
* 16
Basic Linux Commands
• whoami, print user id
• locate, finds files using a pre-built database.
• find, Finds files and directories in real-time.
– locate is faster but relies on an updated index; find
is slower but always accurate.
• whereis, Shows locations of executables,
source code, and manual pages
* 17
File Permissions in Linux
* 18
File Permissions in Linux
Octal Binary Permissions
0 000 _ _ _
1 001 _ _ x
2 010 _ w _
3 011 _ w x
4 100 r _ _
5 101 r _ x
6 110 r w _
7 111 r w x
* 19
Basic Linux Commands
• chmod, changing permissions of files/directories
– Octal mode
• chmod 644 <file name/path>
• chmod 755 <file name/path>
• chmod 6 <file name/path>
– Symbolic mode
• chmod u+x, g-r, o+x <file name/path>
• chmod a+x <file name/path>
• chmod =x <file name/path>
* 20
Shell Scripting Basics
#!/bin/sh
echo "Welcome to Linux -- $USER"
echo "Today is: $(date)"
echo "You are working in: $(pwd)"
echo "Enter your last name:"
read LNAME
echo "Hello -- $LNAME"
echo "Enter the first number:"
read X
echo "Enter the second number:"
read Y
PRODUCT=$((X * Y))
echo "The product is: $PRODUCT"
echo "Bye Bye..."
* 21

Linux Commands - Basic commands for Beginners

  • 1.
  • 2.
    * 2 Operating SystemConcept • An operating system (OS) is a resource manager • It is a set of software routines: – that allow users and application programs to access system resources – in a safe, efficient and abstract way – CPU, memory, disks, modems, printers network cards etc. • A general operating system architecture can be understood by the figure Users Shell or GUI Application Programs System Utilities System Call Library Operating System Kernel Dual Processor with 2 GB RAM, 160 GB Hard Disk
  • 3.
    * 3 Operating SystemConcept • The kernel controls the hardware • It provides functions like – Handling of interrupts from the devices – Allocation of memory to programs – Sharing of CPU among the programs • Basic kernel services are exposed to higher-level programs through a library of system calls • Application Programs and System Utility Programs make use of system calls – Launched using a shell/GUI • The OS may differ from one another on the basis of: – System calls – System utilities – User interface they provide – Resource scheduling policies implemented by the kernel
  • 4.
    * 4 A LinuxDistribution • A distribution comprises of: – Kernel • 2.6.9-89.0.11.EL.cernsmp – System Utilities • File copy, hard disk repair/defragment etc. – GUI • GNOME, KDE – Application Programs • Open office, evolution, firefox, gedit, gftp. konqueror, evince, kdevelop, kview, emace, vim etc.
  • 5.
    * 5 Typical DirectoryStructure • Linux Filesystem is laid out in a hierarchical tree structure. • Top level directory is called root “/”
  • 6.
  • 7.
    * 7 Summary: DirectoryStructure • 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
  • 8.
    * 8 Logging intoa Linux System • Two types of login screens – virtual consoles (text-based) – graphical logins (display managers) • Login using login name and password • Each user has a home directory for personal file storage
  • 9.
    * 9 Absolute &Relative Paths • Absolute pathnames – Begin with a forward slash – Complete "road map" to file location – Can be used anytime you wish to specify a file name • Relative pathnames – Do not begin with a slash – Specify location relative to your current working directory – Can be used as a shorter way to specify a file name
  • 10.
    * 10 Basic LinuxCommands • ls, listing files and directories – ls –a – ls –l – ls -la • clear, clears the screen • echo, display a line or text – echo “any text”, echo $HOSTNAME • exit, exit the current session/shell • file, determine file type – file <file name/path>
  • 11.
    * 11 Basic LinuxCommands • cd, change directory – cd .. – cd – – cd ~/mydir – cd /home/usman – cd • su, switch user, su – (complete user environment) • id, print user and group ids • passwd, change password – yppasswd
  • 12.
    * 12 Basic LinuxCommands • man, manual pages – man <command> • info, information pages – info <command> • command --help, basic help by author – ls --help, man --help • pwd, present working directory
  • 13.
    * 13 Basic LinuxCommands • cp, copy files and directories – cp [options] file destination • More than one file may be copied at a time if the destination is a directory: – cp [options] file1 file2 destination • If the destination is a directory, the copy is placed there • If the destination is a file, the copy overwrites the destination • If the destination does not exist, the copy is renamed
  • 14.
    * 14 Basic LinuxCommands • mv, move and/or rename files and directories – mv [options] file destination • More than one file may be moved at a time if the destination is a directory: – mv [options] file1 file2 destination • In mv also, the destination works like cp • mkdir, creates directories – mkdir <directory name/path> • rmdir, removes empty directories – rmdir < directory name/path>
  • 15.
    * 15 Basic LinuxCommands • touch, create empty files or update file timestamps – touch <file name/path> • rm, remove files – rm [options] <file name/path> – rm -i file (interactive) – rm -r directory (recursive) – rm -f file (force) • rm –r, recursively removes directory trees – rm –rf <directory name/path>
  • 16.
    * 16 Basic LinuxCommands • whoami, print user id • locate, finds files using a pre-built database. • find, Finds files and directories in real-time. – locate is faster but relies on an updated index; find is slower but always accurate. • whereis, Shows locations of executables, source code, and manual pages
  • 17.
  • 18.
    * 18 File Permissionsin Linux Octal Binary Permissions 0 000 _ _ _ 1 001 _ _ x 2 010 _ w _ 3 011 _ w x 4 100 r _ _ 5 101 r _ x 6 110 r w _ 7 111 r w x
  • 19.
    * 19 Basic LinuxCommands • chmod, changing permissions of files/directories – Octal mode • chmod 644 <file name/path> • chmod 755 <file name/path> • chmod 6 <file name/path> – Symbolic mode • chmod u+x, g-r, o+x <file name/path> • chmod a+x <file name/path> • chmod =x <file name/path>
  • 20.
    * 20 Shell ScriptingBasics #!/bin/sh echo "Welcome to Linux -- $USER" echo "Today is: $(date)" echo "You are working in: $(pwd)" echo "Enter your last name:" read LNAME echo "Hello -- $LNAME" echo "Enter the first number:" read X echo "Enter the second number:" read Y PRODUCT=$((X * Y)) echo "The product is: $PRODUCT" echo "Bye Bye..."
  • 21.