Introduction to Bash Shell Scripting: Linux Commands - Part 1

UNIX/Linux

Linux is an operating system, like windows, which is currently being used by 65% of all web servers, and 85% of the top 100 supercomputers.

Operating System Layers

UNIX / Linux has a layered operating system that is comprised of three main parts:

Utilities: Commands available for a user, for example, to copy a file.

Shell: A program that reads and executes a set of our commands. UNIX contains several shells including: Korn Shell (ksh), Bourne Shell (sh), Bourne Again Shell (bash) and C Shell (csh).

Kernel: The heart of the operating system which manages memory, maintains a file system, controls access to hardware, allocated CPU's resources, and more.

We communicate with the OS's kernel through a shell. During this set of tutorials we will be using the Bourne Again Shell, or Bash.

For this entire group of tutorials we will be working in Terminal (may have a different name depending on which version of Linux you are running. Ubuntu is the most common distribution of Linux and it can be found here. If you are a Mac you can use the 'Terminal' application which comes standard on every Mac, since the OS is based on UNIX.

UNIX Commands

Below is a list of some basic UNIX commands we will be using:

ls - lists contents of current directory (like dir in Win)

cd - changes current directory (like cd in Win)

pwd (print working directory) - shows you what directory you are in

cat - displays contents of file(s) with no paging

tac - cat lines in reverse order (last line to first line)

more - like cat but paginated (spacebar acts as page down, enter gets next line, q quits)

cp - copies one file (or directory) to another 

rm - deletes a file(s)

mkdir - creates a new directory

rmdir - erases a directory (it must be empty)

mv - renames a file (or directory) "moves" it in filesystem

wc - gives size (lines, chars) of files

A standard command, when typed in Terminal, will have the following format:

command_name -<option> argument(s)

To look up documentation on how to use any command, you can use the man command in Terminal.

man command_name

In the second part we will look at the UNIX file system, file permissions, and more!

More tutorials coming soon! Let me know how you like the tutorials by commenting below and if there is any specific topics or languages you would like covered.

Programming in C: User Input

Programming in C: Modifiers