Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Unix Commands

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Unix Commands

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

UNIX

Commands
By Mogalaiah K
Date : 09/07/2024

© 2024 DXC Technology Company. All rights reserved.


DXC Internal
Topics going to be covered
 Basic File Navigation
 File Permissions
 OS User Management
 Process Management
 uname and hostname
 Error Lines in Files
 Remove Old Files
 File Exists Check
 Find Big Files
 alias

© 2024 DXC Technology Company. All rights reserved. November 29, 2024 2
DXC Internal
Topics going to be covered
 Compress Files
 General Performance
 vmstat
 free
 iostat
 CPU Usage
 sar
 mpstat
 Top
 Automatic Startup Scripts on Linux
 CRON

© 2024 DXC Technology Company. All rights reserved. November 29, 2024 3
DXC Internal
Basic File Navigation
The "pwd" command displays the current directory.
oracle> pwd
/u01/app/oracle/product/12.1.0.2.0

The "ls" command lists all files and directories in the specified directory. If no location is defined it acts on the current
directory.
oracle> ls
oracle> ls -ltr /u01/app/oracle/product/12.1.0.2.0
cd /u01/app/oracle/product/12.1.0.2.0
ls -ltr

oracle> ls -al
The "-a" flag lists hidden "." files. The "-l" flag lists file details.
The "cd" command is used to change directories.
oracle> cd /u01/app/oracle
© 2024 DXC Technology Company. All rights reserved. 4
DXC Internal
Basic File Navigation
The "touch" command is used to create a new empty file with the default permissions.
oracle> touch my.log

The "rm" command is used to delete files and directories.


oracle> rm my.log
oracle> rm -R /archive
oracle> rm -rf *.log
The "-R" flag tells the command to recurse through subdirectories.

The "mv" command is used to move or rename files and directories.


