Useful shortcuts for vi editor

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday 23 February 2018

How to see both Oracle VM Virtual Box 32bit/64bit options?

e.g. If there are only 32 bit Linux distro in the OS list, you should enable virtualization support in BIOS

* BIOS -> CMOS Setup Utility -> Virtualization Technology -> [Enabled]

Friday 8 December 2017

How to install/use rlwrap?

Installation
e.g.
# rpm -ivh rlwrap-0.42-1.el6.x86_64.rpm  

Usage
Add alias to .bash_profile file (or .bashrc, etc.)
alias sqlplus='rlwrap sqlplus'

$ sqlplus hr/hr
SQL> select 1 from dual;

Key trick is that while in sqlplus command line, use up or down keys to navigate sql history.

Wednesday 8 November 2017

How to export/set ORACLE_SID?

Linux
export variable
$ export ORACLE_SID=XE

check variable
$ echo $ORACLE_SID

Windows
set variable
> set ORACLE_SID=XE

check variable
> echo %ORACLE_SID%

Tuesday 1 August 2017

How to start/stop/configure samba service?

If you need, uninstall old samba
# yum erase samba samba-common samba-client 

install tool
# yum install samba4

or upgrade tool
# yum upgrade samba4

configure settings
# vi /etc/samba/smb.conf

e.g.
[share_folder]
 comment = Share Folder
 path = /share_folder
 create mode = 0777
 readonly = no
 browseable = yes
 public = yes

Check configuration of samba
# testparm

check samba service and version
# smbstatus

startup options
# chkconfig smb on
# service smb start

connect to share folder
e.g. 
RUN> \\10.10.10.10\share_folder

remove startup option and stop vnc
# chkconfig smb off
# service smb stop

Tuesday 11 April 2017

How to find and investigate a process in top command output?

Total connection by machine:
SQL> select machine, count(*) from v$session group by machine order by 2;

Total number of database user who connected:
SQL> select count(1) "NO. Of DB Users Connected", to_char(sysdate,'DD-MON-YYYY:HH24:MI:SS') sys_time from v$session where username is NOT NULL;

Define a process(pid) from top:
17831 ora11g .. ora_m000_ALPERDB  

Get detailed info from database:
SQL> select * from v$process where spid = 17831;
-> M000 means MMON Slave Process
-> e.g. pid -> 16, sid -> 555

SQL>
SELECT s.username, osuser, process machine, p.terminal, type, sid, s.serial#, s.program
FROM v$session s, v$process p
WHERE p.pid = 16
AND s.paddr = p.addr;

SQL> select * from gv$session where sid = 555;

Get sql from below code related to example process if it has SQL:
SQL>
SELECT 
      s.sid
     ,s.CLIENT_INFO
     ,s.MACHINE
     ,s.PROGRAM
     ,s.TYPE
     ,s.logon_time
     ,s.osuser
     ,sq.sorts
     ,sq.DISK_READS
     ,sq.BUFFER_GETS
     ,sq.ROWS_PROCESSED
     ,sq.SQLTYPE
     ,sq.SQL_TEXT
 FROM gv$session s    
    , gv$sql sq
WHERE s.SQL_HASH_VALUE = sq.HASH_VALUE
  --AND s.inst_id= 1
  AND s.sid = 555 
  AND sq.inst_id= s.inst_id

Thursday 9 March 2017

How to kill tty/pts terminal?

Check first your connection to prevent killing yourself
$ tty

Kill other connection
$ skill -9 pts/1
or
# skill -KILL pts/1

Info
Teletypewriter - TTY
pseudo terminal slave - PTS

Saturday 4 February 2017

watch examples

$ watch free -m
-> Display free command output in every two seconds 

$ watch -n 5 free -m
-> Display free command output in every five seconds  (with -n parameter)

Tuesday 31 January 2017

screen commands

screen -> start the tool
ctrl + a -> control screen
ctrl + a + c -> define new screen
ctrl + a + n -> switch between screen
ctrl + a + d -> detach screen
ctrl + a + n -> switch between screen
screen -r -> reattach screen
screen -r [xyz] -> reattach specific screen
screen -ls  -> list the screens
ctrl + a + x -> lock screen
ctrl + a + k  -> kill screen

Friday 20 January 2017

How to start/stop/configure vnc service?

install tool:
yum install tigervnc-server

configure settings:
vi /etc/sysconfig/vncservers

e.g.
VNCSERVERS="2:root 3:oracle 4:alper"
VNCSERVERARGS[2]="-geometry 1280x1024 -nolisten tcp -localhost"
VNCSERVERARGS[3]="-geometry 1280x1024"
VNCSERVERARGS[4]="-geometry 1280x1024"

change password of vnc
$ whoami
-> alper
$ vncpasswd
-> alper123

startup options:
# chkconfig vncserver on
# service vncserver start

login to system with windows vncviewer tool
e.g. 10.10.10.10.:4

remove startup option and stop vnc:
# chkconfig vncserver off
# service vncserver stop

Info: Virtual Network Computing (VNC) is a graphical desktop sharing system

Thursday 19 January 2017

output columns of top command

