Snippets of scripting
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 thefiles.txt
file.-p
: It is an option forcpio
that tells it to copy files while preserving their directory structure.-d
: It is another option forcpio
that creates directories as needed while copying files.< files.txt
: The<
symbol is a shell redirection operator that takes the input from thefiles.txt
file and provides it as input to thecpio
command. Thefiles.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 infiles.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
- 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
- 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