The Command PATH:

Most common commands are located in your shell’s “PATH” meaning that you can just type the name of the program to execute it.

Example:  Typing “ls” will execute the “ ls” command.

Your shell’s “PATH” variable includes the most common program locations, such as /bin, /usr/bin, /usr/X11R6/bin, and others.

To execute commands that are NOT in your current PATH, you have to give the complete location of the command.

Examples:

/home/user/yourprogram

./yourprogram  (This will execute the program in the current directory)

 


Command Syntax:

Commands can be run by themselves or you can pass in additional arguments to make them do different things. Typical command syntax can look something like this:

command [argument] [-argument] [--argument] [file]

Examples:

  • ls –    List files in current directory
  • ls -l   Lists files in “long” format
  • ls -l –color As above, with colorized output
  • cat filename     Show contents of a file
  • cat -n filename Show contents of a file, with line numbers

Beginners – BASH Special Characters

Valic —  November 29, 2012 — 1 Comment

Before we continue to study about UNIX operating system shell commands, it is important to understand that there are several symbols and characters that the shell interprets in special ways called BASH Special Characters. This means that certain typed characters:

  • Cannot be used in certain situations
  • May be used to perform special operations
  • Must be “escaped” if you want to use them in a normal way.
Character Explanation

\

Escape character. If you want to reference a special character, you must “escape” it with a backslash.
Example: touch filename\* – This command will create the file filename*

/

Directory separator. It’s used to separate a string of directory names.
Example: /var/www/htdocs

.

Current directory

..

Parent directory

~

User’s home directory

*

Represents 0 or more characters in a filename or by itself, all files in a directory.
Example: sql*2012 can represent the files sql2012, sql-backup2012, sql29-11-2012 etc.

?

Represents a single character in a filename.
Example: filename?.txt can represent filename1.txt, filenamex.txt.

[]

Can be used to represent a range of values,  [0-9], [A-Z], etc.
Example: filename[0-2].txt represents the names filename0.txt, filename1.txt, and filename2.txt

|

“Pipe” . It’s mostly used to redirect the output of one command into another command.
Example: ls | more

>

Redirects output of a command into a new file. If the file already exists will be over-writed.
Example: ls > listoffiles.txt

>>

Redirects the output of a command onto the end of an existing file. If the file does not exist, will be created.
Example: echo “test ” >> testfile.txt

<

Redirects a file as input to a program.
Example: more < listoffiles.txt

;

Command separator. Allows you to execute multiple commands on a single line.
Example: cd /var/log ; less syslog

&&

Command separator as above, but only runs the second command if the first one finished without errors.
Example: cd /var/logs && less syslog

&

Execute a command in the background, and immediately get your shell back.
Example: find / -name log > logfiles.txt &

What is a command shell:

Command shell is a program that interprets commands,
Allows a user to execute commands by typing them manually at a terminal or automatically in programs called shell scripts.
A shell is NOT an operating system.
It is a way to interface with the operating system and run commands.

What is BASH:

The name itself is an acronym, BASH = Bourne Again SHell
Bash is a shell written as a free replacement to the standard Bourne Shell /bin/sh originally written by Steve Bourne for UNIX systems.
BASH has all of the features of the original Bourne Shell plus additions that make it easier to program.
BASH is Free Software and was adopted as the default shell on most Linux distributions.

The purpose of this new category is to introduce the Linux user  into Linux command shell and a few of its basic utilities.
It is created for the users with zero or limited exposure to the Linux command prompt.

This category is designed to accompany an instructor-led tutorial on this subject, and therefore some details have been left out.

Page 4 of 41234