Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Linux Shell Scripting Cookbook
Linux Shell Scripting Cookbook

Linux Shell Scripting Cookbook: Do amazing things with the shell and automate tedious tasks , Third Edition

Arrow left icon
Profile Icon Clif Flynt Profile Icon Sarath Lakshman Profile Icon Shantanu Tushar
Arrow right icon
€41.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (4 Ratings)
Paperback May 2017 552 pages 3rd Edition
eBook
€32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €11.99p/m
Arrow left icon
Profile Icon Clif Flynt Profile Icon Sarath Lakshman Profile Icon Shantanu Tushar
Arrow right icon
€41.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (4 Ratings)
Paperback May 2017 552 pages 3rd Edition
eBook
€32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €11.99p/m
eBook
€32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €11.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Linux Shell Scripting Cookbook

Chapter 2. Have a Good Command

In this chapter, we will cover the following recipes:

  • Concatenating with cat
  • Recording and playing back terminal sessions
  • Finding files and file listing
  • Playing with xargs
  • Translating with tr
  • Checksum and verification
  • Cryptographic tools and hashes
  • Sorting unique and duplicate lines
  • Temporary file naming and random numbers
  • Splitting files and data
  • Slicing filenames based on extensions  
  • Renaming and moving files in bulk
  • Spell–checking and dictionary manipulation   
  • Automating interactive input
  • Making commands quicker by running parallel processes
  • Examining a directory, files and subdirectories in it

Introduction


Unix-like systems have the best command-line tools. Each command performs a simple function to make our work easier. These simple functions can be combined with other commands to solve complex problems. Combining simple commands is an art; you will get better at it as you practice and gain experience. This chapter introduces some of the most interesting and useful commands, including grep, awk, sed, and find.

Concatenating with cat


The cat command displays or concatenates the contents of a file, but cat is capable of more. For example, cat can combine standard input data with data from a file. One way of combining the stdin data with file data is to redirect stdin to a file and then append two files. The cat command can do this in a single invocation. The next recipes show basic and advanced usages of cat.

How to do it...

The cat command is a simple and frequently used command and it stands for conCATenate.

The general syntax of cat for reading contents is as follows:

$ cat file1 file2 file3 ...

This command concatenates data from the files specified as command-line arguments and sends that data to stdout.

  • To print contents of a single file, execute the following command:
$ cat file.txt
        This is a line inside file.txt
        This is the second line inside file.txt

 

  • To print contents of more than one file, execute the following command:
$ cat one.txt two.txt 
        This line is from one.txt
...

Recording and playing back terminal sessions


Recording a screen session as a video is useful, but a video is an overkill for debugging terminal sessions or providing a shell tutorial.

The shell provides another option. The script command records your keystrokes and the timing of keystrokes as you type, and saves your input and the resulting output in a pair of files. The scriptreplay command will replay the session.

Getting ready

The script and scriptreplay commands are available in most GNU/Linux distributions. You can create tutorials of command-line hacks and tricks by recording the terminal sessions. You can also share the recorded files for others to playback and see how to perform a particular task with the command line. You can even invoke other interpreters and record the keystrokes sent to that interpreter. You cannot record vi, emacs, or other applications that map characters to particular locations on the screen.

How to do it...

Start recording the terminal session with the following...

Finding files and file listing


The find command is one of the great utilities in the Unix/Linux command-line toolbox. It is useful both at the command line and in shell scripts. Like cat and ls, find has many features, and most people do not use it to its fullest. This recipe deals with some common ways to utilize find to locate files.

Getting ready

The find command uses the following strategy:  find descends through a hierarchy of files, matches files that meet the specified criteria, and performs some actions. The default action is to print the names of files and folders, which can be specified with the -print option.

How to do it...

To list all the files and folders descending from a given directory, use this syntax:

$ find base_path

The base_path can be any location from which find should start descending (for example, /home/slynux/).

Here's an example of this command:

$ find . -print
.history
Downloads
Downloads/tcl.fossil
Downloads/chapter2.doc

The . specifies the current directory and ....

Playing with xargs


Unix commands accept data either from the standard input (stdin) or as command line arguments. Previous examples have shown how to pass data from one application's standard output to another's standard input with a pipe.

We can invoke applications that accept command-line arguments in other ways. The simplest is to use the back-tic symbol to run a command and use its output as a command line:

$ gcc `find '*.c'`

