1 / 23

Perl & Chapter 5

Learn about Perl scripting and how the file system works in Linux. Understand aliases, sessions, and different file system types.

waldrup
Download Presentation

Perl & Chapter 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Perl & Chapter 5 Perl Scripting and The File system

  2. Hey real quick aliases • Aliases • Aliases can be defined on the command line, in .bash_profile, or in .bashrc, using this form : alias name=‘command’ • unalias will remove

  3. Sessions • A session started as a login session will read configuration details from the /etc/profile file first. It will then look for the first login shell configuration file in the user's home directory to get user-specific configuration details. • It reads the first file that it can find out of ~/.bash_profile, ~/.bash_login, and ~/.profile and does not read any further files. • In contrast, a session defined as a non-login shell will read /etc/bash.bashrc and then the user-specific ~/.bashrc file to build its environment. • Non-interactive shells read the environmental variable called BASH_ENV and read the file specified to define the new environment.

  4. Brief Perl Scripting • Used for quick and dirty programs you can code in 3-5 minutes. • (Using your favorite text editor) • Perl comments are preceded with (#) • A single line can be split into multiple lines with (\) and multiple lines can be put on a single line separated by (;)

  5. Perl Scripting cont’ • All perl scripts should start with: • print "Hello, world!\n” • (example in text editor) • Tells the kernel to interpret this file as perl script for execution • To run do the following • $ chmod +x hello.pl • $ ./hello • (lets open CentOS and see what happens)

  6. More Perl • In Windows the .exe extension designates an executable file • In Linux (and Unix) the execute bit is the designation. • (we will learn more about the execute bit later in this chapter) • Alternatively you can execute a bash script with perlfilename OR ./filename (if its executable)

  7. Output and Input • The print command is for quick and dirty output. • <STDIN> reads input from stdin • (lets open CentOS and see results)

  8. The File system • How your Linux systems represents system objects and resources. • The file system contains: • Some naming convention and organization • Methods to navigate and manipulate the file system • Security / access methods • Code (software) that ties it all together

  9. File system Types • There are many different types of file systems used on different kernels • FAT32 (Windows) • NTFS (Windows) • HFS+ (Mac OS X) • Ext3 (Linux) • Ext4 (Linux) • XFS (Linux)

  10. XFS – File System • XFS is a highly scalable, high-performance file system which was originally designed at Silicon Graphics, Inc. XFS is the default file system for Red Hat Enterprise Linux 7 and CentOS 7. • Main FeaturesXFS supports metadata journaling, which facilitates quicker crash recovery. The XFS file system can also be defragmented and enlarged while mounted and active. In addition, Red Hat Enterprise Linux 7 supports backup and restore utilities specific to XFS.

  11. Pathnames • The File system stores everything as a hierarchy starting with “/” • This is known as the root directory • Contains any number of subdirectories • Traverse the file system using the “cd” command

  12. Mounting • A file tree is a collection of file systems • A file system is collection of pathnames and files • You add file systems to the file tree with the “mount” command • Usage: mount locationmount-point mount /dev/hda4 /users • After mounting you could do ls –al and see all of the contents of the directory • /etc/fstab

  13. Unmounting • “unmount” is used to detach a mounted file system • (note**** nothing in the mounted file system can be use in order to unmount • Usage: unmountmount-point • The fuser command will tell you whats running in your mount-point • Usage: fuser –mv mount-point

  14. File tree Pathname Contents /bin Commands needed for minimal system operability /boot Kernel and files needed to load the kernel /devDevice entries for disks, printers, pseudo-terminals, etc. /etcCritical startup and configuration files /home Home directories for users /lib Libraries and parts of the C compiler /media Mount points for filesystems on removable media /opt Optional application software packages (not yet widely used) /procInformation about all running processes /root Home directory of the superuser (often just /) /sbinCommands for booting, repairing, and recovering the system /tmpTemporary files that may disappear between reboots /usrHierarchy of secondary files and commands /usr/bin Most commands and executable files /usr/include Header files for compiling C programs /usr/lib Libraries; also, support files for standard programs /usr/local Local software (software you write or install) /usr/local/bin Local executables /usr/local/etcLocal system configuration files and commands /usr/local/lib Local support files /usr/local/sbinStatically linked local system maintenance commands /usr/local/srcSource code for /usr/local/* /usr/man On-line manual pages /usr/sbinLess essential commands for system administration and repair /usr/share Items that might be common to multiple systems (read-only) /usr/share/man On-line manual pages /usr/srcSource code for nonlocal software packages (not widely used) /varSystem-specific data and configuration files /var/admVaries: logs, system setup records, strange administrative bits /var/log Various system log files /var/spool Spooling directories for printers, mail, etc. /var/tmpMore temporary space (preserved between reboots)

  15. File Types • Regular files • Directories • Character device files (rw char by char) • Block device files (rw block chunks) • Local domain sockets • Named pipes (FIFOs) • Symbolic Links • ls –al tells all • rm (delete) removes all

  16. Regular Files • Collection of bytes • Data or text files, executable program, etc • Nothing to see here move on……..

  17. Directories • You may have noticed “.” and “..” the are the directory itself and its parent directory representation • mkdir creates a new directory • rm –r deletes a directory and its subdirectories • cp and ln (hardlink) (oldfile newfile) • In-class examples

  18. File Attributes $ ls -l /bin/gzip -rwxr-xr-x 3 root root 57136 Jun 15 2004 /bin/gzip • The first field specifies the file’s type and mode. The first character is a dash, so the file is a regular file. • The next nine characters in this field are the three sets of permission bits. • The next field in the listing is the link count for the file. Every time a hard link is made to a file, the count is incremented by 1. • The next two fields in the ls output are the owner and group owner of the file. • The next field is the size of the file in bytes. • Next comes the date of last modification: June 15, 2004. • The last field in the listing is the name of the file, /bin/gzip.

  19. More Types • Device and block files • Device driver files that talk to system hardware • Local Domain Sockets • Connections between processes (not to be confused with network sockets but act in much the same way • Aka UNIX domain sockets • Named Pipes • Like local domain sockets piping data from one process to another • Symbolic Links • ln –s command • From the internet Removing the original file does not remove the attached symbolic link or symlink, but without the original file, the symlink is useless (the same concept like Windows shortcut).

  20. More with Files • $touch a • $ ln a a1 • $ ls –al then view results • See that the Inode number for ‘a’ and ‘a1′ are same as we created ‘a1’ as hard link. • But they are different for symbolic link • Stat command

  21. File Permissions • Each file has set of 12 mode attributes called bits. • Read, write, execute, and file type information • Nine (9) bits define permissions for file owner, group, and world (or everyone else) • -r,w,x • octal • chmod command is extremely useful • In class examples

  22. File Permissions Cont’ • Each file has set of 12 mode attributes called bits. • Read, write, execute, and file type information • Nine (9) bits define permissions for file owner, group, and world (or everyone else) • -r,w,x • octal • chmod command is extremely useful • In class examples

  23. chmod • Changes the file permissions • Only file owner or root can run chmod • In class examples • chown and chgrp(UNIX) commands allow you to change the ownership and group permission of a file • umask command allows you to set a default list of permissions given to files you create

More Related