Linux Basics

Shell : Wht is it?

Shell is a program that takes commands from the terminal and gives them to the operating system kernel to perform.

A common shell program is bash, ksh, tcsh etc.


Terminal: Wht is it?

Terminal also called terminal emulator, is a program that opens a window that lets us interact with the shell.

Most common terminal emulators are gnome-terminal, konsole, xterm.


Shell Prompt Analysis

zack is the user logged into the shell. The machine name is hercules.
If last character of shell prompt is # is instead of $, it means you are logged in as superuser.


File Naming facts in linux

  1. File names in linux are case sensitive just like unix.
  2. Files do not need to have an extension in linux.
  3. Files that begin with a period (.) are hidden files


Aliases and Shell Functions

They are another way to add new commands. (the words may not be technically correct.)

Syntax alias name=value
eg. alias l=’ls -la’

Shell Functions: Can be used to add more complex commands to shell

today() {
echo -n “Today’s date is: ”
date +”%A, %B %-d, %Y”
src of above command

To add alias and shell functions edit the .bashrc file in home directory and start a new terminal.


Redirection of Standard Input/ Output

There are 3 main redirection symbols >, >>, <

: If file exists it will be overwritten or else new file will be created. eg. ls > abc.txt
>>: If file exists it will be appended with the new results or else new will be created.
eg. ls >> abc.txt
<: To redirect input to a command through a file not through keyboard input.
eg. cat < abc.txt

eg. sort < names > sorted_names.txt
eg. tr [a-z] [A-Z] < names > capital_names.txt


An instance of running command is called process and the number printed by shell is called process-id (PID).

The ampersand (&) at the end of command tells shells to start the process in background.
eg. $ ls / -R | wc -l &

src of the below table

For this purpose Use this Command Examples*
To see currently running process ps $ ps
To stop any process by PID i.e. to kill process kill    {PID} $ kill  1012
To stop processes by name i.e. to kill process killall   {Process-name} $ killall httpd
To get information about all running process ps -ag $ ps -ag
To stop all process except your shell kill 0 $ kill 0
For background processing (With &, use to put particular command and program in background) linux-command  & $ ls / -R | wc -l &
To display the owner of the processes along with the processes   ps aux $ ps aux
To see if a particular process is running or not. For this purpose you have to use ps command in combination with the grep command ps ax | grep  process-U-want-to see


For e.g. you want to see whether Apache web server process is running or not then give command$ ps ax | grep httpd
To see currently running processes and other information like memory and CPU usage with real time updates. top

$ top
Notethat to exit from top command press q.
To display a tree of processes pstree $ pstree


Exit Status of a Linux Command

If return value/ exit status of a command is 0, then command was successful.

If return value/ exit status non zero then command was not successful or some error occured

To check the exit status of a program echo $? .
eg. echo “hello”
echo $?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s