Sunday, 5 November 2017

Open Source TIPs.

==> cat file1
==> tac file1 -> This will cat the file in reverse order.

==> Tips to use previous commands arguments...
      # mkdir /tmp/xyz  --> create the a directory on /tmp/xyz
      # cd !$           --> will redirect the directory directly.
==> screen--
      screen -S name
      screen -dr name
      screen -list
==> find --
      find / -xdev -type f -size +1G -exec ls -lh {} \;     --> find a file learger than 1GB.

==> echo -e "password\npassword" | passwd testuser          --> will set the password for test user.

==> change the history size -- Add the below in ~/.bashrc, Ex- if you want to change the file size into 40k
      HISTSIZE=40000
      HISTFILESIZE=40000
==> Display the history command with date and time in Linux.. using below..
    Define an environment varibale as below..
      #HISTTIMEFORMAT="%d/%m/%y %T"
    or
      echo 'export HISTTIMEFORMAT="%d/%m/%y %T"' >> ~/.bash_profile
    Here - %d is the day, %m is the month, %y is the year, %T is the time.
==> Erase duplicate entry on history.
      Define an environment varibale as below..
        #export HISTCONTROL=erasedups
==> View history without line numbers
      # history | cut -c 8-
      or
      # history | awk {'print $2'}

==> Record the command session--(using script command)
      # script file1.txt
      Execute your commands..and type exit once you done with the commands and want to save those.\
      # exit
      #cat file1.txt
==> make file immutable -
      touch file1
      chattr +i file1  -> (see the attribute using lsattr)

==> Process running related on Linux..
      The Kernel creates directory to each process on /proc with the pid.
==> snooppy is tool/app in linux can be used to track the executed commands.

==> Copy all files excluding certain files..
      #shopt -s extglob
      #cp !(*.mp3|*.txt) /tmp/
      # The above command will only copy the files extension with mp3 or txt
==> Copy a file to multiple directories..
      # echo /home/user1 /home/user2 | xargs -n 1 cp -v /tmp/test.txt
==> To stop all the running containers using docker.
      # docker stop $(docker ps -q)
==> curl command tips
      # curl -k <url>   --> will ignore the ssl certificate.
      # curl -u username:password <url>   -->(if a website asks a password)
      # curl -L <url>   --> will automatically redirect to new url.
      # curl -O <url>   --> will save the file in same name.
      # curl -o <url>  <file-name>  --> if small o is there it is require to give the file name.
==> Get your IP address
      # myip=$(curl --silent ipecho.net/plain)
      # echo $myip   --> will show your IP
==> Tips on how to use previous commands
      # up arrow & enter     --> will execute the previous command.
      # Type '!!' & enter    --> will execute the previous command.
      # Type '!-1' & enter   --> will execute the previous command.
      # Ctrl + P  (Equivalent to up arrow)  --> will execute the previous command.
      # Ctrl + n            --> Equivalent to down arrow
      # !mo:p               --> will print the previous command starteing with "mo"
==> Viewing files without comments and blank lines.
      # egrep -v "^#|^$" <config file name>
==> Terminal Tips..
      # Ctrl + w  --> Delete one word before cursor.
      # Ctrl + u  --> Delete all left side
      # Ctrl + K  --> Delete all right side.
      # Ctrl + y  --> undo the above
      # Ctrl + a  --> Moves to beginning of the line.
      # Ctrl + e  --> Moves to end of the line.
      # Ctrl + t  --> Swaps the character with left one.

No comments:

Prasanta Kumar Behera. Mob- 8147470101