Additional Topics#
In this section, we will briefly touch on ten important topics in Unix/Bash that were not covered in this course. Each topic includes a brief description and links for further reading.
Path:
~/bin/The
~/bin/directory is a common location to place your own executable scripts or programs. Adding this directory to yourPATHallows you to run your scripts from anywhere.
Hidden Files:
.bashrc,.bash_profileHidden files in Unix start with a dot (
.). Important hidden files include.bashrcand.bash_profilewhich are used for configuring the shell environment.
Wildcard
{}:touch file-{001..100}The
{}wildcard is used for brace expansion, creating multiple files or directories with patterns.Example:
touch file-{001..100}creates filesfile-001tofile-100.
Return Codes:
ks && echo "done?"Commands return codes to indicate success or failure.
0usually means success, and any other value indicates an error.Example:
ks && echo "done?"will echo “done?” ifksis successful.
Standard Input/Output and Redirection:
ks 2>&1 | catInput and output redirection allow you to control where the output of a command goes and where the input comes from.
Example:
ks 2>&1 | catredirects both standard output and standard error ofkstocat.
Job Control:
&, ps, fg, bg, killJob control allows you to manage multiple processes. You can start jobs in the background, bring them to the foreground, and kill them if necessary.
Commands:
&(run in background),ps(list processes),fg(foreground),bg(background),kill(terminate process).
Environment Variables:
exportEnvironment variables are used to pass information into processes that are spawned from the shell.
Example:
export VAR=valuesets an environment variable.
Intro to Unix Filesystem
The Unix filesystem is a hierarchical structure where everything is a file. Directories are special types of files.
Editors:
emacsandvim:vimtutoremacsandvimare powerful text editors available in Unix.vimtutoris a great way to learnvim.
“Magic” Variables:
mkdir tmp_dir && cd $_Magic variables like
$_hold the last argument of the previous command.Example:
mkdir tmp_dir && cd $_creates a directory and then changes to it.
Bash Scripting:
if/else, while, caseBash scripting allows for complex automation tasks using control structures like
if/else,while, andcase.
Line Endings and ASCII:
\n\rUnderstanding line endings (
\nfor Unix,\r\nfor Windows) and ASCII is essential for text processing.
Calculations:
echo $((10**2 - 1))Bash can perform arithmetic operations using
$((expression)).Example:
echo $((10**2 - 1))calculates10^2 - 1.
Each of these topics can be explored further to enhance your Unix and Bash skills.