Unix Fundamental Commands

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

TechZone UNIX commands

UNIX FUNDAMENTAL COMMANDS


pwd: The "pwd" command displays the current directory.
$ pwd
/u01/home/oracle/product/10.1.0.1/db_1/
clear: the “clear” command user to make screen clear.
# clear (ctrl + l also works the same as clear command)
ls: The "ls" command lists all files and directories in the specified directory
$ ls
$ ls $ORACLE_HOME/dbs
$ ls –al -- The "-a" flag lists hidden "." files. The "-
l" flag lists file Permissions.
$ls –s → to see size of files
cd:The "cd" command is used to change directories
$ cd $ORACLE_HOME
touch: The "touch" command is used to create a new empty file with the default permissions.
$ touch f1 f2 f3 f4 → create f1 f2 f3 f4 empty text files
cat: The “cat” commad is used to enter data into a file and display file contents
$ cat > filename → to create new text file and enter data into the
file (press ctrl + d to save&exit)
$cat >> filename → to enter the data to append exiting data in a file
$cat f1 f2 > f3 → copy data of f1 and f2 to f3
cp: The “cp” commad is used to copy files from one loc to other
$cp -rvf oldfileloc newfileloc
-- the “-r” flag indicates recursively
-- the “-v” flag indicates verbose
-- the “-f” flag indicates forcibly
mv: The "mv" command is used to move or rename files and directories.
$mv oldloc newloc
$mv $ORACLE_HOME/dbs/spfileprod.ora /u01/user10/
head: head command used to display top lines of the file.
$ head -10 filename
tail: to see last lines of a file
$tail -20 filename
who: To see the users logged in to the server and their IP address
# who → no of login users.
# whoami → current working username
passwd: →To change passwd of oracle user
# passwd oracle
Cal: The “cal” command is used to display calendar.
# cal
# cal -3 → displays previous, current and next months cal
mkdir: The "mkdir" command is used to create new directories.
$mkdir dir1
rm: The "rm" command is used to delete files and directories.
$ rm dir1
$ rm –r dir1/dir2/ -- The "-r" flag tells the command to recurse
through subdirectories.
cp:The "cp" command is used to copy files and directories.
$cp dir1/file1 dir2/
rmdir:The "rmdir" command is used to delete directories.

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

kill:To kill a process from Unix.


# kill -9 12345 → specific processes can be killed by specifying the process id
uname and hostname: The "uname" and "hostname" commands can be used to get
information about the host.
# uname –a
# uname –a| awk ‘{print $2}’
-- The “-a” flag prints basic information currently available from the system.
-- The “-I” flag prints name of hardware implementation (platform)
-- The “-r” flag displays operating system release level.
error Lines in Files: You can return the error lines in a file using.
# cat alert_prod1.log | grep –i ORA-The "grep -i ORA-" | wc -l
-- command limits the output to lines containing "ORA-". The "-i" flag makes the comparison
case insensitive. A count of the error lines can be returned using the "wc" command. This
normally give a word count, but the "-l" flag alteres it to give a line count.

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

Ipcs: To see the shared memory segment sizes


ipcs –mb

TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 4
TechZone UNIX commands

To see if SQL*Net connection is OK.


tnsping SIDNAME

To see if the server is up.


ping servername
OR
ping IPADDRESS

To see the versions of all Oracle products installed on the server.


$ORACLE_HOME/orainst/inspdver

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

Partitioning with fdisk

# fdisk –l → Use fdisk -l to view all available partitions


# fdisk -l /dev/sda → View Partitions of a Specific Hard Disk usin
# fdisk -s /dev/sda → View the Size of an existing Partition
# mkfs.ext3 /dev/sda → After the partition is created, format it using the mkfs command
#partprobe /dev/sda → It will update in kernel
#mount /dev/sda /u03 → mount on a particular directory
Save the /etc/fstab file. ( To make partition permanent )
/dev/sda /u03 ext3 defaults 0 0

# fsck /dev/sda2 → To Repair a corrupted file system.

TechZone, #101,Manjeera square, opp: prime hospital, Ameerpet. Ph # 9966637709, 040 - 66660787
Page 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy