The document provides an overview of Unix and shell scripting. It discusses what Unix is, its architecture including the kernel, shell, commands, and filesystem. It then covers what shell scripts are, their components and syntax. The document provides examples of shell script code and discusses how to invoke scripts, execute them in background, and useful metacharacters. It also covers various Unix commands like ls, cd, grep, find and their usage.
CompTIA Linux+ Powered by LPI certifies foundational skills and knowledge of Linux. With Linux being the central operating system for much of the world’s IT infrastructure, Linux+ is an essential credential for individuals working in IT, especially those on the path of a Web and software development career. With CompTIA’s Linux+ Powered by LPI certification, you’ll acquire the fundamental skills and knowledge you need to successfully configure, manage and troubleshoot Linux systems. Recommended experience for this certification includes CompTIA A+, CompTIA Network+ and 12 months of Linux admin experience. No prerequisites required.
LInux: Basics & File System:The Unix operating system was conceived and implemented in 1969 at AT&T's Bell Laboratories in the United States by Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna. First released in 1971, Unix was written entirely in assembly language, as was common practice at the time. Later, in a key pioneering approach in 1973, it was rewritten in the C programming language by Dennis Ritchie (with exceptions to the kernel and I/O). The availability of a high-level language implementation of Unix made its porting to different computer platforms easier.
CompTIA Linux+ Powered by LPI certifies foundational skills and knowledge of Linux. With Linux being the central operating system for much of the world’s IT infrastructure, Linux+ is an essential credential for individuals working in IT, especially those on the path of a Web and software development career. With CompTIA’s Linux+ Powered by LPI certification, you’ll acquire the fundamental skills and knowledge you need to successfully configure, manage and troubleshoot Linux systems. Recommended experience for this certification includes CompTIA A+, CompTIA Network+ and 12 months of Linux admin experience. No prerequisites required.
LInux: Basics & File System:The Unix operating system was conceived and implemented in 1969 at AT&T's Bell Laboratories in the United States by Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna. First released in 1971, Unix was written entirely in assembly language, as was common practice at the time. Later, in a key pioneering approach in 1973, it was rewritten in the C programming language by Dennis Ritchie (with exceptions to the kernel and I/O). The availability of a high-level language implementation of Unix made its porting to different computer platforms easier.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
2. What is Unix/Linux?
Unix is a modular OS made up of a number of essential components, including the kernel, shell, file
system and a core set of utilities or programs. At the heart of the Unix OS is the kernel, a master
control program that provides services to start and end programs.
Unix was originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie,
Douglas McIlroy, and Joe Ossanna.
There are various Unix variants available in the market. Solaris Unix, AIX, HP Unix and BSD are few examples. Linux is also a
flavor of Unix which is freely available
Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser system.
A user can also run multiple programs at the same time; hence UNIX is called multitasking.
UNIX OS is commercial and more select audience (i.e.. servers). Where Linux is a free, open-source operating system (OS).
Linux is designed for a general-purpose audience (i.e.. Desktops/Laptops/Mini server’s).
3. Unix Architecture:
• The main concept that unites all versions of UNIX is the following four
basics:
• Kernel: The kernel is the heart of the operating system. It interacts with
hardware and most of the tasks like memory management, task
scheduling and file management.
• Shell: The shell is the utility that processes your requests. When you
type in a command at your terminal, the shell interprets the command
and calls the program that you want. The shell uses standard syntax for
all commands. C Shell, Bourne Shell and Korn Shell are most famous
shells which are available with most of the Unix variants.
• Commands and Utilities: There are various command and utilities
which you would use in your day-to-day activities. cp, mv, cat and grep
etc. are few examples of commands and utilities. There are over 250
standard commands plus numerous others provided through 3rd party
software. All the commands come along with various optional options.
• Files and Directories: All data in UNIX is organized into files. All files are
organized into directories. These directories are organized into a tree-
like structure called the filesystem.
4. UNIX Filesystem
• Unix uses a hierarchical file system structure, much like an upside-down
tree, with root (/) at the base of the file system and all other directories
spreading from there.
/ → This is the root directory which should contain only the directories needed at the top level of the file structure.
/bin → essential command binaries
/boot → static files of the boot loader
/dev → device files (special files to access your devices)
/etc → host-specific system configuration files
/home → user home directories (e.g., /home/peter, /home/sarah, etc)
/lib → essential shared libraries and kernel modules
/media → mount point for removable media (e.g., CD-ROMs & flash disks)
/mnt → “old-style” mount point for any media
/tmp → system-wide temporary folder, writable by anyone
/sbin → Contains binary (executable) files, usually for system administration. For example, fdisk and ifconfig utlities.
5. Files and Directories Permissions
File & directory has the following attributes:
• Owner permissions: The owner's permissions determine what actions the owner of the file can perform on the file.
• Group permissions: The group's permissions determine what actions a user, who is a member of the group that a file belongs to, can perform
on the file.
• Other (world) permissions: The permissions for others indicate what action all other users can perform on the file.
6. Shell (.bashrc file) and Environment Variables
• .bashrc configuration file - .bashrc file is a script file that's executed when a user logs
in. The file itself contains a series of configurations for the terminal session. This
includes setting up or enabling coloring, completion, shell history, command aliases,
and more. It is a hidden file and simple ls command won't show the file.
• #Print all and Check the default environment variables
printenv or env
echo $SHELL
echo $HOME
• #EXPORT command will set the new variable and add the path into existing variable
export V_TEST="Hello World“
echo $V_TEST
export PATH=$PATH:/place/with/the/file
echo $PATH
7. User Login and Password
• #ssh or telnet – command to login into server with ip address or hostname
$ssh username@ip_address_or_hostname
• # su command lets you switch the current user to any other user.
$su – <username>
• # If you prefix “sudo” with any command, it will run that command with
elevated privileges or in other words allow a user with proper permissions to
execute a command as another user. This is the equivalent of “run as
administrator”
$ sudo su – <username>
• #passwd command to change your user password
$passwd <username>
• #The whoami command allows Linux users to see the currently logged-in user
$whoami
•
Tools to connect servers via (SSH and telnet client):
• Putty, WinSCP etc.
8. Vi Editor
• The default editor that comes with the UNIX operating system is called vi
(visual editor). Using vi editor, we can edit an existing file or create a new file
from scratch. we can also use this editor to just read a text file.
• vi filename : Creates a new file if it already not exist, otherwise opens existing
file.
• vi -R filename : Opens an existing file in read only mode.
• view filename : Opens an existing file in read only mode.
• #Create a new file
$vi filename.txt
• Press i to insert mode
• :wq <save>
:q <not-save>
•
#Search Text in file
/<searchtext> Enter
• Press n for next shift+n for previous
9. Unix Commands
• ls – is a command to list computer files and directories
• cd – is a command-line shell command used to change the current working directory
• pwd – the pwd command writes the full pathname of the current working directory to the standard output.
• chown – chown command is used to change the file Owner or group
• $chown -v username file1.txt
• chmod – the chmod command is used to change the access mode of a file
• $ chmod u=rw two.py
• $ chmod o=rw two.py
• $ chmod g=rw two.py
• $ ls -l two.py
• -rw-rw-rw- 1 EAD+rkumar446 EAD+Domain Users 337 May 3 16:25 two.py
• touch – The touch command's primary function is to modify a timestamp. Commonly, the utility is used for file creation.
• $ touch -d "2012-10-19 12:12:12.000000000 +0530" two.py
• $ ls --full-time two.py
• -rw-rw-rw- 1 EAD+rkumar446 EAD+Domain Users 337 2012-10-19 12:12:12.000000000 +0530 two.py
10. • mkdir – The mkdir command in Linux/Unix allows users to create or make new directories.
• rmdir – rmdir command is used remove empty directories from the filesystem
• rm – The rm command removes the entries for a specified file, group of files, or certain select files from a list within a directory.
• echo – echo command in linux is used to display line of text/string that are passed as an argument .
• cat – The cat command is a utility command in Linux. One of its most common usages is to print the content of a file onto the standard
output stream.
• grep – The grep filter searches a file for a particular pattern of characters and displays all lines that contain that pattern.
• $ grep "run" two.py
• $ grep -n "run" two.py
• $ grep -i "ruN" two.py
• $ grep -n -C1 "run" two.py
• head – head command prints the first lines of one or more files (or piped data) to standard output.
• tail –The tail command, as the name implies, print the last N number of data of the given input.
• more –command is used to view the text files in the command prompt, displaying one screen at a time in case the file is large
• uname – To display system information, use the uname command. Displays the operating system name as well as other system related
information like node, release, OS version, hardware name, and processor type etc. Exp: uname -a
11. • find – The “find” command is used to find, filter, or search files and folders in your system according to user-specified conditions and
perform several operations.
• $ find ./ -name "two.py"
• $ find ./ -type f -name "two.py"
• $ find ./ -type f -name "*.py"
• $ find ./ -type d -name "tt"
• $ find ./ -type f -name "*.py" -exec grep 'run' {} ;
• $ find ./ -type f -name "*.py" -print -exec grep -n 'run' {} ;
• ping – PING (Packet Internet Groper) command is used to check the network connectivity between host and server/host.
• top – top command is used to show the Linux processes. It provides a dynamic real-time view of the running system.
• file – file command is used to determine the type of a file. .file type may be of human-readable(e.g. 'ASCII text') or MIME type (e.g.
'text/plain; charset=us-ascii').
• cp – cp stands for copy. This command is used to copy files or group of files or directory.
• mv – The mv command is one of the basic Linux commands that is used to move files and directories from one location to another.
• wc – is a command line utility for printing newline, word and byte counts for files. Exp: wc -l/w/c
• cut – cut is a command for cutting out the sections from each line of files and writing the result to standard output.
• $ echo 'An|exception|occurred|at|runtime'|cut -d '|' -f1
• $ echo 'An|exception|occurred|at|runtime'|cut -d '|' -f2
• $ echo 'An|exception|occurred|at|runtime'|cut -c 1-5
12. • which – The Linux which command is used to locate the executable files or location of a
program from the file system.
• tr – The tr command is a Linux command-line utility that translates or deletes characters from
standard input ( stdin ) and writes the result to standard output ( stdout ).
• $ echo 'An|exception|occurred|at|runtime'|tr e E
• $ echo 'An|exception|occurred|at|runtime'|tr A-Z a-z
• $ echo 'An|exception|occurred|at|runtime'|tr -d 'e'
• ps – ps command is used to list the currently running processes and their PIDs along with
some other information depends on different options. It reads the process information from
the virtual files in /proc file-system.
• $ ps
• PID PPID PGID WINPID TTY UID STIME COMMAND
971 1 971 24872 ? 1074028310 15:12:41 /usr/bin/minty
972 971 972 24324 pty0 1074028310 15:12:44 /usr/bin/bash
1351 972 1351 20808 pty0 1074028310 11:38:18 /usr/bin/ps
• kill – kill command in Linux (located in /bin/kill), is a built-in command which is used to
terminate processes manually.
• $ kill -l
• $ kill pid
• $ kill -9 pid
• history – history command is used to view the previously executed command.
13. • du – to check how much space a file or a directory takes, the du (Disk Usage) command
• df – to get a report on the system’s disk space usage, shown in percentage and KBs.
• tar – The Linux ‘tar’ stands for tape archive, is used to create Archive and extract the Archive
files.
• $ tar cvf file.tar *.c
• $ tar xvf file.tar
• expr – The expr command in Unix evaluates a given expression and displays its corresponding
output.
• $ expr --help
• $ expr 12 + 12
• $ expr 12 * 2
• Help yourself
• man – man command in Linux is used to display the user manual of any command that we can run on
the terminal. It provides a detailed view of the command which includes NAME, SYNOPSIS,
DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS
and SEE ALSO.
• [username@host ~]$ man ls
...
17. What is Shell Script?
• A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various
dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts
include file manipulation, program execution, and printing text. A script which sets up the environment, runs the
program, and does any necessary cleanup or logging, is called a wrapper (another way to extend primary
object/commands behavior).
• The basic concept of a shell script is a list of commands, which are listed in the order of execution. A good shell
script will have comments, preceded by a pound sign, #, describing the steps.
• There are conditional tests, such as value A is greater than value B, loops allowing us to go through massive
amounts of data, files to read and store data, and variables to read and store data, and the script may include
functions.
• Shell scripts and functions are both interpreted. This means they are not compiled.
The whole code of shell is in the text file ASCII Character
18. Why Shell Script ?
Shell scripts can be used to prepare input files, job monitoring, and output processing etc.
To avoid repetitive work and automation
Useful to create own commands with help of alias (to list all execute $alias –p, alias l=‘ls –la’)
Save lots of time on file processing.
To automate some task of day-to-day activity.
System Administration part can be also automated.
Use shell scripting for routine backups, text Parsing, cleanup etc. activity.
19. Components of a script
• A series of OS commands for execution Stored in a text file.
• A shell script have syntax just like any other programming language. A shell script comprises
following elements:
• -Shell Keywords – if, else, break etc.
-Shell commands – cd, ls, echo, pwd, touch etc.
-Functions
-Control flow – if..then..else, case and shell loops etc.
#!/bin/sh
rm -f /tmp/listing.tmp > /dev/null 2>&1
touch /tmp/listing.tmp
ls -l [a-z]*.doc | sort > /tmp/listing.tmp
lpr -Ppostscript_1 /tmp/listing.tmp
rm -f /tmp/listing.tmp
20. Sample .sh Code
#!/bin/sh
rm -f /tmp/listing.tmp > /dev/null 2>&1
touch /tmp/listing.tmp
# This is a comment
ls -l [a-z]*.doc | sort > /tmp/listing.tmp
lpr -Ppostscript_1 /tmp/listing.tmp
rm -f /tmp/listing.tmp
Shell Interpreter (sh, csh, ksh)
Comment
Command
21. How to invoke a script ?
• Make it executable
• $ chmod +x path/to/our/file/my_script.sh
• Correct way
$ /bin/ksh my_script arg_1 arg_2
• $ /bin/csh my_script arg_1 arg_2
• $ /bin/sh my_script arg_1 arg_2
• Simple way
$ my_script arg_1 arg_2
Or
• $ ./my_script arg_1 arg_2
22. Execute a script in background
• At Command Prompt
$ nohup sh my_script arg_1 arg_2 > /dir/file.log &
Or
• $ nohup sh my_script arg_1 arg_2 > /dir/file.log 2>&1
• Means:
• 2 refers to the second file descriptor of the process, i.e.
stderr.
• > means redirection.
• &1 target of the redirection should be the same location as the
first file descriptor, i.e. stdout.
•
So this command first redirects stdout to /dev/null and then
redirects stderr there as well.
23. Useful Metacharacters
• $ Variable Substitution or expand the value of Variable.
• > used for Output Redirection.
• >> used for Output Redirection to append.
• < Input redirection.
• << used for input redirection and is also known as here document.
• * Match any number of characters, Substitution wildcard for zero or more characters
• ? Match one character, Substitution wildcard for 1 character
• [ ] Match range of characters, Substitution wildcard for any character between brackets
• `cmd` Replace cmd with the command to execute and will execute that, Substitution wildcard for command execution
• $(cmd) Replace cmd with the command to execute and will execute that, Substitution wildcard for command execution
• | Pipe is a Redirection the output of one command/program/process to another command for further processing.
• ; Command separator is used to execute 2 or more commands with one statement.
• || OR conditional execution of the commands.
• && AND conditional execution of the commands.
• ( ) Groups the command in to one output stream.
24. Example (metacharacters)
List files having prefix new
$ ls new*
Cat files having prefix ch and one more letter
$ cat ch?
List files starting by letters from D to E
$ ls [D-R]*
• Use of Array, Used in special cases for variables with the $.
• $ numbers=( 1 2 3 4 5 )
• $ echo ${numbers[1]}
25. Quoting
“ “ Everything taken literally, except
$ (variable substitution)
` (command substitution)
“ (ending mark)
‘ ‘ Everything taken literally
Escape next Character
# to comment something.
26. Example (quoting)
$ echo 'my class is "unix and tools"'
My class is "unix and tools“
$ echo "Well, isn't that "good" ?"
Well, isn't that "good" ?
$ echo "You have `ls | wc –l` files in `pwd`"
You have 34 files in /home/user
$ echo "The value of $x is $x"
The value of $x is 100
27. Command forms
cmd1 ; cmd2 Multiple commands on the same line
{ cmd1 ; cmd2 } Commands as a group in current shell
(cmd1 ; cmd2) Commands as a group in a subshell
cmd1 | cmd2 Pipe
cmd1 && cmd2 AND; cmd1, then cmd2 if (cmd succeeds)
cmd1 || cmd2 OR
28. Example (command forms)
$ cd; ls
Execute sequentially
$ (date; who; pwd) > logfile
All output is redirected
$ sort file | pr -3
Sort file, page output, then print
$ grep XX file && cat file
Print file if it contains the pattern;
$ grep XX file || echo "XX not found"
otherwise, echo not found message
29. Arguments
#!/bin/sh
##############################
echo "Script name is [$0]"
echo "First argument is [$1]"
echo "Second argument is [$2]"
echo "This process ID is [$$]"
echo "This argument count is [$#]"
echo "All arguments [$@]“
• The variable $*, is similar, but does not preserve any whitespace, and
quoting,
so "File with spaces" becomes "File" "with" "spaces".
30. Example (Arguments) Output:
hoai@moon:~> my_script.sh DBNAME 1 BACKUP
Script name is [my_script.sh]
First argument is [DBNAME]
Second argument is [1]
This process ID is [5401]
This argument count is [3]
• All arguments [DBNAME 1 BACKUP]
31. Simple commands
sort Sort lines
grep Search for regular expressions
find search for files in a directory hierarchy
sed stream editor for filtering and transforming text
cut Chop up a text by strings or characters
awk Pattern scanning and processing language
tr 'a' 'b' Transform characters
expr Simple arithmetic processor
date Create date strings
head/tail Access lines in files
32. Example (Simple commands -1)
• #Sort
sort data.txt >sort_f.txt OR sort -o output.txt data.txt
sort -k 2 data.txt
• #grep
• grep –nv ^$ file.txt
• grep –w “string” filename
• #Sed
• sed –n ‘25p’ file.txt
• sed ‘s/n/xyz/’ file.txt OR sed ‘s/n/xyz/g’ file.txt
• sed –e ‘s/f/rr/g’ –e ‘s/a/1234/g’ –e ‘s/n/UNIX/g’ file.txt
• #Find
• find /path1/path2/ -type f -name "Alca*tel.txt"
• find ./ -type f|xargs grep “string”
34. Crontab Job Scheduling
• Command
Crontab –l , -e, -r (l-list, e-edit, r-remove). Crontab
have six fields separated either of space or tab. The beginning
five fields represent time to run tasks and last field is for
command.
• -Minute (hold values between 0-59)
• -Hour (hold values between 0-23)
• -Day of Month (hold values between 1-31)
• -Month of the year (hold values between 1-12)
• -Day of week (hold values between 0-6 or Sun-Sat)
• -Command
• Example:
• 00 11,13 * * * sh /home/user/backup_job.sh DB >/home/user/file_bkp.log
35. Example Script-1 (for loop)
#!/bin/sh
alphabet="a b c d e" # Initialise a string
count=0 # Initialise a counter
for letter in $alphabet # Set up a loop control
do # Begin the loop
count=`expr $count + 1` # Increment the counter
# Display the result
echo "Letter $count is [$letter]"
done
36. Example Script-2 (if/else condition)
• #!/bin/sh
• a=10
• b=20
•
if [ $a == $b ]
• then
• echo "a is equal to b"
• elif [ $a -gt $b ]
• then
• echo "a is greater than b"
• elif [ $a -lt $b ]
• then
• echo "a is less than b"
• else
• echo "None of the condition met"
• fi