Skip to content

Instantly share code, notes, and snippets.

@dominiquesydow
Last active May 3, 2019 12:39
Show Gist options
  • Save dominiquesydow/85e588b6c71be68e473634402cd70cfb to your computer and use it in GitHub Desktop.
Save dominiquesydow/85e588b6c71be68e473634402cd70cfb to your computer and use it in GitHub Desktop.
Bash cheat sheet

Useful bash commands

My notes.

File/path/directory naming conventions

path=/home/dom/test.txt
dirname=/home/dom/
filename=test.txt
basename=test.txt
fileroot=test
extension=txt

Extract filename and extension

# Get string up to last occurrence of query (%)...
rootname="${filename%.*}"  # query="."
rootname="${filename%.tar.gz}"  # query=".tar.gz"

# Get string from last occurrence of query (##)...
filename="${path##*/}"  # Extract filename from path
extension="${filename##*.}"  # Extract extension from filename

Compress and decompress files

https://wiki.ubuntuusers.de/tar/

# Compress
tar -czf {folder/}

# Decompress
tar -zxvf {folder.tar.gz}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment