Snippets of scripting

Vjola Velikaj
2 min readJun 19, 2023

Photo by Gabriel Heinzer on Unsplash

Hey there, recently I started my journey of scripting in Ubuntu terminal and I figured it would be a good idea to save my notes here. Below find snippets of scripting for different scenarios:

## — — — — — — — — — — — —— —1— —— — — — — — — —— — — — — ##
Platform: Ubuntu 🐧
Task: Copy files and directories from a list of text file into another directory by preserving the original structure

cpio -pd < files.txt <destination>/

Breakdown:

  • cpio: It is a command-line utility used to copy files to or from an archive, or to create an archive. In this case, it is used to copy files specified in the files.txt file.
  • -p: It is an option for cpio that tells it to copy files while preserving their directory structure.
  • -d: It is another option for cpio that creates directories as needed while copying files.
  • < files.txt: The < symbol is a shell redirection operator that takes the input from the files.txt file and provides it as input to the cpio command. The files.txt file presumably contains a list of files and directories to be copied.
  • destination/: It is the destination directory where the files and directories listed in files.txt will be copied to.

So, running this command will copy the files and directories listed in files.txt into the destination/ directory, preserving their original directory structure.

## — — — — — — — — — — ——— — 2— — — —— — — — — — — — — — — ##

Platform: Windows 🪟
Task: Export and archive repository with history

  1. For git repository without git LFS, use git bundle:
$ git clone --mirror <repo_url> <destination_folder>
$ cd <destination_folder>
$ git bundle create <repo_name>.bundle --all

2. Test bundle once created:

$ git clone -b <branch> "path\to\<repo_name>.bundle" <clone_destination_folder>

3. Compress <repo_name>.bundle archive it

  1. For git repository using git LFS:
$ git clone --mirror <repo_url> my-repo-mirror.git
$ cd my-repo-mirror.git
$ git lfs fetch --all
$ cd ..
$ git init --bare my-repo.git
$ cd my-repo-mirror.git
$ git remote add bare file://$(pwd)/../my-repo.git
$ git push --mirror bare
$ git lfs push --all bare

2. Compress my-repo.git.git and archive it

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Vjola Velikaj
Vjola Velikaj

Written by Vjola Velikaj

vjoli.xyz/ Postgraduate student with significant technical background, focused on product management practices, design and innovation.

No responses yet

Write a response