UNIX - Basic Commands

Basic Directory Commands
 mkdir
 To create a new directory by an user in Unix  
 $mkdir dir_abc

rmdir 
To remove a directory from the file system 
$rmdir dir_abc

pwd 
To get the present working directory 
pwd  is used to identify the present directory in which the user is working. 
$ pwd <enter> 

cd 
To change from the present working directory 
Changing from one directory to the other is done by the command cd
 $cd /usr/dir_abc/AP 

mv 
To rename the files 
mv  is used to change the name of files and directories 
$mv fileabc filexyz

ls 
The command ls  is used to list the files and directories which are available in that current working directory 
$ls <enter>

cp
To copy the contents of one file into another file 
$ cp file1 file2
Copies file1 to file2 

rm 
To delete a file 
rm command is used for deleting unwanted files/directories 
$ rm  file 

sort 
$ sort File.txt
To sort a list

Cat  
$ cat > file
It creates a new file by accepting text from the standard input 
More
To display the contents of a file page by page 

sudo su - appNameID

tail command for real time log checking:
cd /app/logs
tail -500f myLogOut.log
view growing log file in real time with last 100 lines using tail command

tail -f myLogOut.log
view growing log file in real time using tail command

find command -> in below command to find out poi.jar in specific directory
find . -type f -name 'poi*.jar'


Pipes  
It is a feature by which filters & other commands can be combined in such a way that the standard output of one filter or command can be sent as standard input to another filter
e.g. $ ls >temp
         $ more temp 


ls | wc –l
ls lists each object, one per line, and this list is then piped to wc, which, when used with its -l option, counts the number of lines and writes the result to standard output

echo -e "orange \npeach \ncherry" | sort > fruit
The echo command tells the computer to send the text that follows it to standard output, and its -e option tells the computer to interpret each \nas the newline symbol (which is used to start a new line in the output). The pipe redirects the output from echo -e to the sort command, which arranges it alphabetically, after which it is redirected by the output redirection operator to the file fruit.

A filter is a shell command which takes input from the standard input, processes it, and sends its output to the standard output (unless we redirect the input and output) 
 
•     At run time, the system supplies data to the filter as standard input. This standard input file can not be altered by the program. 


wc: 
-  counts lines, words and characters 
-  $ wc -[wlc] [filename] 
 
• head: 
- displays first ‘n’ lines, horizontal slicing  
- $ head -[n] [filename] 
 
• tail: 
- displays last ‘n’ lines, horizontal slicing 
- $ tail -[n] [filename] 


cut:
- cuts file vertically either column wise/field wise 
 
• $ cut -[cfd] [filename] 
– -c  columns/characters
– -f  field number 
– -d  field delimiter/separator 
 
 $ cut -c2-5 sample
 – cuts columns 2 to 5 from the file sample 
 
 
 paste:
- merges lines of specified files and display onto standard output
- $ paste -d[field separator] [list of files]  
 
• sort: ordering text files 
 - $ sort filename   
- e.g. $ sort +3 -4 emp           
- Sorts emp file as per 4th column


uniq:
 removes duplicate lines from a sorted file 
– $ uniq –[dcf] [file] 
-d    only print duplicate lines
-c    prefix lines with number of occurences
-f2     avoid comparing first two fields 
 
 • nl: number lines of files 
– $ nl –[options] [files] 


tr:translating Characters   
$ tr  [options] < [file]   
-d: deletes specified characters   
-cd: do not delete specified characters   
-s: substitute multiple occurrences of a character by single occurrence. 
 
• $ tr “abc” “ABC” < samp: replaces all occurrences of a with A, b with B, c with C 



history command:
The history command can be used to list Bash's log of the commands typed
This log is called the “history”
$ history n
This will only list the last n commands. Type “history” (without options) to see the the entire history list.

fc command:
fc is used to list or edit and re-execute commands from the history list.
fc -l 701 702
To list a specific range of commands the first and last numbers may also be passed.


