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

SystemD commands

[root@centos7 ~]# systemctl -t target UNIT                   LOAD   ACTIVE SUB    DESCRIPTION basic.target           loaded active active Basic System cryptsetup.target      loaded active active Encrypted Volumes getty.target           loaded active active Login Prompts graphical.target       loaded active active Graphical Interface local-fs-pre.target    loaded active active Local File Systems (Pre) local-fs.target        loaded active active Local File Systems multi-user.target      loaded active active Multi-User System network-online.target  loaded active active Network is Online network.target         loaded active active Network nfs-client.target      loaded active active NFS client services nss-user-lookup.target loaded active active User and Gr...

How to tweak linux server harddisk using hdparm

hdparm switches explained http://manpages.ubuntu.com/manpages/intrepid/man8/hdparm.8.html   First of all you have to install hdparm in linux. apt-get install hdparm #hdparm /dev/sda /dev/sda: readonly = 0 (off) readahead = 120 (on) geometry = 8850/255/63, sectors = 142182912, start = 0 Hard disk Performance Information # hdparm -tT /dev/hda /dev/hdd: Timing cached reads: 496 MB in 2.00 seconds = 247.42 MB/sec Timing buffered disk reads: 60 MB in 3.03 seconds = 19.81 MB/sec Hard drive set to low, slow settings # hdparm -cuda /dev/hda /dev/hda: IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 0 (off) readahead = 256 (on) Use below tweaks to increase disk read write performance. For sda drive ~]# hdparm -a 2048 /dev/sda /dev/sda: setting fs readahead to 2048 readahead = 2048 (on) For sdb drive [root@439298a ~]# hdparm -a 2048 /dev/sdb /dev/sdb: setting fs readahead to 2048 readahead = 2048 (on) ]# echo “anticipatory” >...

RAID

Check the Raid installed lspci | grep RAID     Software Raid ============== Linux Support For Software RAID Currently, Linux supports the following RAID levels (quoting from the man page): LINEAR RAID0 (striping) RAID1 (mirroring) RAID4 RAID5 RAID6 RAID10 MULTIPATH, and FAULTY. MULTIPATH is not a Software RAID mechanism, but does involve multiple devices: each device is a path to one common physical storage device. FAULTY is also not true RAID, and it only involves one device. It provides a layer over a true device that can be used to inject faults. Install mdadm Type the following command under RHEL / CentOS / Fedora Linux: # yum install mdadm Type the following command under Debian / Ubuntu Linux: # apt-get update && apt-get install mdadm How Do I Create RAID1 Using mdadm? Type the following command to create RAID1 using /dev/sdc1 and /dev/sdd1 (20GB size each). First run fdisk on /dev/sdc and /dev/sdd with " Softwa...