Bash is a command line-based shell program for UNIX/Linux systems.
Configuration
Any Bash settings are stored in the ~/.bashrc
file. Each time we edit it, we have to restart Bash for any changes to take effect. In particular, anything we define in the local shell instance (environment variables, sourcing commands from shell files) will not persist from session to session unless we add them to the .bashrc
file.
Some basic functionality we can use:
export ENV=value
— sets an environment variable with a particular value. Oftentimes, this is a file path.$ENV
— allows us to access particular environment variables.source file.sh
— executes the content of a given file in the shell. Oftentimes this is used to set useful environment variables dependent on the context.
Index of commands
Basic commands
pwd
prints the current working directory.ls
prints what is in the current working directory.cd
changes the current directory.cd ..
navigates up a folder.cd foldername
navigates into a folder.- For directories with spaces, we can wrap the folder name in quotation marks to access properly.
mkdir foldername
creates a new sub-directory.cp file1 dir/file1
copiesfile1
to the second path/name specified. This also allows us to create a copy with a different name of the folder.rm
deletes a file.-d
for removing empty directories.-r
for removing non-empty directories.
man
gives us the manual page for a given command../programname
will run a given program../programname < input.txt
will run the program withstdin
closed, and this file as the default file descriptor. In other words, it runs against the inputs in a txt file — which is super convenient for debugging.
- The vertical pipe
|
allows us to chain commands, where the output of the left command is set as the input of the right command. chmod
changes user permissions.