Facebook

Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

How to shorten the bash shell prompt


So sometimes it happens that you are working on command terminal and you navigate inside a directory then again in inner directory and so on until half of the screen width is filled with prompt string. Example below....

rana@Brahma: dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8 $ ls 

Now I want to display just the last directory in terminal prompt string so that I am left with enough width space to execute length commands.

For this We need to change the prompt string from .bashrc file. Below are the steps -

1. Go to your home directory.
2. Open .bashrc file.
3. Search for string 'PS1'. To search quick open the file in vi and type /PS1 and hit enter.
4. now you will find below code. (or similar to it) [ I am working on Ubuntu 16.04]
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
5. Replace the 'w' (highlighted in blue color) with capital W. So your new code will be.
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]: \[\033[01;34m\]\W\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
6. Restart the terminal and navigate inside any directory. You will see just the last directory in teminal prompt.
rana@Brahma: dir8$

Happy Learning.


 

Classic snake game in Linux terminal

Hello Friends,

You must have played the classic snake game on feature phones like Nokia 1100.
Now you can again play the same game in Linux terminal.
For this you need to install nsnake package by running below command in terminal.


sudo apt-get install nsnake


After the package is installed , run the game by running nsnake command.




Use the up and down arrow keys to change to game mode to Borders On and Borders Off.
Use left and right arrow keys to change the speed.
Press enter or space to start the game one you are done with settings.
You can exit the game by pressing q key.




Rules are the same as they were in classic game.
If you collide with yourself (snake), you die. Game over.




Download the latest version of this game from Github.
Buy cheapest nokia mobile phones here.


ASCII screensavers in Linux





Are there any ASCII animations in Linux which can be used as screen-saver ?
Answer is "Yes". There are many such ASCII screen-savers , few of them are described below. We will explain in detail how to install and use them.

1. Pipes : Best one so far ( my personal preference .

How to Install :
Open the terminal and run below commands -

   1:  git clone https://github.com/pipeseroni/pipes.sh.git
   2:  cd pipes.sh
   3:  sudo make install 

Refer to this documentation on github for more details.


2. cmatrix : Great one.
It displays matrix movie type characters on screen.


How to install :
Run below command in your terminal.

   sudo apt-get install cmatrix

How to run:
Run the command in terminal :

cmatrix -s -b



3. Termsaver : Multiple animations in one.
Text based screen saver having multiple animations like starwars, matrix, jokes4all etc.

How to install :
Run this command in terminal

sudo apt-get install termsaver

How to use :

termsaver matrix

Output of 'termsaver clock'




4. Aquarium

Installing this ascii screen-saver require a little more work..
I am leaving this on you. Follow these steps to install this screen-saver.


;

Printing both side in Ubuntu


In Ubuntu 14.04 , default document viewer doesn't support both side printing of a PDF document.



To save paper, one must print on both side of a paper.  

Here is the trick to print on both side of paper. 
Right click the document and select 'Open with' option. Now select 'Google Chrome' program from the list. Document will open in a new chrome window/tab. 
Press 'control + p' or select 'Print' form 'file' menu option.
You will see the 'print preview' window. On the left hand side you will see options where at the bottom you can select 'Two-sided'. Printing now will print the document on both side of paper.




Project Android device screen on your laptop


Whenever you need to demonstrate something to everyone present in the classroom or meeting room, you connect the laptop with projector and project the laptop screen. This is simple, you either use RGB cable or HDMI port.
What if you have developed some Android application and want to demonstrate it to a large audience. There is no HDMI port in Android device.

Interactive Voice Response system - FreeSwitch Installation



What is IVRS ?

A technology that allows a computer to interact with human through the use of voice and DTMF tones input via keypad.
IVR systems can respond with pre-recorded or dynamically generated audio to further direct user on how to proceed.How to Setup an IVR System.

Bash ShellShock : Worst than Heartbleed



image - http://gizmodo.com

Bash Shellshock, the newly discovered vulnerability that allows attackers to inject code into your machine, puts your Mac or Linux at a serious risk for malicious attacks. It's kind of like Heartbleed, the Open/SSL bug that scared everyone senseless a few months ago and remains unpatched on thousands of systems. According to some experts, however, Shellshock could be way worse, and it's been around for decades.

How to check if you are vulnerable:

Play a song as soon as someone comes online


Today we are going to create a very simple and small script which plays a song when someone starts their system i.e. as soon as they come online (Of-course you both should be in same network. i.e their system should be reachable form yours) .

So have you heard of ping command. Yes? Great. We will use this command only.

How to use a function from one file into another file in C


So lets say there is some function which you need to use in many programs of your project. One way is to copy paste the code in each and every file. But this will increase the size of every file and what if there are thousands of file. I am sure you would not like it. Also C is the programming language which needs very less space and is used in application which require minimum space. So copying same code in every file seems not a viable option. 


Also what if one day you need to change the code a bit. Oh man ! You are doomed. Better go for a vacation and meanwhile your boss will give this editing task to someone else. 


Unix is Fun


who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; fsck; more; yes; more; gasp; yes; uptime; umount; sleep






StopWatch and other Hacks




Say Yes to all confirmations


So sometimes it happens that you are installing some package or compiling some source code and it asks for your confirmation
Do you want to continue (y/n)?
 so instead of pressing 'y' everytime you just can do this

Let Linux speak for you


Now let your Linux speak for you.
 
There is a utility in linux called 'espeak' using which you can let it speak. Its more or less same as 'Narrator' in Windows.

Syntax is :

Download YouTube video in One Go




How to download single video - 


$ youtube-dl   is a very powerful utility in Linux to download videos from Youtube or other similar sites.


To download just one video use the below syntax


StarWars in Terminal




This is for Geeks and Nerds only. Others may not found it interesting.

To watch StarWars  in command-line terminal, run the below command 

$ telnet  towel.blinkenlights.nl

How to Reset the Root password of any Ubuntu Machine.



You might need to change the root password of your Ubuntu Machine, May be you forgot the password or you want to Log-in into your friend's system and you don't know the password.

Here is the trick to achieve this.

1. Restart the system.

Sharing files in Linux.


Wanna Share some file with your friend ? Here are three methods.

1. The traditional way. Transfer files to Pen Drive and then your friend copy it to their system. This is the best way to share if both system are not in same network.

Cons - 

  • File is copied 2 times.
  • What if file size is more than size of pen drive.


2. Install apache 2. 

Installing Ubuntu 12.04 on Windows Machine.


Ubuntu is one of the most popular Linux flavor. Release 12.04 have support till April 2017. Here are steps on how to install it on your window machine. Official website links are provided for help.


Ubuntu can be installed in 3 ways. 


dmidecode : Finding everything about your hardware.


Only one command in terminal and all the Hardware related information is dumped in human readable format on your terminal.

I was wondering how can I found the Model number and product number of my laptop from terminal. Searching over the Internet fetch me this command.