1  UNIX Shell Basics

1.1 Introduction

The UNIX shell is a command-line interface that provides a way to interact with the operating system, allowing users to execute commands, manage files, and perform various system operations (Bollinger 1999). The shell is a powerful tool for users and administrators alike, offering a wide range of commands and utilities to navigate the filesystem, manage processes, and automate tasks.

This guide serves as a primer on essential UNIX shell commands and concepts, aimed at equipping beginners with the knowledge to start navigating and manipulating the filesystem, understanding the directory structure, and utilizing basic commands for file and directory operations.



1.2 Linux Directory Structure

  • /bin: Essential user command binaries (programs).
  • /dev: Device files (e.g., USB drives).
  • /etc: System configuration files.
  • /home: Home directories for users.
  • /lib: Essential shared libraries and kernel modules.
  • /media: Mount points for removable media (USB, CDs).
  • /mnt: Temporary mount points for filesystems.
  • /opt: Optional/additional software applications.
  • /proc: Virtual filesystem providing system information.
  • /root: Home directory for the root user.
  • /sbin: Essential system binaries.
  • /tmp: Temporary files, cleared at reboot.
  • /usr: Secondary hierarchy for user data; contains most user programs.
  • /var: Variable data files (logs, databases).

1.3 Accessing the Shell

  • Mac: Applications > Utilities > Terminal.
  • Windows: Use WSL or Git-bash or PuTTY, a terminal emulator.

1.4 Basic Shell Commands

1.4.2 Viewing and Examining Files

  • Display file content: cat myfile.txt.
  • Paginated viewing: less myfile.txt.
  • Show the beginning of a file: head myfile.txt.
  • Show the end of a file: tail myfile.txt.
Note

When using the less command, the following keys can be used for navigation:

  • Space: Advances to the next page.
  • Enter: Scrolls down by N lines (default is 1).
  • b: Moves back to the previous page.
  • y: Scrolls up by N lines (default is 1).
  • q: Exits the view mode.

1.4.3 Manipulating Files and Directories

  • Copy files: cp source.txt destination.txt.
  • Move/rename files: mv oldname.txt newname.txt.
  • Create directories: mkdir newdir.
  • Remove files: rm myfile.txt, directories: rm -r mydir.
  • Create empty files or update timestamps: touch newfile.txt.

1.4.5 File and Directory Sizes

  • Disk usage of files/directories: du -sh target.
  • Disk space usage: df -h.

1.4.6 Viewing Manual Pages

  • Access command documentation: man command.

1.4.7 Shell Shortcuts and Wildcards

  • Home directory shortcut: ~.
  • Current directory: ., parent directory: ...
  • Wildcard for matching filenames: * (e.g., *.txt for all text files).

Embarking on the journey of UNIX shell mastery begins with these foundational concepts and commands, paving the way for more advanced system interaction and management tasks.