oracle> mv [from] [to]
oracle> mv my.log my1.log
oracle> mv * /archive
oracle> mv /archive/* .
The "." represents the current directory.

© 2024 DXC Technology Company. All rights reserved. 5


DXC Internal
Basic File Navigation
The "cp" command is used to copy files and directories.
oracle> cp [from] [to]
oracle> cp my.log my1.log
oracle> cp * /archive
oracle> cp /archive/* .

The "mkdir" command is used to create new directories.


oracle> mkdir archive

The "rmdir" command is used to delete directories.


oracle> rmdir archive

© 2024 DXC Technology Company. All rights reserved. 6


DXC Internal
Basic File Navigation
The "find" command can be used to find the location of specific files.
oracle> find /u01/app/oracle/product/db_1/ -name dbmspool.sql
oracle> find / -print | grep -i dbmspool.sql
oracle> find . -name dbmspool.sql
The "/" flag represents the staring directory for the search. Wildcards such as "dbms*" can be used for the filename.

The "which" command can be used to find the location of an executable you are using.
oracle> which sqlplus
The "which" command searches your PATH setting for occurrences of the specified executable.

© 2024 DXC Technology Company. All rights reserved. 7


DXC Internal
File Permissions
See Linux Files, Directories and Permissions.
The "umask" command can be used to read or set default file permissions for the current user.
oracle> umask 022
The umask value is subtracted from the default permissions (666) to give the final permission.
666 : Default permission
022 : umask value
644 : final permission
The "chown" command is used to reset the ownership of files after creation.
oracle> chown -R grid:oinstall /u01/app/product/db_1/
The "-R" flag causes the command ro recurse through any subdirectories.
The "chmod" command is used to alter file permissions after the file has been created.
oracle> chmod 777 *.log

© 2024 DXC Technology Company. All rights reserved. 8


DXC Internal
File Permissions
Owner Group World/Other Permission
========= ========= ========= ======================
7 (u+rwx) 7 (g+rwx) 7 (o+rwx) read(4) + write(2) + execute(1)
6 (u+rw) 6 (g+rw) 6 (o+rw) read + write
5 (u+rx) 5 (g+rx) 5 (o+rx) read + execute
4 (u+r) 4 (g+r) 4 (o+r) read only
2 (u+w) 2 (g+w) 2 (o+w) write only
1 (u+x) 1 (g+x) 1 (o+x) execute only
Character equivalents can be used in the chmod command.
oracle> chmod o+rwx *.log
oracle> chmod g+r *.log
oracle> chmod -Rx *.log
chmod 777 /u01/
© 2024 DXC Technology Company. All rights reserved. 9
DXC Internal
OS Users Management
See Linux Groups and Users.
The "useradd" command is used to add OS users.
[root@node5 ~]# usermod -g oinstall -G dba -d /home/oracle -m -s /bin/ksh grid
• 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.
The "usermod" command is used to modify the user settings after a user has been created.
[root@node5 ~]# usermod -s /bin/csh my_user
The "userdel" command is used to delete existing users.
[root@node5 ~]# userdel -r my_user
The "-r" flag removes the default directory.
© 2024 DXC Technology Company. All rights reserved. 10
DXC Internal
OS Users Management
The "passwd" command is used to set, or reset, the users login password.
oracle> passwd oracle
The "who" command can be used to list all users who have OS connections.
oracle> who
oracle> who | head -5
oracle> who | tail -5
oracle> who | grep -i ora
oracle> who | wc -l
• The "head -5" command restricts the output to the first 5 lines of the who command.
• 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.

© 2024 DXC Technology Company. All rights reserved. 11


DXC Internal
Process Management
See Linux Process Management (ps, top, renice, kill).
The "ps" command lists current process information.
$ ps
$ ps -ef | grep -i ora
$ ps -ef | grep -i ora | grep -v grep
$ ps -ef | grep -i [o]ra
Specific processes can be killed by specifying the process id in the kill command.
$ kill 12345
$ kill -9 12345
You can kill multiple processes using a single command by combining "kill" with the "ps" and "awk"
commands.
$ kill -9 `ps -ef | grep ora | awk '{print $2}'`

© 2024 DXC Technology Company. All rights reserved. 12


DXC Internal
uname and hostname
The "uname" and "hostname" commands can be used to get information about the host.
oracle> uname -a
Linux node5.mogal.com 3.10.0-1160.el7.x86_64 #1 SMP Tue Aug 18 14:50:17 EDT 2020 x86_64 x86_64 x86_64
GNU/Linux
oracle> uname -a | awk '{ print $2 }'
node5.mogal.com
oracle> hostname
node5.mogal.com

© 2024 DXC Technology Company. All rights reserved. 13


DXC Internal
Error Lines in Files
You can return the error lines in a file using.
[oracle@node5 trace]$ pwd
/u01/app/oracle/diag/rdbms/orcl/orcl/trace
[oracle@node5 trace]$
oracle> cat alert_orcl.log| grep -i ORA-
The "grep -i ORA-" 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.
oracle> cat alert_orcl.log| grep -i ORA- | wc -l

© 2024 DXC Technology Company. All rights reserved. 14


DXC Internal
Remove Old Files
The find command can be used to supply a list of files to the rm command or the "-delete" command can be
used directly.
find /backup/logs/ -name *.trc -mtime +21 -exec rm -f {} ;
find /backup/logs/ -name *.trc -mtime +21 -exec ls -ltr {} ;
find /backup/logs/daily_backup* -mtime +5 -exec rm -f {} \;
find /backup/logs/daily_backup* -mtime +5 -delete;

Find Big Files


Find the top 20 biggest files recursively from this directory.
$ find . -type f -print0 | xargs -0 du -h | sort -hr | head -20

© 2024 DXC Technology Company. All rights reserved. 15


DXC Internal
alias
An alias is a named shortcut for a longer command using the following format.
alias name='command'
alias sql='sqlplus / as sysdba'
alias dbs='cd $ORACLE_HOME/dbs'
alias tns='cd $ORACLE_HOME/network/admin'
alias alert='tail -100f $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace/alert_$ORACLE_SID.log'
For example, if you require sudo access for a specific command, you might want to include this as an alias so you
don't have to remember to type it.
alias myscript='sudo -u oracle /path/to/myscript'| xargs -0 du -h | sort -hr | head -20

© 2024 DXC Technology Company. All rights reserved. 16


DXC Internal
Compress Files
See Linux Archive Tools (tar, star, gzip, bzip2, zip, cpio).
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. 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
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
tar -cvpf /bacup/oracle_home_bkp.tar /u01/app/oracle/product/db_1
tar -xvpf /bckup_loca.tar

© 2024 DXC Technology Company. All rights reserved. 17


DXC Internal
General Performance
vmstat
Reports virtual memory statistics.
# vmstat 5 3
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 1060608 24372 739080 0 0 1334 63 1018 1571 14 11 66 10 0
0 0 0 995244 24392 799656 0 0 6302 160 1221 1962 10 10 62 18 0
0 0 0 992376 24400 799784 0 0 1 28 992 1886 3 2 95 0 0
See the vmstat man page.
Netstat command in Linux
Netstat -l
Mpstat
Free
© 2024 DXC Technology Company. All rights reserved. 18
DXC Internal
General Performance
free
Reports the current memory usage. The "-/+ buffers/cache:" line represents the true used and free memory,
ignoring the Linux file system cache.
# free
total used free shared buffers cached
Mem: 8178884 4669760 3509124 0 324056 1717756
-/+ buffers/cache: 2627948 5550936
Swap: 10289148 0 10289148
#
iostat
Reports I/O statistics.
# iostat
Linux 3.2.10-3.fc16.x86_64 (maggie.localdomain) 03/19/2012 _x86_64_(4 CPU)

© 2024 DXC Technology Company. All rights reserved. 19


DXC Internal
General Performance
Using ipcs & ipcrm: Checking active message q's,memory, semaphores
ipcs -a
ipcrm -m 18602
mpstat
Reports processor related statistics.
# mpstat 10 2
Linux 2.6.32-100.0.19.el5 (ol5-112.localdomain) 06/27/2011
# top
top - 13:58:17 up 2 min, 1 user, load average: 2.54, 1.11, 0.41
Tasks: 160 total, 6 running, 154 sleeping, 0 stopped, 0 zombie
Cpu(s): 77.1%us, 22.6%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.3%hi, 0.0%si, 0.0%st
Mem: 2058872k total, 879072k used, 1179800k free, 23580k buffers
Swap: 4095992k total, 0k used, 4095992k free, 620116k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND


2882 oracle 20 0 610m 64m 56m R 24.9 3.2 0:02.20 oracle

© 2024 DXC Technology Company. All rights reserved. 20


DXC Internal
CRON
See CRON : Scheduling Tasks on Linux.
There are two methods of editing the crontab file. First you can use the "crontab -l > filename" option to list the contents and pipe
this to a file. Once you've editied the file you can then apply it using the "crontab filename".
• Login as oracle
• crontab -l > newcron
• Edit newcron file.
• crontab newcron
Alternatively you can use the "crontab -e" option to edit the crontab file directly.
The entries have the following elements.
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31 *
month 1-12 *
day of week 0-7 (both 0 and 7 are Sunday) 6

© 2024 DXC Technology Company. All rights reserved. 21


DXC Internal
CRON
user Valid OS user
command Valid command or script.
The first 5 fields can be specified using the following rules.
* - All available values or "first-last".
3-4 - A single range representing each possible from the start to the end of the range inclusive.
1,2,5,6 - A specific list of values.
1-3,5-8 - A specific list of ranges.
0-23/2 - Every other value in the specified range.
The following entry runs a cleanup script a 01:00 each Sunday. Any output or errors from the script are piped to /dev/null to prevent a
buildup of mails to root.
00 02 * * * /u01/app/oracle/dba/weekly_cleanup > /dev/null 2>&1
To prevent a new job starting if the last run is still running, consider using flock. The job will only run if a lock can be obtained on the
specified lockfile.
From:
0 1 * * 0 /u01/app/oracle/dba/weekly_cleanup > /dev/null 2>&1
To:
0 1 * * 0 /usr/bin/flock -n /tmp/weekly_cleanup.lockfile /u01/app/oracle/dba/weekly_cleanup > /dev/null 2>&1

© 2024 DXC Technology Company. All rights reserved. 22


DXC Internal
Other commands
to send the file

scp file_name <username>@<server>:<path>

to pull the file

scp <username>@<server>:<path>/<file_name> <target_path>

vi editor

tail -100 file

head -100 file

df -h

df -k

bdf

top

topas

free -g

du -sh

.bash_profile

.profile

oratab

© 2024 DXC Technology Company. All rights reserved. 23


DXC Internal
Questions and answers

© 2024 DXC Technology Company. All rights reserved. November 29, 2024 24
DXC Internal
© 2024 DXC Technology Company. All rights reserved.
DXC Internal

You might also like