mrinalraj

Social and Technical Blogger

grep "unix" filename.txt : prints only line containing unix also higlights the “unix ” wherever it is present. unix is great os. unix is opensource. unix is free os. unix linux which one you choose. unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

grep -n "unix" filename.txt : prints only line containing unix and also gives the no. line. 1:unix is great os. unix is opensource. unix is free os. 3:unix linux which one you choose. 4:unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

$grep "[2-3][0-9]" emp : Check for the string from 20 to 39 TCS101 Anu Engineer Manufacturing 30 35000 INFY02 Sona Developer Development 25 29000 TCS102 Raki Accountant Admin 31 32000 INFY03 Arun Engineer Manufacturing 28 34000 INFY04 Amit Accountant Admin 24 27000 TCS103 Nanda Engineer Manufacturing 29 37000 TCS104 Swathi Developer Development 28 29000

$ grep -v "[2-3][0-9]" emp :Invert the sense of matching, to select non-matching lines.

$ grep -n "[2-3][0-9]" emp : Displays in ordered list.(i.e. with line number) with string matching from 20 to 39. 1:TCS101 Anu Engineer Manufacturing 30 35000 2:INFY02 Sona Developer Development 25 29000 3:TCS102 Raki Accountant Admin 31 32000 4:INFY03 Arun Engineer Manufacturing 28 34000 5:INFY04 Amit Accountant Admin 24 27000 6:TCS103 Nanda Engineer Manufacturing 29 37000 7:TCS104 Swathi Developer Development 28 29000

$ grep -n "TCS[0-3][0-9][0-9]" emp : Displays only TCS employee details with line number present in the original file ranging from TCS000 to TCS399. 1:TCS101 Anu Engineer Manufacturing 30 35000 3:TCS102 Raki Accountant Admin 31 32000 6:TCS103 Nanda Engineer Manufacturing 29 37000 7:TCS104 Swathi Developer Development 28 29000

*NOTE : emp and student are the file names.*

unix is great os. unix is opensource. unix is free os. learn operating system. unix linux which one you choose. unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

sed -e 's/unix/UnIx/g' filename.txt : Searches for unix and replaces it with UnIx everywhere. Here g stands for making changes globally. UnIx is great os. UnIx is opensource. UnIx is free os. learn operating system. UnIx linux which one you choose. UnIx is easy to learn.UnIx is a multiuser os.Learn UnIx .UnIx is a powerful. linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

sed 's/unix/UnIx/1g' filename.txt : Replaces with Unix globally from the first occurrence in a line. UnIx is great os. UnIx is opensource. UnIx is free os. learn operating system. UnIx linux which one you choose. UnIx is easy to learn.UnIx is a multiuser os.Learn UnIx .UnIx is a powerful. linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

sed '3,5s/unix/UnIx/' filename.txt : It will replace the unix with UnIx from 3rd line till 5th line if present. unix is great os. unix is opensource. unix is free os. learn operating system. UnIx linux which one you choose. UnIx is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

sed '1,2s/unix/UnIx/' filename.txt: It will replace the unix with UnIx from 1st line and 2nd line. UnIx is great os. unix is opensource. unix is free os. learn operating system. unix linux which one you choose. unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

sed '1,$s/unix/UnIx/' filename.txt : It will replace the unix with UnIx from 1st line till the last line. Here “$” indicates end line. UnIx is great os. unix is opensource. unix is free os. learn operating system. UnIx linux which one you choose. UnIx is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

sed '/unix/ a "Add a new line"' filename.txt : It adds “Add a new line” at the end of the line in which unix occurred. unix is great os. unix is opensource. unix is free os. “Add a new line” learn operating system. unix linux which one you choose. “Add a new line” unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. “Add a new line” linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

sed '/unix/ i "Add a new line"' filename.txt : i means insert the “Add new line” before the occurence of unix “Add a new line” unix is great os. unix is opensource. unix is free os. learn operating system. “Add a new line” unix linux which one you choose. “Add a new line” unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

