CyberKeeda In Social Media
Showing posts with label Linux Utility. Show all posts
Showing posts with label Linux Utility. Show all posts

Linux : Create dummy file of any size for test purpose using fallocate

Requirement :
Create dummy/fake file of desired size using Linux terminal
    There might be some test requirement to mimic the prod setup, in my case I have to write a script to validate files before downloading, instead of making request to prod site I just created a local setup and placed similar dummy files to replicate the prod environment.
Let's know the one linux one liner using tool fallocate to create dummy file of desired size.

  • Fallocate is the Linux terminal utility.

One Liner
# fallocate -l <size_of_file> <desired_name_of_file>

  • Fallocate is the Linux terminal utility.

Syntax Template

# fallocate -l 15M myfile.img

  • <size_of_file >
    • in GB and MB : M for MB and G for GB
    • example : 15M for 15 MB and 5G for 5GB
  • <desired_name_of_file> 
    • It can be anything with our without extension : myfile.tar or myfile.img or myfile or anything

Using Linux for loop and Seq to generate a series of file.
Example : 
  • Below one liner can be used to generate 100 files of 15mb each with suffix changes as file count number.

Syntax Template

# for val in `seq 100`; do fallocate -l 15M demo060621000$val.tar; done;

Output : File starts with name 
demo0606210001.tar and ends with demo0606210099.tar

Syntax Output

# ls -ltr

-rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210001.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210002.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210003.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210004.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210005.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210006.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210007.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210008.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo0606210009.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100010.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100011.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100012.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100013.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100014.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100015.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100016.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100017.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100018.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100019.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100020.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100021.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100022.tar -rw-r--r-- 1 root root 15728640 Jun 6 23:25 demo06062100023.tar

Read more ...

Linux Find Commands with examples.



Linux Find Commands Cheat sheet.

Find Files Using Name in Current Directory.
Lets assume we are currently under our /home directory.
  # find . -name myfile.txt
     /home/myfile.txt


Find Files Using Name and Ignoring Case ( Ignore upper & lower case )


  # find . -iname myfile.txt
     /home/myfile.txt
     /home/MYFILE.txt

Find Files under any specified Directory.


  # find . -iname myfile.txt

     /home/myfile.txt

     /home/MYFILE.txt


