- ANKUSH THAVALI
- 18 Sep, 2020
- 0 Comments
- 7 Mins Read
Basic Linux command for Oracle DBA
Important Linux Command for Oracle DBA
In this post , I have tried to add frequently used linux command by oracle dba. Just install the linux and then start practicing this command.
1) Finding the present working directory : pwd
This command will list the present working directory
example
$ pwd
2) create the directory : mkdir
example
$ mkdir data -> This command will create a directory data under the present working directory.
$ mkdir /blognow/data -> this command will create the directory data under blognow directory ( parent directory).
3) moving to a directory : cd
This command will change the working directory to the new directory
example
$ cd /blognow/data --> this command will change the current working directory to /blognow/data
4) deleting the the directory : rmdir
rmdir : this command will delete and empty directory in UNIX. Please not this command will not work if the directory is not empty.
Example
$ rmdir /blognow/data -> this command will data if the directory is empty.
Let’s assume there is another folder ‘data1’ inside data directory. In that case the above command will not succeed.
Example
let’s assume our directory structure is ‘/blognow/data/data1’ and we try to delete the directory data with the command $ rmdir /blognow/data . The command will fail stating that the directory data is not empty.
5) Deleting the contents forcefully : rm -rf
rm -rf :- this command will delete the contents of the directory recursively, which means it will delete all the all the subfolders and files in the directory which we are removing
Considering our previous example,
$ rm -rf /blognow/data
The above command will remove /blognow/data/data1 and /blognow/data
6) Moving the content is of a directory to another : mv
This command will move the content of the directory to another directory
example
$ mv /blognow/data /blognow/data1
The above command will move the content of the directory /wyheid/data to /blognow/data1
7) renaming a folder : mv
$ mv data data1
This command will rename the folder data to data1
File commands
8)The command to print the contents of a file: cat
Example
$ cat example.txt :- this command will print the contents of the file to the screen.
$ cat example.txt > new.txt :- this command will print the contents of the file example.txt to new.txt
9)Creating a new file
normally the files are created by corresponding applications for example a word processor program will create a file which contains the data. But we can use the cat command to create a simple file as in this example
$ cat "today is Monday" > newfile.txt
In this example a file “newfile.txt” is created with the content ” today is Monday”
10) Removing a file : rm
Example
$ rm newfile.txt
This command will delete “newfile.txt”, which is located in the present working directory and unix will prompt for your confirmation.If you want to avoid the prompt for the confirmation, -f option can be used with the command, as in this example
$ rm -rf newfile.txt
This command will delete “newfile.txt” without waiting for a confirmation from the operator
11) Renaming a file : mv
Example
$ mv first.txt second.txt
This command will rename the file “first.txt” to “second.txt”
12) Copying the file to another location : cp
Example
$ cp new.txt $HOME/new.txt
This command will copy the file “new.txt” to the user’s home directory
13) Listing the contents of a directory: ls
Example
$ ls /blognow/data
This command will list the contents of the folder “/blognow/data”. This command will only list the names of the files and folders in this directory. If you wanted to list that other details like the creation time owner of the file etc, we how to use other switches to the command “ls”
Example
$ ls -l /blognow/data
This command will list to the contents of the folder/blognow/data with all the details. Also known as long listing
Long listing in the order of creation time
$ ls -lt /blognow/data
Long list in the order of creation with hidden files
$ ls -alt
This command will list all the files in that folder “/blognow/data” along with hidden files.
13) Copying the files to another machine: scp
Example
$ scp example.txt oracle@newserver1:/blognow
This example will copy the file” example.txt to the new server with the name “new server1” under the folder /blognow. The file will be copied with the privilege privilege of user Oracle and will be prompted to enter the password of the user Oracle while the command is executed
14) Finding the free space on the system : df
Example
# df -h
If you execute the command from the command prompt Linux will display the Mount points and their allocated size and available space, in human readable format
15) Viewing the contents page by page : more
Example
$ cat example.txt | more
This command will print the contents of the file “example.txt” to the screen. But if the content is more than that of the screen, instead of scrolling up all the contents UNIX will will pause the scrolling up and wait for the instruction (usually the pressing of space bar) from the user.
Important point, in in the above example , I am concatenating two commands using the ‘|’ symbol. In an other words the output of the first command(cat example.txt) is given as the input for the second command (more).
16) Log in to a remote server : ssh
Example
$ ssh oracle@server1
In this example we are trying to connect to the remote host “server1” as oracle. The password of the Oracle user will be prompted while the command is executed.
17) Executing a command on a remote server
Example
$ ssh oracle@server1 cat /etc/oratab
This command will connect to server1 as Oracle user and print the contents of the file /etc/oratab. The password of the user Oracle will be prompted during the command execution.
18) Compressing the file : gzip
Example
$ gzip myfile.txt
This command will compress the file “myfile.txt”, with the gzip utility. The output file will have an extension “.gz”. In our example the compass of filing will be “myfile.txt .gz”
19) uncompressing the file : gunzip
$ gunzip myfile.txt.gz
This command will uncompress the file ” myfile.txt.gz”
20) Listing the schedule the jobs : crontab
Example
$ crontab -l
This command will list to the scheduled cron jobs of the current user . Cron is a utility to schedule the automatic execution of jobs. crontab is the file which contains the details of the scheduled jobs. We can create a new schedule a job by adding an entry to the crontab file. We will discuss more about Cron and job scheduling in another post.
21) Displaying the information about the processes running on the computer : ps
$ ps -eaf
This command will list the processes currently running on the operating system, with details like process ID, parent process ID, program which is being executed, time at which the process got executed etc.
22)Terminating a process : kill
# kill -F 900
The above command will forcefully terminate the process with process ID 900. We can find out the process ID and parent process ID of a process using the PS command explained earlier.
23) Shutting down the operating system : shutdown
Example
# shutdown -h now
This command will cut down the server immediately
# shutdown -h +10
This command will shut down the server after 10 minutes
# shutdown -r now
This command will reboot the machine immediately.
24) Finding out the free memory on the machine : free
Example
# free -G
This command will list the available memory as well as cached memory in gigabyte format.
25) Finding out the top memory consuming process in the operating system: top
Example
# top
this command will list the details like top consumers with the respect to memory and processing power, total CPU usage, swap usage etc. This command is highly useful when you are having a performance issue with the server.
26) Changing the ownership of the file or a directory : chown
Example
# Chown oracle:dba myfile.txt
This command will change the ownership of the file “myfile.txt” to ‘oracle’ user
27) Changing the permission of the file or directory: chmod
Example
# chmod -R 755 /blognow/data
This command will permission of all the files and subfolders under /blognow/data . The resulting permission will be as follows
The file owner : read write and execute
The memeber in the group of the file owner: read and execute
others : read and execute
28) Changing the password of the user : passwd
Example
# passwd oracle
This command executed as root user will change the password of the user Oracle.
$ passwd
This command is executed by the user who is already logged into the operating system and it will change the password of the user who executes the command .
29) Understanding the important information of the Operating System: uname
example
# uname -a
Linux blognowlabserver2 2.6.32-100.28.5.el6.x86_64 #1 SMP Wed Feb 2 18:40:23 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
This example , the name of the machine is “blognowlabserver2” , which is Linux OS and its a 64 bit OS
30) Getting the help of a command : man
Example
# man rm
31) Cleanup any unwanted trace files more than seven days old
find . *.trc -mtime +7 -exec rm {} ;
32) How to find the release in Linux
cat /etc/*-release