Skip to content

Instantly share code, notes, and snippets.

@balajeerc
Last active October 8, 2023 16:18
Show Gist options
  • Save balajeerc/2dc1f1bba474bd914d77f05e7e7ea48e to your computer and use it in GitHub Desktop.
Save balajeerc/2dc1f1bba474bd914d77f05e7e7ea48e to your computer and use it in GitHub Desktop.
Bash Snippets

Bash Snippets

Checking the video driver in use

lspci -k | grep -EA3 'VGA|3D|Display'

Encrypting and Decrypting tars

Encrypt:

tar cz folder_to_encrypt | openssl enc -aes-256-cbc -e > out.tar.gz.enc

Decrypt using OpenSSL:

openssl enc -aes-256-cbc -d -in out.tar.gz.enc | tar xz

Decrypt using PGP:

gpg --encrypt out.tar.gz

Running a command for every line in a file

cat [filename] | while read line; do [command] "$line"; done

Run a command in an infinite while loop

while true; do echo 'Press CTRL+C to stop the script execution'; done

Watch a series of files and run a command when any file is changed

Install two utilities ag and entr:

sudo aptitude install silversearcher-ag entr

Then start watching to invoke a callback command:

ag -l | grep src | entr -p echo /_ "changed"

Extracting columns from output using awk

ps -eff | grep -v grep | grep "celery worker" | awk '{print $2}'

Executing commands using xargs

ps -eff | grep -v grep | grep "celery worker" | xargs -I {} kill -15 {}

Running find and running a command on matching results

find . -name "*.swp" | xargs -I '{}' rm '{}'

Running a container that crashes and using bash intead of default command in Dockerfile

docker run -p 8008:8008 --env-file chanakya_env.list -it --entrypoint /bin/bash sensibull/chanakya-staging
docker run -p 8099:8099 --env-file /home/ubuntu/chanakya_jobserver_env.list --name chanakya-jobserver-instance -it --entrypoint /bin/bash sensibull/chanakya-jobserver-st
aging                                     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment