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 yourPATH
allows you to run your scripts from anywhere.
Hidden Files:
.bashrc
,.bash_profile
Hidden files in Unix start with a dot (
.
). Important hidden files include.bashrc
and.bash_profile
which 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-001
tofile-100
.
Return Codes:
ks && echo "done?"
Commands return codes to indicate success or failure.
0
usually means success, and any other value indicates an error.Example:
ks && echo "done?"
will echo “done?” ifks
is successful.
Standard Input/Output and Redirection:
ks 2>&1 | cat
Input and output redirection allow you to control where the output of a command goes and where the input comes from.
Example:
ks 2>&1 | cat
redirects both standard output and standard error ofks
tocat
.
Job Control:
&, ps, fg, bg, kill
Job 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:
export
Environment variables are used to pass information into processes that are spawned from the shell.
Example:
export VAR=value
sets 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:
emacs
andvim
:vimtutor
emacs
andvim
are powerful text editors available in Unix.vimtutor
is 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, case
Bash scripting allows for complex automation tasks using control structures like
if/else
,while
, andcase
.
Line Endings and ASCII:
\n\r
Understanding line endings (
\n
for Unix,\r\n
for 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.