BASH basics
- acronym for "Bourne Again Shell"
- allows for command and script processing
- supports piping i.e.:
$env | more
will add page breaks when displaying the information:
- For help "man" can be used to access detailed information about command i.e.:
$man pwd
will return:
- sample commands:
pwd - print current working directory
ls - list files and directories, optionally can be used with "-a" (show all including hidden files) or "-l" to list permissions and user/group ownership, example:
mkdir - create directory
rm - deletes file or directory, useful flag "-rf" to force remove all files within deleted
folder
cp - copy file or folder, does not delete the source file
mv - move file/folder between directories, also can be used to rename files/folders
using "mv -f " will force overwrite if destination file already exists
cat - can be used to view or create files,
useful example $cat filename.txt | more
touch - used to create an empty file or change the time stamp without opening it
- running commands at the admin level "sudo" can be used, example:
$sudo apt-get update - this will prompt user to enter password before proceeding with an update of the list of available packages
- environment variables:
env - to view current set of variables, example: $env | more
echo - can be used to display single variable i.e.: echo $PATH
export - can be used to add new variable i.e.: export PASS=c1sco
unset - can be used to remove variable i.e.: unset PASS
note! newly created variable will be lost after session reload unless it is added to .bashrc file (or .zshrc on MacOS)
to add variable, example:
$echo "export PASS=c1sco" >> .bashrc
to reload the variables:
$source ~/.bashrc or $. ~/.bashrc