JustToThePoint English Website Version
JustToThePoint en español

Maximize your online presence with our exclusive offer: Get a stunning hero banner, the hero you need and deserve, at an unbeatable price! Bew, 689282782, bupparchard@gmail.com

Programming in Linux III. Useful scripts


All you need is #!/bin/bash

All you need is #!/bin/bash

Zsh, also called the Z shell, is an extended version of the Bourne Shell, with plenty of new features and support for plugins and themes.

Automate the “git, commit, and push”

# It automates the git, commit, and push process (.local/bin/gitpush.sh)
cd ~/dotfiles
git add .

echo 'Enter the commit message:'
read commitMessage

git commit -m "$commitMessage"
git push

Open any file from the command line

# Script to extract files, view images, read plain text files, play music, etc.

if [ -f $1 ] ; then
  case $1 in
    *.tar.bz2)  tar xjf $1     ;;
    *.tar.gz)   tar xzf $1     ;;
    *.tar.xz)   tar zxvf $1    ;;
    *.bz2)      bunzip2 $1     ;;
    *.rar)      rar x $1       ;;
    *.gz)       gunzip $1      ;;
    *.tar)      tar xf $1      ;;
    *.tbz2)     tar xjf $1     ;;
    *.tgz)      tar xzf $1     ;;
    *.xz)       xz -d $1       ;;
    *.zip)      unzip $1       ;;
    *.Z)        uncompress $1  ;;
    *.pdf)      evince $1      ;; # sudo pacman -S feh evince
    *.mov|*.avi|*.mpeg|*.mpg|*.flv|*.wmv|*.mp4|*.mp3) vlc $1    ;;
    *.doc|*.docx|*.xls|*.xlsx|*.ppt|*.pptx|*.odf) libreoffice $1 ;;
    *.txt|*.conf|*.sh|*.py|*.hs) atom --no-sandbox  $1;;
    *.png | *.jpeg | *.jpg) feh $1;;
    *)          xdg-open $1    ;;
  echo "'$1' is not recognized as a compressed file"

A small script to clone and build packages from AUR

aurpkgs="bpytop deadbeef"
for pkg in $aurpkgs; do
    git clone "https://aur.archlinux.org/$pkg.git"
    cd $pkg
    makepkg -si
    cd ..
    rm -rf $pkg

Deploying Hugo with Rsync.

USER=yourUser # Your hosting's username
HOST=yourHostingIPAddress # Your hosting's IP address
DIR=httpdocs/ # The directory where your website files should go, i.e., the web server root of your website

rm -r ./public
hugo # It builds the public folder.
duration=$SECONDS # It returns a count of the number of seconds the shell has been running.
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds took the task."

rsync --compress --recursive --verbose --checksum --delete -e 'ssh -p 2222' --delete public/ ${USER}@${HOST}:~/${DIR}

The syntax is rsync OPTIONS SOURCE [USER@]HOST:DEST.

  1. ‐‐delete allows remote deletion of files, so it mirrors or clones the local (public/) and remote directories (httpdocs/) and deletes extraneous files from the remote directory.
  2. -e ‘ssh -p 2222’ uses a non-standard SSH port (2222).
  3. SOURCE is the local directory, i.e., the Hugo’s default “public” directory in our local machine.
  4. [USER@]HOST:DEST indicates our hosting’s username, IP address, and destination directory.
  5. rsync compresses the file data as it is sent to the destination machine, so it reduces the amount of data being transmitted. It skips files that have likely not changed. We want files to be updated if they have a different size or checksum. I prefer to replace ‐‐archive with ‐‐recursive, because archive implies many options related to file metadata (owner, group, permissions, and timestamp), and I don’t want to update timestamps.

You can also use this script to backup in an external hard drive your Hugo proyect: rsync -aAXv ‐‐exclude ‘-cleanDestinationDir’ ‐‐exclude ‘-disableFastRender’ ‐‐delete $HOME/justtothepoint /run/media/nmaximo7/mydisk2/. A trailing slash on a source path (e.g., $HOME/justtothepoint/) means “copy the contents of this directory”. Without a trailing slash it means “copy the directory”.

Credits: Hugo, Deployment with Rsync, Nicholas Whittaker, A pretty Little Bit of Rsync.

More scripts: Bash file converter from (png, jpg, and jpeg) to webp., Scripts for checking broken links., Get information about your Linux system, and Awesome Bash. It is a curated list of delightful Bash scripts and resources.

Bitcoin donation

JustToThePoint Copyright © 2011 - 2024 Anawim. ALL RIGHTS RESERVED. Bilingual e-books, articles, and videos to help your child and your entire family succeed, develop a healthy lifestyle, and have a lot of fun. Social Issues, Join us.

This website uses cookies to improve your navigation experience.
By continuing, you are consenting to our use of cookies, in accordance with our Cookies Policy and Website Terms and Conditions of use.