Skip to content

Unix Shell and Unix Filesystem

Unix and Unix-like operating systems

For clarity, Unix is a family of multitasking, multi-user computer operating system. There is a large family of Unix-like operating systems.

Some well-known cases of Unix-like operating systems are Linux and BSD.

Sessions in UNIX/Linux

To work in a terminal, we need to have a valid username, in order to begin a session via the login command.

If using VSCode we can launch a new terminal from the "Hamburguer Menu" as shown in the next figure

New Terminal

The new terminal will open in the lower right part of the VSCode interface.

Terminal

The terminal is ready for user input.

:memo: To end the session enter the exit command. It will finish the session and close the terminal.

The Command Shell or Command Line Interpreter

In the background a Command shell is running. To find out which shell is active we can type the following command after the system prompt $.

echo $SHELL

which will return the command shell program, /bin/bash, in the Codespaces terminal. This is Bash (Bourne Again Shell), which is derived from the original shell /bin/sh. In other system environments, maybe you will encounter other similar shells (/bin/csh, /bin/tcsh, /bin/ksh, /bin/zsh, and others).

The command shell serves as an intermediary between the user and the Operating System Kernel, which controls all the available computer resources.

Kernel Layout

Read more on the Unix Shell

Files and Directories

The Unix filesystem is considered as the central component of the operating system. The filesystem provides storage and retrieval for other programs to read them. The filesystem also provides access to other resources, for example the device files, terminals, printers, computer mice, and many other.

Directory or file Description
/ The root directory is the top-level directory in the Unix file system.
/bin The bin directory contains executable programs.
/dev The dev directory contains device files.
/lib The lib directory contains libraries.
man The man directory contains manual pages.
/etc The etc directory contains configuration files.
/home The home directory is the default directory for each user.
/tmp The tmp directory is a temporary directory where files can be created and deleted without affecting the rest of the file system.
/usr The usr directory contains system files that are shared by all users.
/var The var directory contains files that can vary in size, such as log files and mail files.

The Unix file system is a hierarchical structure, with each directory containing a set of files and subdirectories. The root directory is the top-level directory, and all other directories are below it.

Unix Filesystem Hierarchy

(See a larger image)

First steps: Manual pages and getting help

In general, almost all Unix systems include their manual pages of system commands.

Commands Description
man command Online manual pages
apropos keyword Searches keyword in manual pages
command --help Show how to use command
more filename Show contents of a text file
less filename Show content of a text file

The more and less commands show the contents of a file. The following commands control the flow of information.

Command Action in less / more
d or Space bar page down
u page up (less)
p beginning of file
G End of file
q Quit and exit

ls: Listing files in directories

The ls command, lists all the contents of a directory.

For example ls -al will list all files in a directory in long format, including hidden files (those files whose name starts with a dot .)

Try ls --help to show you all the available options of the command.

The command ls -al */* shows all the contents of a directory and subdirectories next level down.

pwd: Prints present/working directory

The pwd command, will show the current position in the directory structure.

cd: Change the working directory

The cd command, will help you navigate in the directory structure.

Common commands

Command Action
cd A blank option takes you to your HOME directory
cd ~ Same as above, takes you to your HOME directory (where ~ is aka tilde)
cd .. Moves you up, to the parent directory
cd ../.. Moves you up two levels
cd - Moves you to the previous working directory

See more Unix Shell Commands here

References


Created: 05/13/2023: Updated: 05/15/2023

Carlos Lizárraga