Columns:
PID     -> Process ID   
USER    -> Process owner   
PR      -> Priority of process 
NI      -> Nice value of process  
VIRT    -> Virtual memory using by process
RES     -> Physical memory using by process  
SHR     -> Shared memory of process
S       -> Status of process (R-> Running, S-> Sleeep, Z-> Zombie, D-> Uninterruptible Sleep, T-> Traced or Stopped)
%CPU    -> CPU usage of process (as percent)
%MEM    -> RAM usage of process (as percent)
TIME+   -> Total time activity for process 
COMMAND -> indicates of process name

Info:
PR = 20 + NI (PR-RT -> Real Time system process)
PR -> (0 is the highest priority and 39 is the lowest priority)
NI; Nice value (−20 is the highest priority and 19 is the lowest priority)
VIRT; Virtual image (kb) -> disk storage + RAM
RES;  Resident size (kb) -> RAM (non-swapped physical memory)
SHR; Shared mem size (kb)-> RAM (shared memory)

Extras:
Set priority of a process before start;
nice -n 19 tar cvzf archive.tgz largefile

Change priority of a process;
renice -n -20 -p process_id

Ref:

Wednesday 11 January 2017

How to learn linux distribution?

See all info
$ lsb_release -a
a - all

See only distro info
$ lsb_release -i -r
i - id, r - release

How to define timeout setting for auto logout users in linux system?

Configure it
# vi /etc/profile
add following parameter at the end of the profile file:
# this parameter runs as seconds and affects all users. e.g. 3600; one hour
TMOUT=3600

Check it
$ echo $TMOUT

Test result
$ timed out waiting for input: auto-logout

Monday 19 December 2016

How to see file extensions in current directory?

$ find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

bash: /bin/rm: Argument list too long error Solution

Command
rm -f *

Error 
bash: /bin/rm: Argument list too long error

Solution
Use following command line
$ find . -maxdepth 1 -name "*.txt" -print0 | xargs -0 rm

Thursday 15 September 2016

How to gain root access without entering root password on Linux?

Add the line into the end of /etc/sudoers file as root
vi /etc/sudoers
alper ALL=(ALL) NOPASSWD: ALL

Test your connection
ssh alper@10.10.10.10
$ sudo su -
(executes all /etc/profile, .profile and .bashrc files)
# ifconfig
$ sudo su
(executes only .bashrc file)
# ifconfig

References:

Tuesday 2 August 2016

How to mount devices at startup by /etc/fstab and /etc/rc.d/rc.local for RedHat distro?

-> define uuid for connected devices
ls -l /dev/disk/by-uuid/

-> add related info into /etc/fstab
e.g.
UUID=1111 /alper/sdb1 ext3 defaults,nobootwait 0 0

-> if this cannot mount the path, you may deal with network issues. To fix it, you should add following command into /etc/rc.d/rc.local config file.
mount -a

extra info: -> If you use 1 1 instead of 0 0 for priority option, you may encounter "maintenance mode" problem. To fix it, run this command
mount -o rw, remount /

Tuesday 26 July 2016

What are the differences between SAN, NAS and DAS?

SAN(Storage Area Network);
SAN is used for applications to access BLOCK storage over an optical FC network using the SCSI protocol. (e.g. FibreChannel, iSCSI, FoE)

NAS(Network Attached System);

NAS is used for access to FILE storage over TCP/IP on an Ethernet network using either the CIFS (for Windows) or NFS (for Unix) protocol. (e.g. NFS, CIFS, AFS)

DAS(Direct Attached Storage);
DAS is a block device from a disk which is physically [directly] attached to the host machine. (e.g. IDE, SCSI, SATA)

Source: 

http://searchstorage.techtarget.com/tip/SAN-vs-NAS-Which-do-you-need
http://serverfault.com/questions/81723/what-is-the-difference-between-san-nas-and-das

Tuesday 19 April 2016

How to use "wall" and "write" commands?

$ wall
-> press "ctrl+d" to send the message

$ echo "Hello World!" | wall

$ sudo wall message.txt
-> send content of message.txt file

$ write alper
-> press "crlt+c" to quit

$ write alper pts/0
-> run "who" to see terminal names like pts/0

Thursday 7 April 2016

What are hard link and soft link in Linux?

Hard link; it may used for backup (replica) purpose. (seems to RAID 1)
e.g.
$ ln original_file.txt hd_file.txt
$ ln original_file2.txt /home/alper/hd_file2.txt

Soft link; it may used as shortcut like in Windows OS.
e.g.
$ ln -s original_file soft_file.txt
$ ln -s original_file /home/alper/soft_file2.txt

to list the links;
$ ls -l 
(l; list)
or 
$ ls -i
(i; inode number)
then find the files by same inode number
$ find . -inum <inode_number>

e.g.
$ find . -inum 10000

tcpdump examples

tcpdump -D
-> Display all available interfaces for tcpdump

$ tcpdump -i 1 | more
-> Listen (interface 1) with more command

$ tcpdump -i any
-> Listen all actived interfaces

$ tcpdump -i eth1
-> Listen eth1 interface

$ tcpdump -i eth0 port 22
-> Listen eth0 interface on port 22

$ tcpdump -i eth2 port 23 -w example.pcap
-> Listen eth2 interface on port 23 and save as desired file name