Tuesday, 9 May 2017

Linux Support | Linux commands | linux tutorial

Linux Support | Linux commands | linux tutorial

_________________________________________________________________________________

Check the Linux machine is 32bit or 64

uname -m
x86_64 ==> 64-bit kernel
i686   ==> 32-bit kernel
_________________________________________________________________________________

scp :
this command use for copy file from remote pc

example:
for Copy Directory 1)scp -rp 192.168.2.X.X:/usr/local/eclipse /usr/local/
for Copy application
 
where..
-192.168.2.X.X is address of the user which has eclipse di
-:/usr/local/eclipse path to eclipse
-/usr/local/ path where receiver want to save eclipse
_________________________________________________________________________________
ssh:
command use for remote login

example:
1)ssh root@192.168.2.X.X

where..
-root is username
-192.168.2.X.X is the ip of remote pc
_________________________________________________________________________________

grep:
print lines matching a pattern.

example:
grep "this" file   [if any space b\w file name like.."hello world" then type hello\ world]
grep -i "This" file [-i: ignore case sensitive]

Grep String from number of files
tail -1000f logfile.log.* |grep -i "NullPointerException"

Search String in files of Particular Directory.
grep -rnw 'directory' -e "string"

Search Multiple words from files
grep -w  "MemTotal\|MemFree\|Buffers\|Cached\|SwapCached" /proc/meminfo
_________________________________________________________________________________

tail;
gives output the last part of files.

example:
tail filename

-f : displays last 10 lines then update the file as new lines are being added.
-tail filename -n 10 : displays last 10 lines of the file.
-tail -f access.log | grep 192.168.X.X :

example:
tail -fn 100 filename
-tail filename 100 : displays last 10 lines of the file.
100 is count of line number you want to see.
_________________________________________________________________________________

Install Memcached

yum install memcached

--> if found error then need to install dependencies:
yum install libevent libevent-devel

service memcached start
_________________________________________________________________________________

Find current processes and Kill them

ps:
report a snapshot of the current process

example:
ps e
ps -ef
ps ux --> To display all processes owned by the current user

To terminate particular process find PID and follow the command..

kill -9 PID

-->The '-9' will ensure "execution".
_________________________________________________________________________________

 svn in centos

yum install mod_dav_svn subversion

To checkout the project file from server
--> svn checkout source/path destination/path
--> svn checkout source/path destination/path --username [username]

To get latest update from the server..
svn up

To set local project files to server
svn commit -m "type your msg" /path/filename1,/path/filename2,...,/path/filenameN

To check differance between local and server files..
svn diff -r HEAD filename

To check number of files location which different from server
svn st

To Recursively clean up the working local copy
svn cleanup

To Delete from svn
svn delete -m "Delete Handoff" path/to/location( Ex : http://192.168.X.X:9880/HandOff/trunk/)(-m for message)

To Add new file
svn add file(Ex svn add ReleaseNote)

For first check in
svn import -m "First Release" http://192.168.X.X:9880/HandOff/branches

For History check
svn log -v
_________________________________________________________________________________ 

command for ibator

java -jar ibator.jar -configfile ibatorConfig.xml
_________________________________________________________________________________

Change IP or Gateway

vim /etc/sysconfig/network-scripts/ifcfg-eth0 (Change Whatever you need) then..restart network
/etc/init.d/network restart

change nameserver
vim /etc/resolv.conf

Firewall On/Off

Turn On --> service iptables start
Turn OFF --> service iptables stop
_________________________________________________________________________________

Install vimdiff..

yum install vim-en*
_______________________________________________________________________________

Merge two file line to line

--> paste filename1 filename2 > newFileName

and make new string with using column...

-->  cat filename | while read code columnName1; do echo "if(v==$columnName2){$('#_country').prop('selectedIndex',$columnName1);}"; done
_________________________________________________________________________________

Create Alias / Custom Command

vim /etc/bashrc   --> add your command at the end of the file with prefix 'alias' keyword.

alias {alias_name}='{value}'

Example:
alias db82='mysql -h192.168.X.X -ulocaluser -p'

reload file
. /etc/bashrc

For UBUNTU:

- vim ~/.bashrc
- Add alias at the end of the file
- for reload 'source ~/.bashrc'
_________________________________________________________________________________

MYSQL

check mysql status: /etc/init.d/mysqld status

for database dump or backup:
--> mysqldump -hHostname -uUsername -pPassword database_Name > filename.sql
mysqldump -h192.168.X.X -ulocaluser -plocaluser --databases --ignore-table billing.epr_349_20120422110438
                                  --ignore-table billing.epr_349_20120422110439
                                  --ignore-table billing.epr_349_20120622110639
                                  --ignore-table billing.epr_349_20120722110714
                            --ignore-table billing.epr_742_20120316030349 billing > billing.sql
--> Now filename.sql ready for dump database in any host..

for restore database:
-->mysql -hHostname -uUsername -pPassword database_Name < filename.sql

for backup particular data:
--> mysqldump -ulocaluser -plocaluser -hlocalhost --no-create-info broadcast bccall_details --where="id<3" > m.sql

Alter table:
--> alter table bccall_details modify column created_at datetime Default '0000-00-00 00:00:00'


For foreign key truncate Exception..

set foreign_key_checks=0;
--it ignore foreign key constraints temporarily.


create query for employee

 CREATE TABLE `employee` (
  `employee_id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(50) DEFAULT NULL,
  `lastname` varchar(50) DEFAULT NULL,
  `dob` datetime DEFAULT NULL,
  `created_date` datetime DEFAULT NULL,
  `updated_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`employee_id`)
) ENGINE=MyISAM

