Sunday, March 20, 2011

Basic Linux commands

IFCONFIG : It is used to display the IP address and configure Kernal-
resident network.
Syntax: ifconfig

Kill -9: To terminate or kill the process in Linux we use the kill command
Syntax: kill -9 pid#

Kill -3: It is used to take thread dumps on Linux platforms.
Syntax: kill -3

Tail: The tail command displays the last few lines of a file. By default, tail will
show the last 10 lines of a file.
Syntax: tail filename
Syntax: tail –n filename
Where n is number of lines

Head: The Head command displays the first few lines of a file. By default,
Head will show the first 10 lines of a file.
Syntax: Head filename
Syntax: Head –N filename
Where N is number of lines

Top: It is used to show CPU consumption, RAM memory consumption and
the top sessions on a Linux server.
Syntax: root> top
Cpu status:
CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS

VMSTAT: The VMSTAT displays various server values over given time
interval. It is invoked from UNIX prompt, and it has several numeric
parameters.
The first numeric argument to VMSTAT represents the time interval
[expressed in seconds] between server samples. The second argument specifies
the number of samples to be reported
Syntax: root> vmstat [first argument] [second argument]
Ex: root> vmstat 2 2

DU: It displays the disk usage for all directories and subdirectories under the
current directory.
Syntax: du
DF: It displays the disk space free on each file system. It is very useful.
Syntax: df -m results in megabytes
df -k results in kilobytes
df –h results in gigabytes

PS: It displays the current process information.
Syntax: root> ps
root> ps –ef | grep –i java
LS –ltr: It list the files and directories with complete description
Syntax: root> ls –ltr
PWD: It displays the present working directory.
Syntax: root> pwd

Free: This command is used to quickly display the amount of RAM memory
on the server.
Syntax: root> free

UMASK: This command can be used to read or set default file permissions for
the current user.
Syntax: root> umask 022
• the umask value is subtracted from the default permissions(666) to give
the final permissions.
666 : Default permission
022 : - umask value


644 : Final permission

CHMOD: This command is used to alter the file permissions after the file has
been created.
Syntax: root> chmod 777 *.log

Owner
=======
7 (u+rwx)
6 (u+wx)
5 (u+rx)

Group
=======
7 (g+rwx)
6 (g+wx)
5 (g+rx)

World
=====
7 (o+rwx)
6 (o+wx)
5 (o+rx)

Permission
=========
read + write + execute
write + execute
read + execute

VI Editor: Vi editor is modifying, coping, deleting and adding
Syntax: VI filename
i is the command to insert the data
a is the command append the data
:w it is for saving
:q we need to quit from vi editor
:wq we need to save and quit from vi editor
:q! Forcefully quitting from vi editor without saving

Rm: Rm is a command to remove a file
Syntax: rm[options] file/dir
Ex: rm file1

Rm dir : it can delete dir
Rm –r dir1: Before delete it will ask I am gong to delete or not
Rm –rf dir1: It will delete the dir1 forcefully without asking

CHOWN: This command is used to change the ownership of files after
creation. The “-R” flag causes the command to recurse through subdirectories.
Syntax: root> chown –R oinstall.dba *

CP: This command is used to copy files and directories
Syntax: root> cp [from] [to]
Ex: cp file1 file2
SCP: It will copy the files from one server to another server
Syntax:
USERADD: The useradd command is used add the OS users
Syntax:root> useradd -G oinstall –g dba –d
/user/users/
my_user –m –s /bin/ksh my_user

NETSTAT: It is useful for checking the network configuration and activity. It
is in fact a collection several tools lumped together

The –n flag makes netstat print addresses as dotted quad IP numbers
rather than the symbolic host and network names.
The –r flag displays the kernel routing table in the way we have been
doing with route.
The –i flag displays statistics for the network interfaces currently
configured.
The –a flag by itself will display all sockets from all families

Tar: Tar command is used to create tape archives and add or extract the files
Creating tar file: tar –cvvf file.tar myfile.txt
Extracting the files from tar file:
1) tar –xvvf : This command is used to uncompresse(untar)
the file.
Ex: tar –xvvf myfile.txt
2) tar –xvzf : This command is used to extract the file
Ex: tar –xnzf myfile .txt
NSLOOKUP:
Nslookup [-option….] [host-to-find [server name]]
It is program to query Internet domain name servers. Nslookup has two
modes:
1. Interactive: It allows the user to query name servers for
information about various hosts and domains or to print a list of
hosts in a domain.
2. Non-interactive: It is used to print just the name and requested
information for a host or domain.

Interactive mode is entered in the following cases:
a) when no arguments are given(the default name server will be used)
b) when the first argument is hyphen (-) and the second argument is the
host name or internet address of a name server.

No comments:

Post a Comment