Sunteți pe pagina 1din 4

1

NSR Technologies
UNIX Commands
PWD : This command will print your home directory on screen, PWD means Present Working Directory EX: /u0/nas/basha LS: This command is most widely used command it displays the contents of directory. Options:

Ls : Will list all the files in your current directory. This command has many options. Ls l : Will list all the file names, permissions, group, file size, etc., in long format. Ls lrt : Will list all files names based on the time of creation, new files bring first. Mkdir: This command will create new directory Ex: Mkdir Basha (Here Basha directory is created). Cd : cd command will change directory from current directory to next directory Syntax: cd basha Will change from current directory to basha directory. CAT : cat command will display the contents of a file. Syntax: cat <file name> Head: Head command will display the file header lines. By default it will display the first 10 lines of a file. Syntax: Head <filename> If you want to display first 50 lines you can use head -50 <filename> and so Tail : This command will display the last lines of a file. By default it will last 10 lines of a file. Syntax: tail <filename> by default will display the last 10 lines of a file. If you want last 2 lines you can use tail -2 <filename> More: 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 this command. display the

Syntax: more <filename> Wc : Wc command counts the characters, words or lines in a file depending upon option. Options: a) wc l <filename> : Will print total number of lines in a file. b) wc w <filename> : Will print total number of words in file. c) wc c <filename> : Will print total number of characters in a file. Cp : cp command copies a file. In the same directory or different directory Syntax: cp <existing filename> < new filename> If you want to copy a file name abc in a current directory to a file abc_new in a current directory. Ex; cp <abc> <abc_new> If you want copy existing file to other directory for example /temp then cp <existing filename> /temp/newfilename. Mv : mv command is used to move a file from one directory to another directory or to rename a file. Synatax: mv <oldfilename> <new filename> - will rename old file name to new filename. Mv * /user/basha/ will move all the files in current directory to /user/basha directory. Rmdir: This command will remove directory or directories if a directory is Options: empty. the

Rm : Command will use to delete existing files. Syntax: rm <existing filename> will delete the specified file. rm r : This command will delete the entire directory as well as the subdirectories Syntax: rm r <directory_name> will remove directory along with files. Diff: This command will compare the two files and print out the dirrerences between. Syntax: diff <file1> <file2> will give the following output. < this is different as;lkdjf -- Howt to move data from one file to another file: $> cat test.txt> test1.txt This command will write data from one file to another file by sorting Ex: sort ETL.txt > Testing.txt This command will write data from one file to another file by sorting and removed the duplicate records Ex: $>sort ETL.txt|uniq > Testing.txt

How to check all the running (Programmes) process in Unix> $> ps ef How to Unzip a file in Unix? $> unzip j filename.zip How to remove the first line from file? $> sed 1 d filename.txt Grep: grep command is the most useful search command. Syntax: grep <string> <filename> Ex: grep ETL <filename> How to count ETL word in file: Ex: grep c ETL <filename> Write a command that will find all text files in a directory Ex: $> grep *.txt How to display n-th line of a file? Syntax: $> sed n <n> p filename.txt Note: You need to replace <n> with the actual line number. So if you want to print 5 th line, the command will be: $> sed n 5 p test.txt Vi Editor Commands: How to Open exiting file? $> Vi <filename> How to create a new file in Vi editor $> Vi <new filename> Vi Modes: Vi has 2 modes: 1) Command Mode 2) Insert Mode 1) Command Mode: In command mode, the letters of the keyboard perform editing function (like moving the cursor, deleting text, etc., ). To enter into command mod e press <Esc> key in the file.

Insert mode: In order to begin entering text in this empty file, change from command mode to Insert mode. To do this, type i Note: When you type i nothing appers to change, but you are now in insert mode can begin typing text. Moving Cursor: To move the cursor to another position, you must be in command mode. If you are still in insert mode, go back to command mode by pressing <Esc>. The cursor is controlled with four keys (h, j, k ,l)

Key h j k l

Cursor Movement Left one space Down one line Up one line Right one space

Deleting characters in Vi editor: To delete a character from a file, move the cursor on the letter and then type x To delete 4 characters (the one under the cursor and the next 3 characters) 4x How to delete a word from file? To delete a word, move the cursor to the first letter of the word, and type dw Note To delete 3 words type 3dw How to delete whole line in vi editor? Type: 2dd How to Delete from the cursor position to the end of the line? type: D (uppercase) Replace the character: o To replace one character with another. o Move the cursor to the character to be replaced. o Type r o Type the replacement character. Replac one word with another word: o To replace one word with another, move to the start of inccorect word and type cw o Inserting Text: o Position the cursor where the new text should go o Type i (it will go into insert mode) o Enter the new text (The text is inserted Before the cursor. o Press <ESC> to get back to command mode. Joining Lines: How to join two lines together : Put the cursor on the first line to be joined and Type J How To join 3 lines together Put the cursor on the first line to be joined Type 3J

S-ar putea să vă placă și