This solution works fine in many situations, but if there are a lot of files to be processed, you'll see the dreaded Argument list too long error message. The xargs program solves this problem.

The xargs command reads a list of arguments from stdin and executes a command using these arguments in the command line. The xargs command can also convert any one-line or multiple-line text inputs into other formats, such as multiple lines (specified number of columns) or a single line, and vice versa.

Getting ready

The xargs command should be the first command to appear after...

Translating with tr


The tr command is a versatile tool in the Unix command–warrior's kit. It is used to craft elegant one-liner commands. It performs substitution of characters, deletes selected characters, and can squeeze repeated characters from the standard input. Tr is short for translate, since it translates a set of characters to another set. In this recipe, we will see how to use tr to perform basic translation between sets.

Getting ready

The tr command accepts input through stdin (standard input) and cannot accept input through command-line arguments. It has this invocation format:

tr [options] set1 set2

Input characters from stdin are mapped from the first character in set1 to the first character in set2, and so on and the output is written to stdout (standard output). set1 and set2 are character classes or a set of characters. If the length of sets is unequal, set2 is extended to the length of set1 by repeating the last character; otherwise if the length of set2 is greater than that...

Checksum and verification


Checksum programs are used to generate a relatively small unique key from files. We can recalculate the key to confirm that a file has not changed. Files may be modified deliberately (adding a new user changes the password file), accidentally (a data read error from a CD-ROM drive), or maliciously (a virus is inserted). Checksums let us verify that a file contains the data we expect it to.

Checksums are used by backup applications to check whether a file has been modified and needs to be backed up.

Most software distributions also have a checksum file available. Even robust protocols such as TCP can allow a file to be modified in transit. Hence, we need to know whether the received file is the original one or not by applying some kind of test.

By comparing the checksum of the file we downloaded with the checksum calculated by the distributer, we can verify that the received file is correct. If the checksum calculated from the original file at the source location matches...

Cryptographic tools and hashes


Encryption techniques are used to protect data from unauthorized access. Unlike the checksum algorithms we just discussed, encryption programs can reconstruct the original data with no loss. There are many algorithms available and we will discuss those most commonly used in the Linux/Unix world.

How to do it...

Let's see how to use tools such as crypt, gpg, and base64:

  • The crypt command is not commonly installed on Linux systems. It's a simple and relatively insecure cryptographic utility that accepts input from stdin, requests a passphrase, and sends encrypted output to stdout:
$ crypt <input_file >output_file
        Enter passphrase:

We can provide a passphrase on the command line:

$ crypt PASSPHRASE <input_file >encrypted_file

In order to decrypt the file, use this:

$ crypt PASSPHRASE -d <encrypted_file >output_file
  • gpg (GNU privacy guard) is a widely used tool for protecting files to ensure that data is not read until it reaches its intended destination...

Sorting unique and duplicate lines


Sorting text files is a common task. The sort command sorts text files and stdin. It can be coupled with other commands to produce the required output. uniq is often used with sort to extract unique (or duplicate) lines. The following recipes illustrate some sort and uniq use cases.

Getting ready

The sort and uniq commands accept input as filenames or from stdin (standard input) and output the result by writing to stdout.

How to do it...

  1. We can sort a set of files (for example, file1.txt and file2.txt), like this:
$ sort file1.txt file2.txt > sorted.txt

 Alternatively, use this:

$ sort file1.txt file2.txt -o sorted.txt
  1. For a numerical sort, we use this:
$ sort -n file.txt
  1. To sort in the reverse order, we use the following command:
$ sort -r file.txt
  1. To sort by months (in the order Jan, Feb, March,...), use this:
$ sort -M months.txt
  1. To merge two already sorted files, use this command:
$ sort -m sorted1 sorted2
  1. To find the unique lines from a sorted file, use this:
$...

Temporary file naming and random numbers


Shell scripts often need to store temporary data. The most suitable location to do this is /tmp (which will be cleaned out by the system on reboot). There are two methods to generate standard filenames for temporary data.

How to do it...

The mktemp command will create a unique temporary file or folder name:

  1. Create a temporary file:
$ filename=`mktemp`
        $ echo $filename
        /tmp/tmp.8xvhkjF5fH

This creates a temporary file, stores the name in filename, and then displays the name.

  1. Create a temporary directory:
