Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:42:18+00:00 2026-06-11T06:42:18+00:00

I have JUST started looking into the world of scripting, specifically with with bash,

  • 0

I have JUST started looking into the world of scripting, specifically with with bash, and am trying to write a simple script to copy the contents of a folder (that contains sub-folders) to a back-up location on an external flash drive (trying to back-up Thunderbird’s data). I’ve looked at a couple of tutorials and what I’m running into are issues with how to navigate to parent directories within the script. The folder I want to copy exists in the directory 1 above where my script file lies. To get to the hard drive I’ve got to back-up through two parent directories… Here’s what I’ve created (I’m running ubuntu 12.04):

#! /bin/bash

#this attepmts to copy the profile folder for Thunderbird to the backup drive
echo "...attempting to copy Thunderbird Profile to back-up drive (My Passport)"

#attempt to backup two directories to where media folder (and therefore My Passport is located)
parent=$(dirname $PWD)
grandparent=$(dirname $parent)
greatgrand=$(dirname $grandparent)

#show what directories the variables are set to
echo "...parent: $parent"
echo "...grandparent: $grandparent"
echo "...greatgrand: $greatgrand"

echo "...copying..."

#FIRST SUBSHELL 
#create a subshell and cd to directory to copy && tar directory
#tar: -c = create tarball, -f = tells it what to create " - " = is the unix convention for stdout (this goes with the -f) " . " = means the whole directory.  I the end this first subshell is creating a tarball and dumping it in stdout
# | = pipe
#SECOND SUBSHELL

(cd /mcp/.thunderbird/lOdhn9gd.default && tar -cf - .) | (cd $greatgrand/media/My Passport/Gmail_to_Thunderbird_Backup && tar -xpf -)

When I run this I get:

mcp@mcp-Satellite-A135:~/BashScriptPractice$ ./thunderProfileBU.sh
...attempting to copy Thunderbird Profile to back-up drive (My Passport)
...parent: /home/mcp
...grandparent: /home
...greatgrand: /
...copying...
./thunderProfileBU.sh: line 23: cd: //media/My: No such file or directory
./thunderProfileBU.sh: line 23: cd: /mcp/.thunderbird/lOdhn9gd.default: No such file or directory

I should be starting in the directory “/mcp”. I’m guessing I don’t need it in the first sub-script (the last line) above but when I tried to just use “cd /.thunderbird/lOdhn9g…” I was still getting the error. For the second sub-script I’m not sure exactly what is happening. Am I just misunderstanding the folder navigation syntax?

Also, this is a side question but is scripting in this manner something a software developer should know how to do or is this kind of thing more reserved for system admins? I haven’t taken any scripting classes or do I know of any offered through my university however I find it interesting and can see how it could be pretty useful… Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:42:20+00:00Added an answer on June 11, 2026 at 6:42 am

    Instead of using dirname to get the parent of each directory, you could use .., where $greatgrand is simply ../../...

    Now relying on parent directories in a script is often a bad idea because you have to garantee that they exist.

    There’s two places where your script fails:

    ./thunderProfileBU.sh: line 23: cd: //media/My: No such file or directory
    

    You should protect the directory name since it contains spaces, and spaces are an argument separator.

    ./thunderProfileBU.sh: line 23: cd: /mcp/.thunderbird/lOdhn9gd.default: No such file or directory
    

    The directory you want to copy doen’t exist. I’m guessing you want ~mcp instead, or /home/mcp.

    If what you want is to backup your thunderbird preferences to an external drive, you should use rsync:

    # Make sure directory exists
    mkdir -p "/media/My Passport/Gmail_to_Thunderbird_Backup"
    # Copy the contents recursively
    rsync -av "~/.thunderbird/lOdhn9gd.default/" "/media/My Passport/Gmail_to_Thunderbird_Backup"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just getting started couchdb and have been looking into writing couch apps.
I have just started looking into .net MVC and I really like it. There
I have just started looking into msbuild, because I want to make my own
I have just started looking into using Modules in Flex and would like to
I have just started using RSpec and I copied the very simple test on
I have just started learning python version 3 and trying to create a file
I just started looking into the use of jQuery UI. What I would like
I just started looking into Raphael, and every tutorial said that you may draw
I have started looking into the Rabbyt library and so far I am really
How would you test this scenario? I've just started looking into NHibernate and having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.