Skip to main content

SOME USEFUL LINUX COMMANDS

1. Tar command
=============

Create a tar archive
--------------------

root@cpanel [/home]# tar cvzf /root/avid.tar.gz avid/

avid/ is the directory name I want to archive.
avid.tar.gz is the file name that will be assigned for the archive. /root/avid.tar.gz  is the path where the tar file will be stored in to,


Extract a particular file from tar archive to a required location
--------------------------------------------------------------

root@cpanel [/home]#  tar xvzf avid.tar.gz -C /root/ avid/public_html/wp-config.php
avid/public_html/wp-config.php

In the above example the file  avid/public_html/wp-config.php from the tar file avid.tar.gz is extracted to the location /root/.


View the content inside an existing Tar archive
--------------------------------------------------


root@cpanel [/home/avid/public_html]# tar tvzf content.tar.gz
drwxr-xr-x avid/avid         0 2014-04-16 23:36 wp-content/
drwxr-xr-x avid/avid         0 2014-04-16 23:36 wp-content/plugins/
drwxr-xr-x avid/avid         0 2014-04-16 23:36 wp-content/plugins/akismet/
drwxr-xr-x avid/avid         0 2014-04-16 23:36 wp-content/plugins/akismet/views/


========================================================================

2. grep command usage


Case in-sensitive search
-------------------------
root@cpanel [/home/avid/public_html]# grep -i noBody test123.txt
 nobody
 NOBODY
 nobody
 noBODy



Search and print 3 lines after it
-------------------------------

root@cpanel [/home/avid/public_html]# grep -A 3 dummy test123.txt
 dummy
 pastha
 mytestdo
 shopcpan

Serach and print along with the 3 lines before the text
---------------------------------------------------------
root@cpanel [/home/avid/public_html]# grep -B 3 dummy test123.txt
 avid
 avid
 training
 dummy

Serach and print along with the 3 lines around the match
--------------------------------------------------------
root@cpanel [/home/avid/public_html]# grep -C 3 dummy test123.txt
 avid
 avid
 training
 dummy
 pastha
 mytestdo
 shopcpan


Search for a given string in all files recursively
-------------------------------------------------

root@cpanel [/home/avid/public_html]# grep -r dummy *
test123.txt: dummy
test321.txt: dummy


Difference using grep
---------------------------
 sdiff  test321.txt test123.txt
 hgtestdo                                                        hgtestdo
                                                              >  hgtestdo
                                                              >  HGTESTDO
                                                              >  avid
 avid                                                            avid
 training                                                        training
 dummy                                                           dummy
 pastha                                                          pastha
 mytestdo                                                        mytestdo
                                                              >  shopcpan
                                                              >  hgdomain
                                                              >  hgdomain
                                                              >  hgdomain
                                                              >  nobody
                                                              >  NOBODY
                                                              >  nobody
                                                              >  noBODy



root@cpanel [/home/avid/public_html]# grep -Fxvf test321.txt test123.txt
 HGTESTDO
 shopcpan
 hgdomain
 hgdomain
 hgdomain
 nobody
 NOBODY
 nobody
 noBODy

To get the full match using w
------------------------------------
root@cpanel [/home/avid/public_html]# grep  "body" test123.txt
 nobody
body
 nobody
root@cpanel [/home/avid/public_html]# grep -w "body" test123.txt
body


Invert the match using -v
-------------------------------

root@cpanel [/home/avid/public_html]# grep -iv "body" test123.txt
 hgtestdo
 hgtestdo
 HGTESTDO
 avid
 avid
 training
 dummy
 pastha
 mytestdo
 shopcpan
 hgdomain
 hgdomain

 hgdomain

root@cpanel [/home/avid/public_html]# grep -wv "body" test123.txt
 hgtestdo
 hgtestdo
 HGTESTDO
 avid
 avid
 training
 dummy
 pastha
 mytestdo
 shopcpan
 hgdomain
 hgdomain
 hgdomain
 nobody
NOBODY
 nobody
 noBODy







Comments

Popular posts from this blog

WiFI connection

    root@kali:~# iw dev root@kali:~# ip link set wlan0 up root@kali:~# iw wlan0 scan root@kali:~# wpa_passphrase blackMOREOps >> /etc/wpa_supplicant.conf root@kali:~# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf root@kali:~# iw wlan0 link root@kali:~# dhclient wlan0 root@kali:~# ping 8.8.8.8 (Where wlan0 is wifi adapter and blackMOREOps is SSID) (Add Routing manually) root@kali:~# ip route add default via 10.0.0.138 dev wlan0    

Modsecurity block rule for XMLRPC and wp-login attack

SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000134  <Locationmatch "/wp-login.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000135,msg:'ip address blocked for 5 minutes, more than 10 login attempts in 3 minutes.'"  SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.bf_counter=0,id:5000136"  SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,setvar:ip.bf_counter=+1,deprecatevar:ip.bf_counter=1/180,id:5000137"  SecRule ip:bf_counter "@gt 10" "t:none,setvar:user.bf_block=1,expirevar:user.bf_block=300,setvar:ip.bf_counter=0"  </Locationmatch>  SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000234  <Locationmatch "/xmlrpc.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000235,msg:'ip address blocked for 5 m...

Apache tuning documentation

Apache bench marking ======================= Things or checklist to be considered before the test     CPU: avoid power-saving mode. cpufreq-set -g performance.     File descriptors: raise the limit to (at least) the number of concurrent connections you wish to handle, using ulimit -n in your shell, or setrlimit(RLIMIT_NOFILE) in your server. Beware, some systems forbid you to raise the limit, you might need to investigate a bit to find how to unlock it.     Disable the logs of your server (you do not want to lose time logging thousands of requests instead of answering them).     Raise /proc/sys/net/somaxconn to the number of concurrent connections you want to handle. To understand why this is necessary, read the technical report or the excellent paper Measuring the Capacity of a Web Server (Banga and Druschel, Usenix 97). More on the fascinating topic of the accept() queue can be found in accept()able Strategies for Im...