Command Function
cut A given number of columns will be shown in the standard output 
comm Line by line comparison of two files 
paste Horizontally to combine two files 
diff To get the different between two files 
grep Globally search for the regular expression and print it 
tail To output only required number of lines 
uniq Used to count / eliminate repeated (duplicate) lines in a file which is pre-sorted 
head To show the first few lines of the file 
cmp To compare two files 




Vi Editor

vi session begins by invoking the command “vi” with a filename 

$ vi [filename]  
 
•    vi can be started without a filename, and it can be saved when required.  
 
•   The last line in the screen is reserved for some commands that can be entered    to act on the text. This line is also used by the system to display messages. 
The three different modes of operations are: 
– Command mode: 
This is the default mode where commands are passed to act on the text, using most of the keys of the keyboard   
Switch to this mode using “Esc” key  
 
       – Insert (Input) mode:
 To enter the text, go to input mode
 Press key “i” to enter into insert mode from command mode 
 Switch to command mode by pressing “Esc” key 


ex mode or line mode: 
Save the file or switch to another file or make a global substitution in the file.
Use ex mode, where instruction can be entered in the last line of the screen. 
To enter into this mode, press “Esc”  key followed by  “:” 


inserts text before cursor position
Appends text after cursor position   
inserts text at beginning of line  
Appends text after end of line
opens line below current line to insert text   
opens line above current line to insert text 


left by one character   
right by one character   
k up by one line   
down by one line   
right by one word   
left by one word   
0 or ^  beginning of line   
end of line 


[n]dw  delete n words  
d0  beginning to cursor position  
d$ or D  cursor position to end of line  
[n]dd  n lines from current line  [n]dd    
pp will paste deleted lines to current cursor  position 


y    character     
y0  beginning to cursor position     
y$  cursor position to end of line    
[n]yw  copy n words    
[n]yy  n  lines from current line in to the buffer     
[n]yy p  p will paste copied lines

ZZ  or :wq    save and exit 
:w    save & continue editing 
:q!    quit without saving

“a4yy      copy 4 lines into buffer  
“ap      paste contents of buffer a to current  cursor  position. Maximum 26 buffers  are available buffer having names “a” to  “z” 
ctrl-v        select particular columns  
“byy        copy selected into buffer b  
“bp      paste contents of buffer b to current cursor position 




File Permission

Code Meaning
a All
u User
g Group
o Other
+ Add
- Remove
= assign

Type of users: 
 
– File owner ( the one who creates the file)
– Group owner  
– Others 
 
• Symbols used to identify the users: 

-u – represents the owner / creator of the file 
-g – represents the user who belong to the group of the owner of the file
-o – represents any other user not belonging to the group to which the owner belongs to.

chmod

There are 3 types of permissions on a file/directory: 
-read (R)
-write (w) 
-execute (x) 
 
• chmod command is used to change the permissions on a file for owner, group and others 
chmod <permission><filename> 
 
 
 $chmod u+x fileabc – to provide execute permission to the user 
 
$chmod u-x fileabc – to remove the execute permission from the user for the file   fileabc 
 
$chmod ugo +x fileabc – to provide execute file permission to all the three groups of users for the file named fileabc. 






Information retrieval command:
who         To get the names of all the users who have logged in at that point of time 
who am I To get the user id of the user who has logged in the same terminal 
tty                 Represents the Terminal type 
date         To get the date, month, time and year in the system 
Man         Provides the manual pages of all commands on Unix 


Date command
Example: $ date “+Today is %a %m %Y” 


Sequence Interpretation
 %a abbreviated weekday name (Mon .. Sun) 
%b or %h abbreviated month name (Jan .. Dec) 
 %d day of month (01 .. 31) 
 %r time (12- hour) 
 %T time (24- hour) 
 %y last two digits of year (00 .. 99) 
 %D date (mm/dd/yy)

Comments

Popular posts from this blog

PUTTY - The server's host key is not cached in the registry cache

OIM-12c Installation - FMW - SOA - IDM

SAML & OAuth 2.0