Find Files Using Name and Ignoring Case ( Ignore upper & lower case )

      #  find . -iname myfile.txt
    
         /home/myfile.txt
    
         /home/MYFILE.txt


    Find files  based on extention ( .php .txt .csv .sh )


      #  find . -type f -name "*.php"
    
         /home/myfile.php
    
         /home/index.php
    
    
    
     #  find . -type f -name "*.csv"
    
         /home/abc.csv
    
         /home/newfile.csv
    
    
    
     #  find . -type f -name "*.sh"
    
         /home/myscript.sh
    
         /home/new.sh
    
    
    
    
    


    Find Directories 


      #  find . -type d -name  mydirectory
    
    
        /home/mydirectory


    Find files with 777 Permission


      #  find /home   -type f -perm 0777 -print
    
          /home/abc.txt

    Find files without  755 Permission


       #  find /home  -type f ! -perm 755
    
           /home/myfile.txt
    
           /home/MYFILE.txt


    Find  all files Based on User
    We will find all files placed within /home directory having ownership of user jackuna
      #  find /home -user jackuna
    
          /home/myfile.txt


    Find  all files based on specific Group
    We will find all files placed within /home directory having group of user sysadmins
      #  find /home -group sysadmins
    
          /home/admin.sh


    Find  specific file type for a user
    We will find all files with .txt extension for user jackuna under /home directory
      #  find /home -user jackuna -iname "*.txt"
    
         /home/myfile.txt


    Find all empty files ( no content )
    We will find all empty/blank files  under /tmp directory.
       #  find /tmp -type f -empty


    Find all empty directories ( no content )
    We will find all empty/blank directories  under /tmp directory.
       #  find /tmp -type d -empty


    Find all hidden files
    We will find all hidden files under /tmp directory.
       #  find /tmp -type f -name ".*"


    Find  and remove a single file
    We will find file named as  myfile.txt  under /home directory and remove it permanently 
      #  find /home  -type f -name "myfile.txt" -exec rm -f {} \;


    Find  and remove a multi[ple file
    We will find all files with .sh and .mp3 extension under /home and delete it permanently 
      #  find /home -type f -name "*.sh" -exec rm -f {} \;
     
      #  find  /home  -type f -name "*.mp3" -exec rm -f {} \;


    Find files that are older then n number of days 
    Below find command will find all files that are older then 20 days under /tmp directory
      #  find  /tmp -mtime +20 -print
    


    Find files that are accessed then n number of days before
    Below find command will find all files that are accessed  20 days before under /tmp directory
      #  find  /tmp -atime +20 -print


    Find files that are changed within last hour
    Below find command will find all files that are changed within last 60 min under /tmp directory
      #  find /tmp -cmin -60


    Find modified files in last 60 minutes
    Below find command will find all files that are modified within last 60 min under /tmp directory
      #  find /tmp -mmin -60


    Find accessed files in last 60 minutes
    Below find command will find all files that are accessed within last 60 min under /tmp directory
      #  find /tmp -amin -60

    
    
    Read more ...

    SSH from your favourite browser using Shellinabox




    Shellinabox is perfect tool if you have any of the requirement.

    Missing Putty or SSH agent on your desktop  ?
    Looking for Client less agent to SSH ?
    Want to SSH your Linux server or desktop from mobile.

    So lets move ahead and just follow the steps to install Shellinabox.

    Video tutorial, for video lovers.


    ShellinaBox Installation on  CentOS7

    Introduction [ Shell In A Box ]

    Shell In A Box implements a web server that can export arbitrary command line tools to a web based terminal emulator. This emulator is accessible to any JavaScript and CSS enabled web browser and does not require any additional browser plugins.

    Official repository link

    More info on official git page :  https://github.com/shellinabox/shellinabox

    Installation.

    Intsall EPEL Repo.


    [root@cyberkeeda ~]# yum install epel-release 


    Install shellinabox package


    [root@cyberkeeda ~]# yum install shellinabox


    Configuration.

    Shellinabox configuration file  :    /etc/sysconfig/shellinaboxd


     Lets have a look on the file and allow and modify the important lines

    [root@cyberkeeda ~]# vim /etc/sysconfig/shellinaboxd



    # Shell in a box daemon configuration
    # For details see shellinaboxd man page

    # Basic options
    USER=shellinabox
    GROUP=shellinabox
    CERTDIR=/var/lib/shellinabox
    PORT=4200
    OPTS="--disable-ssl-menu -s /:LOGIN"
    OPTS="-t -s /:SSH:192.168.0.181"

    PORT

    PORT=4200

    Chnage PORT to some other to avoid conflict between sytem level ports 

    I will be changing it to 6162 

    SSH HOST

    OPTS="-t -s /:SSH:192.168.0.101"

    Chnage IP or Hostname to your default login host, by default shellinabox will ask to login into it, then later you can ssh and jump into n number of servers.


    My final config file would look as

    # Shell in a box daemon configuration
    # For details see shellinaboxd man page

    # Basic options
    USER=shellinabox
    GROUP=shellinabox
    CERTDIR=/var/lib/shellinabox
    PORT=6162
    OPTS="--disable-ssl-menu -s /:LOGIN"
    OPTS="-t -s /:SSH:192.168.0.101"


    Configuration Done..

    Important : 

    STOP Firewalld iptables and disable selinux 

    #    Service firewalld stop
    #    Service iptables stop

    Disable SELINUX : change status of selinux to disabled

    Finally Restart the shellinaboxd daemon.



    [root@cyberkeeda ~]# service shellinaboxd start

    Read more ...

    How to add Hosts and Host groups into Ansible Server



    Ansible Initial Host Configuration.

    Ansible knows the hosts and hostgroups from a host file by default it is located as /etc/ansible/hosts.

    Read more ...

    DPKG Cheat Sheet


    DPKG [ dpkg ] is a traditional yet powerful CLI tool for the debian based Linux Distribution.
    It is used to install/manage individual packages.

    Here are some useful dpkg commands which you can use as a cheat code.




    SyntaxDescriptionExample
    dpkg -i {.deb package}Install the packagedpkg -i zip_virtualbox-5.amd64.deb
    dpkg -i {.deb package}Upgrade package if it is installed else install a fresh copy of packagedpkg -i virtualbox-5.amd64.deb
    dpkg -R {Directory-name}Install all packages recursively from directorydpkg -R /tmp/downloads
    dpkg -r {package}Remove/Delete an installed package except configuration filesdpkg -r zip
    dpkg -P {package}Remove/Delete everything including configuration filesdpkg -P apache-perl
    dpkg -lList all installed packages, along with package version and short descriptiondpkg -l
    dokg -l | less
    dpkg -l '*apache*'
    dpkg -l | grep -i 'sudo'
    dpkg -l {package}List individual installed packages, along with package version and short descriptiondpkg -l apache-perl
    dpkg -L {package}Find out files are provided by the installed package i.e. list where files were installeddpkg -L apache-perl
    dpkg -L perl
    dpkg -c {.Deb package}List files provided (or owned) by the package i.e. List all files inside debian .deb package file, very useful to find where files would be installeddpkg -c virtualbox-5.amd64.deb
    dpkg -S {/path/to/file}Find what package owns the file i.e. find out what package does file belongdpkg -S /bin/netstat
    dpkg -S /sbin/ippool
    dpkg -p {package}Display details about package package group, version, maintainer, Architecture, display depends packages, description etcdpkg -p lsof
    dpkg -s {package} | grep StatusFind out if Debian package is installed or not (status)dpkg -s lsof | grep Status
    Read more ...
    Designed By Jackuna