sed '/unix/ c "Add a new line"' filename.txt : replace the line containing unix with the content “Add new line” “Add a new line” learn operating system. “Add a new line” “Add a new line”

In Python there is no need to import any external libraries for file handling as it comes with an inbuilt library There are 3 main operations associated with the file. 1. Creating/Opening a file. 2. Writing into the file/ Reading from the file. 3. Closing a file.


Step 1: Creating Opening a file :

Syntax : filePtr = open("your_file_name.txt", "mode") Following are the modes supported in python: 1. “w”, “r”, “a”: To open files in write mode, read mode and append mode respectively. ex: filePtr = open("my_file.txt", "w") It will create a new file if the given file name doesn't exist else it will overwrite the contents of the given file.

filePtr = open("my_file.txt", "r") It will open a file only if it exists in the reading mode. i.e. we cannot edit the contents of the file.

filePtr = open("my_file.txt" , "a") It will append the contents of the file if already exists else it will create a new one.

  1. “w+”, “r+”, “a+” : To open a file in write and read mode, read and write mode, and append and read mode.

filePtr = open("my_file.txt", "w+") It will create a new file if the given file name doesn't exist else it will overwrite the contents of the given file. In this mode, we can also read the content of the file at the same time.

filePtr = open("my_file.txt", "r+") It will open a file only if it exists in the reading mode also we can edit the contents of the file unlike in “r” mode. ** Note: +r differs from +w mode as in +r mode it doesn't delete the content also it doesn't create a new file if doesn't exist.**

filePtr = open("my_file.txt" , "a+") It will allow simultaneous read and append operation on the file.

  1. “wb”, “rb”, “ab”: To open files in write, read and append in binary mode respectively. ex: filePtr = open("my_file.txt", "wb") It will create a new file if the given file name doesn't exist else it will overwrite the contents of the given file.

filePtr = open("my_file.txt", "rb") It will open a file only if it exists in the reading mode. i.e. we cannot edit the contents of the file.

filePtr = open("my_file.txt" , "ab") It will append the contents of the file if already exists else it will create a new one.

  1. “wb+”, “rb+”, “ab+” : To open a file in write and read, **read and write **, and append and read in binary mode.

filePtr = open("my_file.txt", "wb+") It will create a new file if the given file name doesn't exist else it will overwrite the contents of the given file. In this mode, we can also read the content of the file at the same time.

filePtr = open("my_file.txt", "rb+") It will open a file only if it exists in the reading mode also we can edit the contents of the file unlike in “r” mode.

filePtr = open("my_file.txt" , "ab+") It will allow simultaneous read and append operation on the file.


Step 2: Writing in a file/ Reading from the file:

We can write in a file using write() function Syntax : filePtr.write("THIS is a file CONTENT")

We can read from the file using read() and readline() function ex: content = filePtr.read(): This return the entire content of the file. content = filePtr.readline(): This returns only the content of one line in a file.


Step 3: Closing a file

Closing a file is very important as if it exceeds the top limit it can lead to the crashing of the program. So it is advisable to close a file. Syntax : filePtr.close()

Today I tried to install UBUNTU 18.04 LTS into my friend's laptop. I will say it was quite a mixed experience. Below are the following steps I did for installing:

Step 1 : Partition

Click on windows icon type “Create and format Disc”. There you will see the following : Create and Format Disc

  • Right-click on C Drive.
  • Go to shrink Volume.
  • It is preferred to choose 30GB to 100Gb for UBUNTU OS. Here we will choose 60GB .i.e . 61440MB You will now see some free space being allocated. Note that during partition the unallocated free space must be at the end of all drives refer to this post on how to move unallocated spaces to the right.

Step 2: Creating a USB flash drive

Meanwhile, download the ISO file for UBUNTU 18.04 (LTS bionic). Also, download Etcher for creating flash USB. Give the path for downloaded iso file. Etcher image

Step 3 : Restart

