Skip to main content

20 posts tagged with "bash"

View All Tags

Date created: 2024-10-08

Description

Putting a [[detach-process-from-terminal|task in the background]] turns it into a background job. This is how we can manage tasks like that.

Go wild here

Running jobs in the terminal lists all foreground and background tasks running in the terminal, with a number associated with them.

$ jobs
[1]- Stopped vim .
[2]+ Stopped vim .
[3] Running idea &

The background ones usually have the & symbol shown after them, like idea in the example above. we can now call it into the foreground by saying fg 3, and manage it like a normal terminal process, e.g. closing it with [C-c].

Date created: 2024-10-02

Go wild here

Given an awk script script.awk, an input file source.csv, and an output file target.js, we can execute awk like the following:

$ awk -f script.awk ./source.csv > target.js

Date created: 2024-10-01

Switch current working directory to Git repository root

Note: since this spawns another terminal, it can't be used as a script file, and should instead be put into the .bashrc directly.

#!/bin/bash

# Ensure the script is being run from the root of a Git repository
GIT_ROOT=$(git rev-parse --show-toplevel)
if [ $? -ne 0 ]; then
echo "Error: Not inside a Git repository."
exit 1
fi

# Change to the Git root directory
cd "$GIT_ROOT" || exit 1
echo "Navigating to Git root: $GIT_ROOT"

Date created: 2024-10-06

Description

Ubuntu supports .deb packages for installation. This allows to convert .rpm packages into .deb, and install them on Ubuntu.

Go wild here

sudo add-apt-repository universe #Add the Universe Repository
sudo apt-get update
sudo apt-get install alien #Install Alien package
sudo alien <name of package>.rpm #Convert .rpm package to .deb
sudo dpkg -i <name of package>.deb #Install the Converted Package

Or directly install .rpm with alien:

sudo alien -i <name of package>.rpm    #Install RPM Package Directly Onto the System on Ubuntu

Date created: 2024-09-23

Resources and links

https://stackoverflow.com/questions/57335266/how-to-untar-a-file

If a file ends on .tar.gz

tar -xzvf <filename.tar.gz>

If you want to specify a directory to extract to:

tar  -xzvf  <filename.tar.gz>   -C  <output/dir>

Where,

  • -z : Work on gzip compression automatically when reading archives.
  • -x : Extract tar.gz archive.
  • -v : Produce verbose output (Display progress and extracted file list on screen).
  • -f : Read the archive from the archive to the specified file. (In this case, read example.tar.gz.)
  • -t : List the files in the archive.
  • -r : Append files to the end of the tarball.
  • –delete (GNU/Linux tar only) : Delete files from the tarball.

Date created: 2024-09-23

Resources and links

https://stackoverflow.com/questions/57335266/how-to-untar-a-file

If a file ends on .tar.xz

tar -xjvf <filename.tar.xz>

If you want to specify a directory to extract to:

tar  -xjvf  <filename.tar.xz>   -C  <output/dir>

Where,

  • -z : Work on bzip2 compression automatically when reading archives.
  • -x : Extract tar.xz archive.
  • -v : Produce verbose output (Display progress and extracted file list on screen).
  • -f : Read the archive from the archive to the specified file. (In this case, read example.tar.xz.)
  • -t : List the files in the archive.
  • -r : Append files to the end of the tarball.
  • –delete (GNU/Linux tar only) : Delete files from the tarball.