"Karmanyevadhikaraste ma phaleshu kadachana, Ma karma phala hetur bhurmatey sangostva akarmani."

Unix

The ls command ( lowercase L and lowercase S ) lists the contents of your current working directory
To list all files in your home directory including those whose names begin with a dot, type
% ls –a   As you can see, ls -a lists files that are normally hidden.
% mkdir unixstuff  make a subdirectory in your home directory to hold the files you will be creating
% cd unixstuff  The command cd directory means change the current working directory to 'directory'. 
The current directory (.)
In UNIX, (.) means the current directory, so typing % cd .

The parent directory (..)

(..) means the parent of the current directory, so typing % cd ..

pwd (print working directory)

Pathnames enable you to work out where you are in relation to the whole file-system. For example, to find out the absolute pathname of your home-directory, type cd to get back to your home-directory and then type
% pwd

~ (your home directory)

Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing % ls ~/unixstuff

cp (copy)

cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls itfile2

mv (move)

mv file1 file2 moves (or renames) file1 to file2
To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two.

rm (remove), rmdir (remove directory)

% cp science.txt tempfile.txt
% ls
% rm tempfile.txt 
% ls
% clear
This will clear all text and leave you with the % prompt at the top of the window.

cat (concatenate)

The command cat can be used to display the contents of a file on the screen. Type:
% cat science.txt

less

The command less writes the contents of a file onto the screen a page at a time. Type
% less science.txt

head

The head command writes the first ten lines of a file to the screen.
First clear the screen then type
% head science.txt
% head -5 science.txt

head -n 15 /var/log/maillog

tail

The tail command writes the last ten lines of a file to the screen.
Clear the screen and type % tail science.txt
To see growing log file in real time:
$ tail -f /var/log/syslog
find: to search for a file..

grep:  searches files for specified words or patterns. First clear the screen, then type

% grep science science.txt
To ignore upper/lower case distinctions, use the -i option, i.e. type
% grep -i science science.txt
% grep -i 'spinning top' science.txt
-c print only the total count of matched lines 
\-v display those lines that do NOT match 
the number of lines without the words science or Science is
% grep -ivc science science.txt

wc (word count)

% wc -w science.txt

CAT

cat command to write the contents of a file to the screen. % cat

Redirecting the Output 

to create a file called list1 containing a list of fruit, type  
% cat > list1

3.2.1 Appending to a file

The form >> appends standard output to a file. So to add more items to the file list1, type
% cat >> list1
to join (concatenate) list1 and list2 into a new file called biglist. Type
% cat list1 list2 > biglist
We use the < symbol to redirect the input of a command.
 redirect the input to come from a file rather than the keyboard. For example, to sort the list of fruit, type
% sort < biglist
To output the sorted list to a file, type, % sort < biglist > slist
To see who is on the system with you, type % who
One method to get a sorted list of names is to type,
% who > names.txt
% sort < names.txt
Or simply % who | sort

The * wildcard

This will list all files in the current directory starting with list.... % ls *list

The ? wildcard

The character ? will match exactly one character.
On-line Manuals
% man wc   or  
% whatis wc
Permisions rwx  owner, user, all
% chmod go-rwx biglist
This will leave the other permissions unaffected.
To give read and write permissions on the file biglist to all,
% chmod a+rw biglist
% sleep 10
This will wait 10 seconds before returning the command prompt %
To kill a suspended or background process, type
% kill %jobnumber
To report on all files in your home directory, type
% file *
To search for all fies with the extention .txt, starting at the current directory (.) and working through all sub-directories, then printing the name of the file to the screen, type
% find . -name "*.txt" -print
To see the differences type % diff file1 file2

Environment Variables

The value of this is the current operating system you are using. Type % echo $OSTYPE

  • USER (your login name)
  • HOME (the path name of your home directory)
*******************************************************************

About tee

Reads from standard input, and writes to standard output and to files.

Syntax

tee [OPTION]... [FILE]...

Description

The tee command is named after the T-splitter in plumbing, which splits water into two directions and is shaped like an uppercase T.

tee copies data from standard input to each FILE, and also to standard output. In effect,tee duplicates its input, routing it to multiple outputs at once.

Options

-a--appendAppend to the given FILEs. Do not overwrite.
-i--ignore-interruptsIgnore interrupt signals.
--helpDisplay a help message, and exit.
--versionDisplay version information, and exit.
If a FILE is specified as a dash ("-"), tee writes again to standard output.

Examples

ls -1 *.txt | wc -l | tee count.txt
In the above example, the ls command lists all files in the current directory that have the filename extension .txt, one file per line; this output is piped to wc, which counts the lines and outputs the number; this output is piped to tee, which writes the output to the terminal, and writes the same information to the file count.txt. If count.txt already exists, it is overwritten.