basic unix commands for dba
TRANSCRIPT
-
8/12/2019 Basic Unix Commands for DBA
1/8
1
Basic Unix commands for DBA
Command Syntax Description
1 man man command
man ls
Display the manual of the command, this will listall the options which can used by the command.
To exit out of the manual you need to press q.
2. ls ls
ls -a
ls -ltr
List all the files under your current directory.
List all the hidden files.
List files with date, sorted in the date modified,
oldest first.
-rw-r--r-- 1 oracle oinstall 0 Oct 13 20:21 test.txt.
Column1 - Permissions of the file or directory
r-read, w-write, x-execute
Position 1 indicates if it is a directory
Positions 2-4 is the permission for owner
Positions 5-7 is the permission for group
Positions 8-10 is the permission for others
Column2 - Owner of the file/directory
Column3 - Group which the owner belogs to
Column4 - Size of the file in bytes
Column5 - Last Modified Date
Column6 - Last Modified Time
Column7 - Name of the file/directory
3. clear clear To clear the screen
4. pwd pwd Displays the Present/Current Working Directory
.
5. cd cd [directory name]
cd Test
cd ..
cd ~
Change directory, without argument will change
your working directory to your home directory.
Change working directory to "Test".Change working directory to one directory
backwards (.. is parent and . is current
directory).
~ is also referred as home directory.
description of the
output from ls -ltr
-
8/12/2019 Basic Unix Commands for DBA
2/8
2
6. touch touch filename
touch test.txt
Create a 0 byte file or to change the timestamp
of file to current time .
This will create a file called as test.txt.
7. mkdir mkdir directory name
mkdir test_1
mkdir -p
mkdir directory1 directory2
To Create a Directory .
This will create a directory called as test_1,in the
current path.
Create directory down many levels in single
command.
mkdir -p
/home/oracle/test_1/test_2/test_3/test_4
This will create multiples directories in one
command, in the current path
8. rmdir rmdir directory name
rmdir test1
To remove a empty directory.
This will remove a empty directory named astest1.
9. rm rm filename
rm -rf directory name
To remove a file( with data or without data).
Remove directory with files. Note- There is no
way to undelete a file or directory in UNIX. So be
careful in deleting files and directories. It is
always good to have rm -i filename for deletes.
When you -i flag it ask for confirmation before
deleting it.
9. cp cp filename newfilename
cp -r* newpath
Copy a file.
To copy all files and subdirectories to a new
location, use -r flag to recursively copy.
10. mv mv filename newfilename
mv filename directoryname
mv filename
directoryname/newfilename
mv * directotyname
Rename (Move) a file. Rename filename to new
filename.
Move filename under directory name with the
same file name.
Move filename to directory name as new
filename.
If you use a wildcard * in the filename, It will
move all the files to directory name specified in
the command.
11. file file filename To see what kind of file, whether editable.
Executable files are binary and you should not
open them.
-
8/12/2019 Basic Unix Commands for DBA
3/8
3
12. cat cat filename
cat filename1 filename2
filename3 > new_filename
See contents of a text file. cat (catenae) will list
the whole file contents. Cat is mostly used to
catenae two or more files to one file using the
redirection operator.
Catenae the contents of filename1, filename2
and filename3 to a single file called
new_filename. If you do not use the
redirection(>), then the result will be shown on
the standard output, i.e., screen.
13. more
page
more filename
page filename
Show the contents of the file, one page at a
time. In more/page, use space to see next page
and ENTER to see next line. If you wish to edit
the file (using vi), press v; to quit press q.
14 pg pg filename To show the contents of the file, page by page.
In pg, you go up and down the pages with + and
- and numbers.
1 First Page of the file
$ Last Page of the file
+5 Skip 5 pages
-6 Go back 6 pages
ENTER Next page
- Previous Page
q Quit
/string Search for string
15. tail tail -n filename
tail -10 filename
tail -f filename
To see the specified number of lines from theend of the file. where m is number of lines.
will display last 10 lines from filename.
will display the current appending output in the
filename.
16. head head -n filename To see the specified number of lines from the
top of the file.
17. env env
To set an environment
variable:
echo $VARIABLENAME
To see value of all environment variables.
In ksh or sh
"export VARIABLENAME=value", Note there is
no space between =.
See value of an environment variable
-
8/12/2019 Basic Unix Commands for DBA
4/8
4
18. echo echo string
echo "Oracle SID is
$ORACLE_SID"
To print the string to standard output.
Will display "Oracle SID is ORCL" if the value of
ORACLE_SID is ORCL.
19. chmod chmod permission filename
chmod +rwx filename
chmod 777 filename
chmod u+rwx,g+rx,o-rwx
filename
chmod 750 filename
Change the permissions on a file.As explained
under ls -l, the permissions are read, write,
execute for owner, group and others.
You can change permissions by using numbers
or the characters r,w,x. Basically, you arrive at
numbers using the binary format.
Examples:
rwx = 111 = 7
rw_ = 110 = 6
r__ = 100 = 4r_x = 101 = 5
Give all permissions to everyone on filename
Read, write, execute for owner, read and
execute for group and no permission for others
20. chown chown newuser filename Change owner of a file
21. chgrp chgrp newgroup filename
chown newuser:newgroup
filename
Change group of a file
Change owner and group of file.
22. compress compress filename Compress a file - compressed files have
extension .Z. To compress file you need to have
enough space to hold the temporary file.
23. uncompress uncompress filename Uncompress a file
-
8/12/2019 Basic Unix Commands for DBA
5/8
5
24. df df [options] [mountpoint]
df -k /u01
df -k .
Free space available on the system (Disk Free);
without arguments will list all the mount points.
Free space available on /u01 in Kilobytes.
If you're not sure of the mount point name, go
to the directory where you want to see the free
space and issue this command, where "."
indicates current directory. You can use df -h to
display the sizes in GB.
25. du du [-s] [directoryname]
du -s
Disk used; gives operating system blocks used by
each subdirectory. To convert to KB, for 512K OS
blocks, divide the number by 2.
gives the summary, no listing for subdirectories
26. find Find files.
find /home/oracle -name
"*.txt" -print
find . -name "*log" -print
-exec rm {} \;
find is a very useful command, searches
recursively through the directory tree looking for
files that match a logical expression(search
string). It has many options and is very powerful.
Simple use of find - to list all files whose name
ending with .txt under /home/oracle and its
subdirectories.
to delete files whose name end in log. If you do
not use the "-print" flag, the file names will notbe listed on the screen.
-
8/12/2019 Basic Unix Commands for DBA
6/8
6
27. grep Global regular expression
print
grep oracle /etc/passwd
grep -i -l EMP_TAB *.sql
grep -v '^#' /etc/oratab
to search for an expression in a file or group of
files. This is a very useful command, especially to
use in scripts.
to display the lines containing "oracle" from
/etc/passwd file.
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 extension.
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).
28. mail mail "[email protected]"