Unix Fundamental Commands
Unix Fundamental Commands
Unix Fundamental Commands
TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 1
TechZone UNIX commands
$mkdir dir1
find:The "find" command can be used to find the location of specific files.
$ find / -name dbmspool.sql
$ find / -print |grep –I dbmspool.sql
$ find . –name file_name -> TO find file location from current Dir.
The "/" flag represents the staring directory for the search. Wildcards such as "dbms*" can be
used for the filename.
which: The "which" command can be used to find the location of an executable you are using.
$which sqlplus
The "which" command searches your PATH setting for occurences of the specified executable.
umask: The "umask" command can be used to read or set default file permissions for the
current user.
#umask 002
The umask value is subtracted from the default permissions (666) to give the final permission.
666 : Default permission
022 : - umask value
644 : final permission
chmod: The "chmod" command is used to alter file permissions after the file has been created.
# chmod 777 *.log -- Character equivalents can be used in the chmod
command
# chmod o+rwx *.log
# chmod g+r *.log
chown: The "chown" command is used to reset the ownership of files after creation.
# chmod -R oinstall.dba *
The "-R" flag causes the command ro recurse through any subdirectories.
group add: The “group add” command is used to create new group
# groupadd –g oinstall
chgrp: used to chage the group of the user.
# chgrp newgroup filename
useradd: The "useradd" command is used to add OS users.
# useradd –G oinstall –g dba –d /u01/home –m –s /bin/sh oracle
-- The "-G" flag specifies the primary group.
-- The "-g" flag specifies the secondary group.
-- The "-d" flag specifies the default directory.
-- The "-m" flag creates the default directory.
-- The "-s" flag specifies the default shell
Passwd: The "passwd" command is used to set, or reset, the users login password.
#passwd oracle
usermod: The "usermod" command is used to modify the user settings after a user has been
created.
#usermod –s /bin/ksh oracle
userdel: The "userdel" command is used to delete existing users.
# userdel –r oracle -- The "-r" flag removes the default directory.
The "who" command can be used to list all users who have OS connections.
# who
# who | head -5
# who | tail -5
# who | grep -i ora
# who | wc –l
-- The "head -5" command restricts the output to the first 5 lines of the who command.
TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 2
TechZone UNIX commands
-- The "tail -5" command restricts the output to the last 5 lines of the who command.
-- The "grep -i ora" command restricts the output to lines containing "ora".
-- The "wc -l" command returns the number of lines from "who", and hence the number of
connected users.
wc: To see the number of lines in a text file (can be used to find the number of records while
loading data from text file).
wc -l filename
Sort : The command “sort” used to sort the contents of a file.
$ sort <option> filename
$sort –r file1 → sort and display contents of file1 in reverse order
Wall: broadcasting the message on the network.
$ wall <message>
Write: Its one way communication, message can be sent to particular user.
$ write <username>
Mail: send the message when the user is offline
$ mail <username>
grep: global regular expression print to search for an expression in a file or group of files. grep
has two flavours egrep (extented - expands wild card characters in the expression) and frep
(fixed-string - does not expand wild card characters). This is a very useful command, especially
to use in scripts.
$ grep oracle /etc/passwd → to display the lines containing "oracle" from /etc/passwd file.
$ grep -i -l EMP_TAB *.sql → to display only the file names (-l option) which contains
the string EMP_TAB, ignore case for the string (-i option), in all files with sql extention.
$ grep -v '^#' /etc/oratab → display only the lines in /etc/oratab where the lines do not
(-v option; negation) start with # character (^ is a special character indicating beginning of line,
similarly $ is end of line).
$ find /usr/oracle -mtime +7 –print → list all files under /usr/oracle which are older
than a week.
$ find /usr/oracle -mtime -7 –print → list all files under /usr/oracle which are
modified within a week.
ps: The "ps" command lists current process information.
$ ps
$ ps –ef | grep –i ora
-- The –f does full listing
-- The –e selects all process
TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 3
TechZone UNIX commands
compress Files: In order to save space on the filesystem you may wish to compress files such
as archived redo logs. This can be using either the gzip or the compress commands.
gzip: The gzip command results in a compressed copy of the original file with a ".gz" extension.
The gunzip command reverses this process.
# gzip myfile
# gunzip myfile.gz
compress: The compress command results in a compressed copy of the original file with a ".Z"
extension. The uncompress command reverses this process.
# compress myfile
# uncompress myfile.z
vmstat: Reports virtual memory statistics.
# vmstat 5 3
sar: Collect, report, or save system activity information.
# sar –u 10 8
mpstat: Reports processor related statistics.
# mpstat 10 2
Top: Displays top tasks.
# top
df: df [options] [moutpoint] Freespace available on the system (Disk Free); without arguments
will list all the mount points.
# df -k /u01 Freespace available on /u01 in Kilobytes.
du: du [-s] [directoryname] Disk used; gives operating system blocks used by each
subdirectory. To convert to KB, for 512K OS blocks, divide the number by 2.
# du -s gives the summary, no listing for subdirectories
Here are some files that may be of use.
/etc/group → group settings
/etc/hosts → hostname information
/etc/exports → It states how partitions are mounted and shared with other Linux/UNIX systems.
/etc/fstab → this file automatically mounts filesystems that are spread across multiple drives.
/etc/inittab → describes which processes are started at bootup or at different runlevels.
/etc/passwd → contains user information.
/etc/shells → contains the names of all the shells installed on the system
/etc/ftpusers → contains the login names of users who are not allowed to log in by way of FTP.
/etc/shawdow → it contains encrypted passwords are stored in /etc/shadow.
/etc/profile → This file contains settings and global startup information for the bash shell.
/etc/crontab →Lists commands and times to run them for the cron deamon .
/var/log/messages→ The main system message log file.
/var/spool/mail→Where mailboxes are usually stored
/etc/resolv.conf → Configures the name resolver, specifying the address of your name server
and your domain name .
/etc/sysconfig/network→Defines a network interface.
/proc/version→The kernel version.
/etc/redhat-release → Includes one line stating the Red Hat release number and name
TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 4
TechZone UNIX commands
Vi EDITOR:
Vi editor is used to make new text files, scripting files or modifying contents of existing files.
Modes of vi editor:
➔ Command mode:
i → to start insertion from current cursor position
I → to start editing from beginning of line
a → to append contents to right side of your current cursor position
A → to append contents to the end of the current cursor line
r → to replace a char from current cursor position
R→ to replace a whole word from current cursor position
x →to remove the char from current cursor position
dd → to remove / to delete a line
2dd → to remove 2 lines from current cursor position
yy → to copy the line of current cursor position
2yy → to copy 2 lines from current cursor position
p → to paste the copied content to after cursor position
P → to paste the content above the cursor line
u → to undo previous operations
dgg → to remove / delete above lines including current cursor line till beginning of file
dG → to remove / delete below lines including current cursor line till end of file
l → to move cursor to character by character at a time
h → to move cursor back char by char
k → to move cursor to above line
j → to go to next line
H → to go to end of the file.
G →to go to beginning of file
➔ Execution mode:
esc → to go to execution mode
:w → to save changes in the file
:q → to quit from the file
:wq → to save and quit
:x → to save and quit
:wq! → Forcibly save changes in the file and quit.
:s%/oldtext/newtext/g → to replace all oldtext with newtext in the file
:se no → to display line number
:no se → to hide line number
TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 5
TechZone UNIX commands
TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 6