Thursday

Basic Commands Part2

Command Options Description
25.Head
 
head newfile
head -5 newfile
head -1 newfile | wc -c
vi 'ls -t | head -1'
head -c 512 newfile
head -c 1b newfile
head -c 2m newfile
Display top content of file
Display top 10 lines of file when used without argument
Display top 5 lines of file<newfile> when used without argument
To count the number of character present in first line.
To open the last modified file for editing.
To pick special no of character from file.
Print first 512 byte character
Print first 2 blocks (1 MB each)
26.Tail
 
tail -5
tail +10
tail -f 6_load.log
Display end of file
Display last 5 lines of file.
start dispplaying 10 line onward till the end.
Print the gworth of file
27.$$
Prints the Process id of current shell
28.ps
 
ps -f
ps -f -u a_cmdb
ps -a
ps -e
 
Prints the Processes associated with current user.
Prints the Processes associated with current user with their hierarchy.f stands for full.
Prints all the processes associated with a_cmdb user.
Prints all the users processes.
Prints system process.
prints all the ksh process running in the system by first searching for all the process.
29.Background job
 
ps -f
ps -f -u a_cmdb
ps -a
ps -e
 
Running job in background
Run the search job in background by printing its process id.Shell become the parent of all background process.
This command print all the jobs runnung in background with their sequence no of exceution.
Running fg will bring most recently started background process <LAST IN FIRST OUT>
First job will come into foreground.
30.nohup
 
nohup ps -eaf | grep 'ksh' &
Shell is parent of all background jobs and it dies when user logs out and ultimately all the child process also dies.To avoid dying of shell even when the user logs out run the background process using nohup command.
System process init having PID as 1 is parent of all SHELL processes and when the user login this PID become the PPID of SHELL prrocess. Now after running the process in nohup mode kernel has reassigned the PPID of ps process with PID of system process which will not die even after SHELL dies through logging out.
31.Kill
 
kill 520
kill 640
kill 1
kill $!
kill 0
 
To kill the command.
Kill the process with 520 process id.
Kill the parent process id which inturn kill all the child process.
Killing system process init is not possible. A Process having process id as 1 is parent of all SHELL processes.
No need to remember Process id of last background procees its in $!
Kill all process in the system except login shell process.
$$ stores the PID of current login shell
32.Nice
 
nice who | wc - l &
nice -n 10 who | wc -l &
Running the command with low priority
Nice value range from 1 to 39, higher the nice value lower the priority.default nice value is 20.
nice value becomes 30.
33.At
 
at 2:10 load.ksh
To Run the job at specied time of the day.
Indicate the load.ksh will execute today by 2:10
34.Batch
batch load.ksh
batch command executes the process whenever the CPU is free.
35.Cron
cron executes process at regular intervals it keeps checking the control file at /user/spool/cron/crontabs for jobs.
36.Finger
finger
finger a_cmdb
Produces list of all logged users when run without any argument. The 2nd and last field of output is taken fron passwd file from /etc directory.
Prints details about a_cmdb user.
37.Set
 
set 10 20 30
-x
set the posional parameter.
This will set $1, $2, $3 , $* and $# posional parameter
When this statement is used at start of ksh script it echoes each statement at the terminal
38.Shift
 
shift
shift 2
shift command transfer the contents of positional parameter to next lower number.
shift one position.
shift 2 places
39.Chown
 
chown jaspreet testfile
chown -R jaspreet testfile
To change the owner of file can only be done by owner or sys admin.
change the owner from gagan to jaspreet for testfile. Now gagan cannot change the ownership of test file what he can do is just create the similar copy of file and then he can become the owner of file.
Recursively changes the owner all files under current directory.
40.Chgrp
 
chgrp GTI test file
chgrp -R GTI test file
To change the group of file can only be done by owner or sys admin.
group changed to GTI from IB as user is still the same and he can again change the group of file to IB.
Recursively changes group all files under current directory.
41.Touch
 
touch 03161430 test file
touch -m 04161430 test file
touch -a 05161430 test file
Changing the time stamps of file
touch without any argument will change both modified time and access time.
Changes only modification time.
Changes only access time.
42.Linking in
 
ln 6_load.ksh 7_load.ksh
rm 6_load.ksh
Linking two file, doing this both the file will have same inode number and changes in one will reflect in another also.
ls -li 6_load.ksh 7_load.ksh will give us same inode number.
Drop the link between two files.
43.df
 
df -t /home/oracle
Prints the amount of free space available on the disc.
Prints the free and total space under oracle file system.
44.du
 
 
du -s
du -s /home/*
Prints the disk usage of specific directory tree.
By default du prints disk usage for each sub directory.
Prints summary of whole directory tree.
Prints disk usage for every user

No comments :

Post a Comment

Recent Comments