for foreign Key..

create table xyz('id' int(11) NOT NUll AUTO INCREMENT,`employee_id` int(11) NOT NULL,'name' varchar(50) DEFAULT NULL,
         FOREIGN KEY('employee_id') REFERENCES employee (employee_id));

for DISTINCT column name

select DISTINCT {column_name} from {table_name};
_________________________________________________________________________________

MySQL tab completion

vim /etc/my.cnf

then find..
[mysql]
no-auto-rehash

and replace it with...
[mysql]
auto-rehash
_________________________________________________________________________________

find . -name "*.java" -print -exec grep "conference_user" -inr {} \;
_________________________________________________________________________________

Download and Install Java

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u72-b14/jdk-7u72-linux-x64.tar.gz"

tar xzf jdk-7u72-linux-x64.tar.gz

View / Update Alternatives:
alternatives --config java

Set Alternatives:
alternatives --install /usr/bin/java java /usr/local/jdk1.6.0_45/bin/java 1


if you want upgrade already installed java
then update jdk location in /etc/profile.d/java.sh
_________________________________________________________________________________

To change/set user permission for Directory

sudo chown -R username:group directory

Example:
sudo chown -R root:root /home/Workspace
________________________________________________________________________________

Install RPM file

rpm -Uvh {filename}

However, if you want to install the package anyway, you can use the --replacepkgs option

rpm -ivh --replacepkgs {filename}
_________________________________________________________________________________

Check Harddrive status

$ ls -l /usr/bin/vim
$ ls -lh /usr/bin/vim
$ stat -x /usr/bin/vim

df -h

Check memory occupied by each folder

du -sh * | more

example:
du -sh Folder       

Check file size in MB:
du -h {file_name}

_________________________________________________________________________________
Count File

find . -type d -print0 | while read -d '' -r dir; do
    files=("$dir"/*)
    printf "%5d files in directory %s\n" "${#files[@]}" "$dir"
done
_________________________________________________________________________________

Store HOST IP With Name

To Change host name of the person
vim /etc/hosts
enter ip address with tailing name over there
192.168.X.X   localhost localhost.localdomain vishal
_________________________________________________________________________________

copy and compress in one command

tar cf - logfile.log | gzip -c -> backuplogfile.log.tar.gz
_________________________________________________________________________________

To view system file configuration
ulimit -a

Result:
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 30784
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 100000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 70000
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Upgrade open files limit
ulimit -n {amount}

NOTE: this settings available only for current session.

For permenant changes

vim /etc/security/limits.conf

add this at the end of the file
*       soft    nofile  100000
*       hard    nofile  100000
*       soft    nproc   65536
*       hard    nproc   65536
 _________________________________________________________________________________

Split one large file into multiple files

Syntax:
split -b {segment-size} {FILENAME} {segment-prefix}

Example:
split -b 10240k rtbms.log rtbms
_________________________________________________________________________________

Enable Incoming PING log

iptables -I INPUT -j LOG
_________________________________________________________________________________

Check memory status by every second:

free -m -s 1 (you can update last parameter for delay in time like 5 means after 5 seconds)
OR
watch -n 1 free -m
OR
watch -n 1 cat /proc/meminfo


Clear cache and buffer:

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
(I used this command to clear the cache which occupied by mysql result set called as Query Cache,
Note that the 'Query Cache' in MYSQL is not a general page/blocks cache. it's cache of the results of queries which not always useful )
_________________________________________________________________________________
 

No comments:

Post a Comment