Additional Topics

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.

  1. Path: ~/bin/

    • The ~/bin/ directory is a common location to place your own executable scripts or programs. Adding this directory to your PATH allows you to run your scripts from anywhere.

  2. 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.

  3. 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 files file-001 to file-100.

  4. 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?” if ks is successful.

  5. 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 of ks to cat.

  6. 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).

  7. 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.

  8. Intro to Unix Filesystem

    • The Unix filesystem is a hierarchical structure where everything is a file. Directories are special types of files.

  9. Editors: emacs and vim: vimtutor

    • emacs and vim are powerful text editors available in Unix. vimtutor is a great way to learn vim.

  10. “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.

  11. Bash Scripting: if/else, while, case

    • Bash scripting allows for complex automation tasks using control structures like if/else, while, and case.

  12. Line Endings and ASCII: \n\r

    • Understanding line endings (\n for Unix, \r\n for Windows) and ASCII is essential for text processing.

  13. Calculations: echo $((10**2 - 1))

    • Bash can perform arithmetic operations using $((expression)).

    • Example: echo $((10**2 - 1)) calculates 10^2 - 1.

Each of these topics can be explored further to enhance your Unix and Bash skills.