$ dirname=`mktemp -d`
        $ echo $dirname
        tmp.NI8xzW7VRX

This creates a temporary directory, stores the name in filename, and displays the name.

  • To generate a filename without creating a file or directory, use this:
    $ tmpfile=`mktemp -u`
                    $ echo $tmpfile
                    /tmp/tmp.RsGmilRpcT

    Here, the filename is stored in $tmpfile, but the file won't be created.

    • To create the temporary filename based on a template, use...

    Splitting files and data


    Splitting a large file into smaller pieces is sometimes necessary. Long ago, we had to split files to transport large datasets on floppy disks. Today, we split files for readability, for generating logs, or for working around size-restrictions on e-mail attachments. These recipes will demonstrate ways of splitting files in different chunks.

    How to do it...

    The split command was created to split files. It accepts a filename as an argument and creates a set of smaller files in which the first part of the original file is in the alphabetically first new file, the next set in the alphabetically next file, and so on.

    For example, a 100 KB file can be divided into smaller files of 10k each by specifying the split size. The split command supports M for MB, G for GB, c for byte, and w for word.

    $ split -b 10k data.file
    $ ls
    data.file  xaa  xab  xac  xad  xae  xaf  xag  xah  xai  xaj

    The preceding code will split data.file into ten files of 10k each. The new files are named xab...

    Slicing filenames based on extensions


    Many shell scripts perform actions that involve modifying filenames. They may need to rename the files and preserve the extension, or convert files from one format to another and change the extension, while preserving the name, extracting a portion of the filename, and so on.

    The shell has built-in features for manipulating filenames.

    How to do it...

    The % operator will extract the name from name.extension. This example extracts sample from sample.jpg:

    file_jpg="sample.jpg" 
    name=${file_jpg%.*} 
    echo File name is: $name 

    The output is this:

    File name is: sample

    The # operator will extract the extension:

    Extract .jpg from the filename stored in the file_jpg variable:

    extension=${file_jpg#*.} 
    echo Extension is: jpg 

    The output is as follows:

    Extension is: jpg

    How it works...

    To extract the name from the filename formatted as name.extension, we use the % operator.

    ${VAR%.*} is interpreted as follows:

    • Remove the string match from $VAR for the wildcard pattern that appears...

    Renaming and moving files in bulk


    We frequently need to move and perhaps rename a set of files. System housekeeping often requires moving files with a common prefix or file type to a new folder. Images downloaded from a camera may need to be renamed and sorted. Music, video, and e-mail files all need to be reorganized eventually.

    There are custom applications for many of these operations, but we can write our own custom scripts to do it our way.

    Let's see how to write scripts to perform these kinds of operation.

    Getting ready

    The rename command changes filenames using Perl regular expressions. By combining the find, rename, and mv commands, we can perform a lot of things.

    How to do it...

    The following script uses find to locate PNG and JPEG files, then uses the ## operator and mv to rename them as image-1.EXT, image-2.EXT, and so on. This changes the file's name, but not its extension:

    #!/bin/bash 
    #Filename: rename.sh 
    #Desc: Rename jpg and png files 
    
    count=1; 
    for img in `find . -iname '*.png...

    Spell–checking and dictionary manipulation


    Most Linux distributions include a dictionary file. However, very few people are aware of this, thus spelling errors abound. The aspell command-line utility is a spell checker. Let's go through a few scripts that make use of the dictionary file and the spell checker.

    How to do it...

    The /usr/share/dict/ directory contains one or perhaps more dictionary files, which are text files with a list of words. We can use this list to check whether a word is a dictionary word or not:

    $ ls /usr/share/dict/ 
    american-english  british-english

    To check whether the given word is a dictionary word, use the following script:

    #!/bin/bash 
    #Filename: checkword.sh 
    word=$1 
    grep "^$1$" /usr/share/dict/british-english -q  
    if [ $? -eq 0 ]; then 
      echo $word is a dictionary word; 
    else 
      echo $word is not a dictionary word; 
    fi 

    The usage is as follows:

    $ ./checkword.sh ful 
    ful is not a dictionary word 
    
    $ ./checkword.sh fool 
    fool is a dictionary word

    How it works...

    In grep...

    Automating interactive input


    We looked at commands that accept arguments on the command line. Linux also supports many interactive applications ranging from passwd to ssh.

    We can create our own interactive shell scripts. It's easier for casual users to interact with a set of prompts rather than remember command line flags and the proper order. For instance, a script to back up a user's work, but not to back up and lock files, might look like this:

    $ backupWork.sh
    • What folder should be backed up? notes
    • What type of files should be backed up? .docx

    Automating interactive applications can save you time when you need to rerun the same application and frustration while you're developing one.

    Getting ready

    The first step to automating a task is to run it and note what you do. The script command discussed earlier may be of use.

    How to do it...

    Examine the sequence of interactive inputs. From the previous code, we can formulate the steps of the sequence like this:

    notes[Return]docx[Return] 

    In addition to...

    Making commands quicker by running parallel processes


    Computing power constantly increases not only because processors have higher clock cycles but also because they have multiple cores. This means that in a single hardware processor there are multiple logical processors. It's like having several computers, instead of just one.

    However, multiple cores are useless unless the software makes use of them. For example, a program that does huge calculations may only run on one core while the others will sit idle. The software has to be aware and take advantage of the multiple cores if we want it to be faster.

    In this recipe, we will see how we can make our commands run faster.

    How to do it...

    Let's take an example of the md5sum command we discussed in the previous recipes. This command performs complex computations, making it CPU-intensive. If we have more than one file that we want to generate a checksum for, we can run multiple instances of md5sum using a script like this:

    #/bin/bash 
    #filename:...

    Examining a directory, files and subdirectories in it


    One of the commonest problems we deal with is finding misplaced files and sorting out mangled file hierarchies. This section will discuss tricks for examining a portion of the filesystem and presenting the contents.

    Getting ready

    The find command and loops we discussed give us tools to examine and report details in a directory and its contents.

    How to do it...

    The next recipes show two ways to examine a directory. First we'll display the hierarchy as a tree, then we'll see how to generate a summary of files and folders under a directory.

    Generating a tree view of a directory.

    Sometimes it's easier to visualize a file system if it's presented graphically.

    The next recipe pulls together several of the tools we discussed. It uses the find command to generate a list of all the files and sub-folders under the current folder.

    The -exec option creates a subshell which uses echo to send the filenames to the tr command's stdin. There are two tr commands...

    Left arrow icon Right arrow icon

    Key benefits

    • Become an expert in creating powerful shell scripts and explore the full possibilities of the shell
    • Automate any administrative task you could imagine, with shell scripts
    • Packed with easy-to-follow recipes on new features on Linux, particularly, Debian-based, to help you accomplish even the most complex tasks with ease

    Description

    The shell is the most powerful tool your computer provides. Despite having it at their fingertips, many users are unaware of how much the shell can accomplish. Using the shell, you can generate databases and web pages from sets of files, automate monotonous admin tasks such as system backups, monitor your system's health and activity, identify network bottlenecks and system resource hogs, and more. This book will show you how to do all this and much more. This book, now in its third edition, describes the exciting new features in the newest Linux distributions to help you accomplish more than you imagine. It shows how to use simple commands to automate complex tasks, automate web interactions, download videos, set up containers and cloud servers, and even get free SSL certificates. Starting with the basics of the shell, you will learn simple commands and how to apply them to real-world issues. From there, you'll learn text processing, web interactions, network and system monitoring, and system tuning. Software engineers will learn how to examine system applications, how to use modern software management tools such as git and fossil for their own work, and how to submit patches to open-source projects. Finally, you'll learn how to set up Linux Containers and Virtual machines and even run your own Cloud server with a free SSL Certificate from letsencrypt.org.

    Who is this book for?

    If you are a beginner or an intermediate Linux user who wants to master the skill of quickly writing scripts and automate tasks without reading the entire man pages, then this book is for you. You can start writing scripts and one-liners by simply looking at the relevant recipe and its descriptions without any working knowledge of shell scripting or Linux. Intermediate / advanced users, system administrators / developers, and programmers can use this book as a reference when they face problems while coding.

    What you will learn

    • • Interact with websites via scripts
    • • Write shell scripts to mine and process data from the Web
    • • Automate system backups and other repetitive tasks with crontab
    • • Create, compress, and encrypt archives of your critical data.
    • • Configure and monitor Ethernet and wireless networks
    • • Monitor and log network and system activity
    • • Tune your system for optimal performance
    • • Improve your system s security
    • • Identify resource hogs and network bottlenecks
    • • Extract audio from video files
    • • Create web photo albums
    • • Use git or fossil to manage revision control and interact with FOSS projects
    • • Create and maintain Linux containers and Virtual Machines
    • • Run a private Cloud server
    Estimated delivery fee Deliver to Finland

    Premium delivery 7 - 10 business days

    €17.95
    (Includes tracking information)

    Product Details

    Country selected
    Publication date, Length, Edition, Language, ISBN-13
    Publication date : May 29, 2017
    Length: 552 pages
    Edition : 3rd
    Language : English
    ISBN-13 : 9781785881985
    Tools :

    What do you get with Print?

    Product feature icon Instant access to your digital copy whilst your Print order is Shipped
    Product feature icon Paperback book shipped to your preferred address
    Product feature icon Redeem a companion digital copy on all Print orders
    Product feature icon Access this title in our online reader with advanced features
    Product feature icon DRM FREE - Read whenever, wherever and however you want
    OR
    Modal Close icon
    Payment Processing...
    tick Completed

    Shipping Address

    Billing Address

    Shipping Methods
    Estimated delivery fee Deliver to Finland

    Premium delivery 7 - 10 business days

    €17.95
    (Includes tracking information)

    Product Details

    Publication date : May 29, 2017
    Length: 552 pages
    Edition : 3rd
    Language : English
    ISBN-13 : 9781785881985
    Tools :

    Packt Subscriptions

    See our plans and pricing
    Modal Close icon
    €11.99 billed monthly
    Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
    Feature tick icon Constantly refreshed with 50+ new titles a month
    Feature tick icon Exclusive Early access to books as they're written
    Feature tick icon Solve problems while you work with advanced search and reference features
    Feature tick icon Offline reading on the mobile app
    Feature tick icon Simple pricing, no contract
    €119.99 billed annually
    Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
    Feature tick icon Constantly refreshed with 50+ new titles a month
    Feature tick icon Exclusive Early access to books as they're written
    Feature tick icon Solve problems while you work with advanced search and reference features
    Feature tick icon Offline reading on the mobile app
    Feature tick icon Choose a DRM-free eBook or Video every month to keep
    Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
    Feature tick icon Exclusive print discounts
    €169.99 billed in 18 months
    Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
    Feature tick icon Constantly refreshed with 50+ new titles a month
    Feature tick icon Exclusive Early access to books as they're written
    Feature tick icon Solve problems while you work with advanced search and reference features
    Feature tick icon Offline reading on the mobile app
    Feature tick icon Choose a DRM-free eBook or Video every month to keep
    Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
    Feature tick icon Exclusive print discounts

    Frequently bought together


    Stars icon
    Total 169.97
    Working with Linux ??? Quick Hacks for the Command Line
    €32.99
    Linux Shell Scripting Cookbook
    €41.99
    Linux: Powerful Server Administration
    €94.99
    Total 169.97 Stars icon
    Visually different images

    Table of Contents

    13 Chapters
    Shell Something Out Chevron down icon Chevron up icon
    Have a Good Command Chevron down icon Chevron up icon
    File In, File Out Chevron down icon Chevron up icon
    Texting and Driving Chevron down icon Chevron up icon
    Tangled Web? Not At All! Chevron down icon Chevron up icon
    Repository Management Chevron down icon Chevron up icon
    The Backup Plan Chevron down icon Chevron up icon
    The Old-Boy Network Chevron down icon Chevron up icon
    Put On the Monitors Cap Chevron down icon Chevron up icon
    Administration Calls Chevron down icon Chevron up icon
    Tracing the Clues Chevron down icon Chevron up icon
    Tuning a Linux System Chevron down icon Chevron up icon
    Containers, Virtual Machines, and the Cloud Chevron down icon Chevron up icon

    Customer reviews

    Rating distribution
    Full star icon Full star icon Full star icon Full star icon Empty star icon 4
    (4 Ratings)
    5 star 50%
    4 star 0%
    3 star 50%
    2 star 0%
    1 star 0%
    RAGHAV Mar 21, 2018
    Full star icon Full star icon Full star icon Full star icon Full star icon 5
    book recieved in great condition.
    Amazon Verified review Amazon
    Raj Jun 03, 2019
    Full star icon Full star icon Full star icon Full star icon Full star icon 5
    👍👍👍👍👍👍✌✌✌✌✌🕵️‍♀️🕵️‍♀️💗
    Amazon Verified review Amazon
    qishan2002 Jan 08, 2018
    Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
    Very lengthy illustration of the command options some of which are quite useful and some are quite obscure and we can do without. The book is overall weak in with respect to scripting -- have commands work together.
    Amazon Verified review Amazon
    Amazon Customer Jan 28, 2018
    Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
    I would expect a book about Linux Shell Scripting to be be about actually scripting. This book shows you how to write glorified commands but is anemic with regards to actual scripting. If your goal is to write better commands and even how to structure them, this is your book but with hardcore scripting techniques, I can't reasonably encourage you to purchase this one.
    Amazon Verified review Amazon
    Get free access to Packt library with over 7500+ books and video courses for 7 days!
    Start Free Trial

    FAQs

    What is the delivery time and cost of print book? Chevron down icon Chevron up icon

    Shipping Details

    USA:

    '

    Economy: Delivery to most addresses in the US within 10-15 business days

    Premium: Trackable Delivery to most addresses in the US within 3-8 business days

    UK:

    Economy: Delivery to most addresses in the U.K. within 7-9 business days.
    Shipments are not trackable

    Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
    Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

    EU:

    Premium: Trackable delivery to most EU destinations within 4-9 business days.

    Australia:

    Economy: Can deliver to P. O. Boxes and private residences.
    Trackable service with delivery to addresses in Australia only.
    Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
    Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

    Premium: Delivery to addresses in Australia only
    Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

    India:

    Premium: Delivery to most Indian addresses within 5-6 business days

    Rest of the World:

    Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

    Asia:

    Premium: Delivery to most Asian addresses within 5-9 business days

    Disclaimer:
    All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


    Unfortunately, due to several restrictions, we are unable to ship to the following countries:

    1. Afghanistan
    2. American Samoa
    3. Belarus
    4. Brunei Darussalam
    5. Central African Republic
    6. The Democratic Republic of Congo
    7. Eritrea
    8. Guinea-bissau
    9. Iran
    10. Lebanon
    11. Libiya Arab Jamahriya
    12. Somalia
    13. Sudan
    14. Russian Federation
    15. Syrian Arab Republic
    16. Ukraine
    17. Venezuela
    What is custom duty/charge? Chevron down icon Chevron up icon

    Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

    Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

    The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

    List of EU27 countries: www.gov.uk/eu-eea:

    A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

    How do I know my custom duty charges? Chevron down icon Chevron up icon

    The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

    For example:

    • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
    • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
    How can I cancel my order? Chevron down icon Chevron up icon

    Cancellation Policy for Published Printed Books:

    You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

    Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

    What is your returns and refunds policy? Chevron down icon Chevron up icon

    Return Policy:

    We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

    1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
    2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
    3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
    4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
    5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
    6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

    On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

    What tax is charged? Chevron down icon Chevron up icon

    Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

    What payment methods can I use? Chevron down icon Chevron up icon

    You can pay with the following card types:

    1. Visa Debit
    2. Visa Credit
    3. MasterCard
    4. PayPal
    What is the delivery time and cost of print books? Chevron down icon Chevron up icon

    Shipping Details

    USA:

    '

    Economy: Delivery to most addresses in the US within 10-15 business days

    Premium: Trackable Delivery to most addresses in the US within 3-8 business days

    UK:

    Economy: Delivery to most addresses in the U.K. within 7-9 business days.
    Shipments are not trackable

    Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
    Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

    EU:

    Premium: Trackable delivery to most EU destinations within 4-9 business days.

    Australia:

    Economy: Can deliver to P. O. Boxes and private residences.
    Trackable service with delivery to addresses in Australia only.
    Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
    Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

    Premium: Delivery to addresses in Australia only
    Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

    India:

    Premium: Delivery to most Indian addresses within 5-6 business days

    Rest of the World:

    Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

    Asia:

    Premium: Delivery to most Asian addresses within 5-9 business days

    Disclaimer:
    All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


    Unfortunately, due to several restrictions, we are unable to ship to the following countries:

    1. Afghanistan
    2. American Samoa
    3. Belarus
    4. Brunei Darussalam
    5. Central African Republic
    6. The Democratic Republic of Congo
    7. Eritrea
    8. Guinea-bissau
    9. Iran
    10. Lebanon
    11. Libiya Arab Jamahriya
    12. Somalia
    13. Sudan
    14. Russian Federation
    15. Syrian Arab Republic
    16. Ukraine
    17. Venezuela