Go to the BIOS setup. For my dell Vostro laptop. I will press F12 just as the dell image logo is visible. BIOS setup * Go to your USB drive * Select “Open UBUNTU without installing”

Click on the “Install UBUNTU 18.04.1 LTS” and it will ask for the following configuration.

  1. Select Normal Installation. Uncheck download updates while installing Ubuntu. Normal Installation Now there are two steps 1. Easy Step 2. Creating our configuration

    Easy Step

  2. Select “Install Ubuntu alongside Windows Boot Manager” and goto Step 8 Windows Boot Manager

    Our Configuration for home, root, and swap

  3. Select “Something ElseSometing Else Find where there is free space you have created. Free Space

  4. Select and click on the “+” icon and we will allocate the space for “swap” and “home” and “root” directory.

  5. Select logical memory and / signifies root, allocate 20 GB for it.

  6. Select swap memory for 4GB (half the RAM size is preferred, for my Laptop of 8GB, it's 4096 MB).

  7. Now give the rest of the space for the home.

  8. Now select install now. Install now and Continue Continue Click on continue. And wait for the installation to finish. Yay! we are all done.

Learning Unix commands are very essential as it helps you to navigate easily in your directories and files. Today we will learn some basics Unix commands which is easy for any beginners to begin with. Also you will get to know some bonus tips in the end.

Let's begin with creating new file.

cat > filename : creates a new file, if files already exists then overwrites it.

cat >> filename: appends the content in the already existing filename, else if not found then creates a new one.

Now to see if file is created or not.

ls -li : long list the files present in that directory with the inode no.

Now if you want to list files which is in some other directory or same working directory then there comes the concept of Relative addressing and Absolute addressing.

Relative addressing and absolute addressing


Relative addressing: here we can move to the directory which is under that directory.

username@hostname directoryname$ cd directory_name

Absolute Addressing: here we specify address from the root username@hostname directoryname$ cd /home/username/directory_name

Lets play with calendar commands.

cal: prints the calendar of current month

cal mm yyyy : will print calendar of that year of that month.

cal year : will print the calendar of that year

In Unix, you can do calculations as well.

bc: It will open binary calculator. Here you can perform calculations.


ln filename linkname : it creates a new link pointing to the existing file “file_name”

where cp filename newfilename : creates a new file with “newfilename” and then copies the content of the filename into it.

Note ls -li will confirm that in the copy command there will be different inode number while link command creates a new link to file as they have the same inode no.

mkdir is used to make a directory and rmdir is to remove a directory

rm file_name: is used to remove a file_name

Till now we learned some basic tips. Time for some Bonus Tips.

passwd : this command is used to change the current password

sudo passwd -l username : to lock that username from the system

sudo passwd -u username: to unlock that username from the system

sudo passwd -e username: to expire the username password next time he logins he has to give new passwd

sudo passwd -d username: deletes the password of that account and sets that account passwordless.

In recent years, we have been in so much love for the free commodity without realizing we ourselves have become the commodity. We install only free apps from stores. This is to make you aware of the possible threat to our Right to Privacy which is very important:

What the problem is?

We have used Facebook like various free social networking sites which claims connecting people. Have you ever wondered how these proprietary companies are offering users its product for free? Yes, Facebook gets lots of revenue from adds. But how these adds are unknowingly so accurate? There has to be something tracking our data. These trackers know very effectively which sites have I visited and which product I looked in the cart. There has been many cases of phone tapping and call records that itself has put the citizens privacy a question.

Whom will our data benefit?

You might have gone through various surveys that asks you varieties of question and it will predict your personality. You fill it and submit ignoring the Terms and Condition. These can give them permissions to our personal data likes messages our locations etc. Now these contents are connected to my profile. Giving the direct access to any buyer about my pulse. These companies can now target the user by bombarding with the polarised content which is designed for me and seen only by me.

Why us?

We spent most of our time on these social sites liking and disliking the contents, called as data points . These data points can describe our personality. Through these personality they target those user whose decision can be influenced. These data are so much important to the buyer's that they can pay any amount. Most of the buyers are the political parities who want to influence the election by targeting its citizens. This is cheating democratic process of election. There is a instance during the Trump's Election campaign where a candidate named Ted Cruz won the election on the basis of the user's Facebook like. See how big that difference can cause. Data mining companies like Cambridge analytica had major role in his winning. According to the report Cambridge Analytica has stated that it has around 5000 data points of around millions of American's citizens.

Our privacy is our responsibility

We have to skeptic about our data sharing. You don't know how can some companies mines your data and influence you in their reasoning. Our society has to be updated with the current threat and unethical business model. As the world is getting more advanced keeping our data secure and private is very challenging. There have been many cases of data phishing and fraud calls where we unknowing share our personal and crucial details. The reason behind this is lack of awareness among the people. It is our duty to find the solution so that the technologies we build for human life enhancement should not break it.

gitCoffee

Got a dream contributing to FOSS projects but lacking confidence in git commands. Don't worry this blog is for you: Let's begin learning git with the following FAQ:

  1. What is git init and why it's used?

    git init: Using this command we first initialize a local git repository. The files we will add here will now be tracked by the git. Running git init command is safe it reinitialize if there is an existing one.

  2. What is git clone and how can I clone a project?

    git clone https://github.com/your_username/repo_name: Will clone the remote repository into a newly-created directory.

  3. What's the status in git?

    git status: This command gives the list of files that have not been committed. This includes modified files and newly created files.

  4. What is Staging? How can I add a file to staging?

    Staging is like a checkpoint where only those files are there which is to be committed. Here we do modify any changes before final commit. git add [file-name.txt]: This command adds the file-name.txt to the staging area.

  5. How can I add all files to the staging area?

    git add -A or git add .: Using this command we can add all new and changed files to the staging area.* Note: There are times when unwanted files like file_name.swp also get added and committed to avoid this it's better to add files one by one.*

  6. How to commit a change with a proper message?

    git commit -m "[commit message]" -m is used to allow adding a commit message
    Using this command we can move all the staging area files to commit area in the local repository.

  7. How can I delete a file or folder?

    git rm file-name or git rm -r folder-name The above command are useful when you are deleting a file or deleting multiple files. git rm -r file-name removes the duplicate file-name recursively.

  8. I have created multiple branches. How can I get all my branches?

    git branch: This command lists all the branches created in your local repository. The asterisk denotes the current branch. git branch -a: This will list all the branches in the local as well as a remote repository.

  9. How to create and delete a branch?

    git branch [branch name]: This command will create a new branch.Note this does not checkout the new branch. git branch -d [branch name]: This command will delete the branch. This is the safest way to delete a branch as it prevents deletion if there are any unmerged changes. git branch -D [branch name]: This command will forcefully delete the branch and also deletes the commits associated with the branch. *Note all the above will bring changes in the local repository.

  10. How can I delete a branch in a remote repository?

    git push origin --delete [branch name]: This command will delete a remote branch.

  11. Can I create a new branch and automatically switch to it?

    Yes, you can use git checkout -b [branch name] command to create a branch and switch to that branch automatically.

  12. How to change branch present in a remote repository?

    Well, It depends on the Git version you are using. For modern version of git: git checkout [remotebranch] For older version of git : git checkout [remotebranch] origin/[remotebranch]

  13. What are the ways to see my commits?

    • git log: Using this we will see all the changes committed in the repositories.

    • git log --summary: Using this we get the detailed view of the changes made in the repositories.

    • git log --oneline: This command gives the history of the commits in brief.

  14. What are the ways to discard changes made to the file?

    • git checkout -- [file-name.txt]: This command will permanently discard all the changes made in the branch local repository.

    • git stash: This command will remove the changes made in the current branch but saves it for later use. So using git stash pop we can get back the saved changes made in the file of that branch.

First of all kudos for successfully creating `.onion' address. If not, see my previous blog. Tor Browser

Just having a domain is useless if you don't know how to make use of it. So let's begin with the newly created domain. Note the following guidelines are verified on Ubuntu 18.04

Step 1 : First make a directory :-

sudo mkdir /var/www/your_directory_name cd /var/www/your_directory_name/

Step 2 : Create a file name index.html :-

touch index.html

Step 3 : Editing the newly created file

sudo vi index.html : sudo gives the power to override the readonly files Press 'i' to go in INSERT mode Write your good name Press ESC and give :wq as command to save index.html and exit vi Editor.

Step 4 : Editing the root :

cd /etc/nginx/sites-available/ : If says permission denied sudo it :) sudo vi default : It will open long content. Edit the root line from '/var/www/html' to '/var/www/yourdirectoryname'. Save and exit.

Step 5 : Reloading nginx :

systemctl reload nginx

Kudos our work is done

Step 6 : Open your domain name in Tor Browser :

Incase you forgot your domain name. Type sudo cat /var/lib/tor/hidden_service/hostname

Happy Coding :)


Onion Note : The following guidelines are verified on Ubuntu 18.04 First install tor and nginx using the following commands: sudo apt install tor sudo apt install nginx sudo ufw allow Nginx Full

Open Terminal and enter : vi /etc/tor/torrc command press i to go in INSERT mode. then search for ############### This section is just for location-hidden services ###

Un-comment the following 2 lines by removing “#” symbol. HiddenServiceDir /var/lib/tor/hidden_service/ HiddenServicePort 80 127.0.0.1:80

to exit vi press Esc then enter :wq to save the changes and exit.

Try to restart the tor and nginx services by the following two commands: sudo service tor restart sudo systemctl restart nginx

On entering the command : sudo ls /var/lib/tor/hidden_service/ you will find filename such as hostname and private key. Enter : sudo cat /var/lib/tor/hidden_service/hostname use will find .onion address. Check it on the Tor browser.

“Congrats you got your own new domain.”

This post may contain error. Please bring it to the notice to help others. By connecting Mrinal Raj


First things first, we should be thankful that we all live in a country where there is freedom to speak on our views. As decades passed and technology evolved the ways of expressing our views have changed completely. We spend most of the time on various social networking sites, updating status almost regularly, sharing our locations, our likes and dislike, our religion and even our views on politics. Now the question is what if we are being tracked? What if these data are easily available to the trackers. You are then left with two replies :

  • Either you completely deny the fact that it is possible.
  • Or you say you got nothing to hide and got no problem with it!

You will find most of the people who state that they have nothing secret in them to hide, it sounds like you don't care about your fundamental rights as you have got nothing special to speak.

To say that you have nothing to hide means like you have nothing to say to protect your freedom of speech.

-Edward Snowden

If you think your privacy is safe and no one is peeping inside your personal and professional life, you need to go through inspiring true story of Edward Snowden and how he was chased when he chose the path of adversaries to benefit others instead of spending rest of his life luxuriously.

Edward Snowden


Edward Joseph Snowden was working as a contractor under US Government where he had access to all the classified files collected from the global surveillance. Edward revealed in public misuse of around billions of internet data and telephonic data records which is called metadata collected by government globally without user's interest. Edward saw that this was a direct attack on the citizens' Freedom of Speech and privacy.

Government's Point of View


Right after the 9/11 attack on the World Trade Centre, US government took various steps to curb terrorism among which one was to give secret access to US State Secret Service which can conduct the surveillance on any of citizen's phone record, GPS location, browser history, etc. Through MNC's like Google, Facebook, Apple they started to gain the data on the citizens. According to the report, there have been about 1.2 million people under the US watch list. Government believes that they can prevent terror attack before it happens using mass surveillance at the stake of our Right to privacy.

Conclusion


Most of the time we fall prey to the online trackers like Facebook and Google where our privacy is more vulnerable. We should try to avoiding websites that tracks our identity and location. Always open-source software should be preferred over a proprietary one.