Monday, November 29, 2010

Learning UNIX - I

UNIX commands to Explore
xyx:/>pwd command. Show home directory on screen, PWD means print working directory.
is output for the command when used pwd in /export/home/crk directory.

xyx:/>mkdir command.
xyx:/>mkdir crk will create new directory, i.e. here crk directory is created.

xyx:/>cd command.
cd crk will change directory from current directory to crk directory.

xyx:/>cat command
cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).

xyx:/>head command.
head filename by default will display the first 10 lines of a file. For first 50 lines you can use head -50 filename.
xyz:/> head -50 file1

xyx:/>tail command.
tail filename by default will display the last 10 lines of a file. For last 50 lines then you can use tail -50 filename.

xyx:/>more command. more command will display a page at a time and then wait for input which is spacebar. For example if you have a file which is 500 lines and you want to read it all. So you can use
more filename

xyx:/>wc command
wc command counts the characters, words or lines in a file depending upon the option.
Available Options
wc -l filename will print total number of lines in a file.
wc -w filename will print total number of words in a file.
wc -c filename will print total number of characters in a file.

xyx:/>man command. This is help command for looking any information about that command available,
man cp show cp command details with example and how you can use it.
man -k pattern command gives search for particular pattern with details.

xyx:/>banner command. For printing poster type ascii character, useful for making identifiable logins, any presentable output. Like below

xyx:/> banner crk

#### ##### # #
# # # # # #
# # # ####
# ##### # #
# # # # # #
#### # # # #


xyx:/>cal command. shows the calander on current month by default.
Witout options with cal command , will show current month calander, refer below example for more clarification


November 2010
S M Tu W Th F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

N.B: if want to print calendar of 2nd Month of 2008
xyz> cal 2 2008
February 2008
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29

xyx:/>ls command
ls command is most widely used command and it displays the contents of directory.
ls list all the files in your home directory.
ls -l list all the file names, permissions, group, in long format.
ls -a list all the files including hidden files that start with .
ls -lt list all files names based on the time of creation, newer first.
ls –Fx list files and directory names will be followed by slash.
ls -R lists all the files and files in the all the directories, recursively.
ls -R | more will list all the files and files in all the directories, one page at a time.

xyx:/>file Command displays about the contents of a given file, whether it is a text (Ascii) or binary file. To use it type
file filename. For example I have cal.txt which has ascii characters about calander of current month and I have resume1.doc file which is a binary file in MS word. Result would be as

file resume.doc
resume1.doc: data
file cal.txt
cal.txt: ascii text

xyx:/>cp command.
cp command copies a file. If I want to copy a file named oldfile in a current directory to a file named newfile in a current directory.

xyz:/>cp oldfile newfile

To copy oldfile to other directory in /tmp
xyz:/>cp oldfile /tmp/newfile.
Available Options are :
cp are -p and -r . -p options preserves the modification time and permissions,
-r recursively copy a directory and its files, duplicating the tree structure.

xyx:/>rcp command.
rcp command will copy files between two unix systems and works just like cp command (-p and -i options too).
Let us assume a unix system that is called unix1 and want to copy a file which is in current directory to a system that is called unix2 in /usr/om/ directory then you can use rcp command
rcp filename unix2:/usr/om
You will also need permissions between the two machines. For more infor type man rcp at command line.

xyx:/>mv command.
mv command is used to move a file from one directory to another directory or to rename a file.
Some examples:
mv oldfile newfile will rename oldfile to newfile.
mv -i oldfile newfile for confirmation prompt.
mv -f oldfile newfile will force the rename even if target file exists.
mv * /usr/om/ will move all the files in current directory to /usr/om directory.

xyx:/>ln command.
Instead of copying you can also make links to existing files using ln command.
If you want to create a link to a file called myfile in /usr/local/bin directory then you can enter this command.
ln myfile /usr/local/bin/myfile
Some examples:
ln -s fileone filetwo will create a symbolic link and can exist across machines.
ln -n option will not overwrite existing files.
ln -f will force the link to occur.

xyx:/>rm command.
To delete files use rm command.
Available Options:
rm oldfile will delete file named oldfile.
rm -f option will remove write-protected files without prompting.
rm -r option will delete the entire directory as well as all the subdirectories, very dangerous command.

xyx:/>rmdir command. Remove directory or directories if a directory is empty.
• rmdir om --> to remove om directory.
• rmdir -p --> to remove directories and any parent directories that are empty.

No comments:

Post a Comment