Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Most Useful Linux/Unix Commands

Here is the list of commonly used commands on Unix/Linux systems.

1. Split File based on number of lines 

  If you want to split text file "abc.txt" containing 50 lines by each line use the below command
csplit abc.txt 1 {49}

2. Find out Top 10 Memory intensive processes 

  If you want to figure out which are the top 10 memory consuming processes use the command below
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
You can change mem with cpu for top CPU consuming processes.

3. Curl command to skip SSL Certificate check (HTTPS)

You can skip the SSL Certificate check by providing -k parameter to curl as below.
curl -k --location --request GET 'https://your.web.com'

This post will be forever updated as and when I find new useful commands.

How to avoid host key checking during ansible script execution

During execution of ansible playbook or ansible script on new remote host (which you have not connected via ssh so far) the script might fail with below error

 UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ----}

To avoid this you can set the environment variable (ANSIBLE_HOST_KEY_CHECKING) to disable host check before ssh during ansible script execution.

 export ANSIBLE_HOST_KEY_CHECKING=False

Now you can execute the ansible script.

How to switch boot order within Windows & Linux

If you have both Windows and Linux installed on your computer, default  booting operating system would be Linux.
If you are frequent Windows user than Linux, the default booting OS(Operating System) should be Windows else you will waste time in every time choose boot to Windows.
Note that to change the boot sequence you will require the root level access as you are going to modify "/boot/grub/grub.cfg".
If you are using x windows system, open the file "/boot/grub/grub.cfg" using any text editor. If you don't have root level access then open text editor using sudo command as:
sudo -u root gedit 
Then open the file grub.cfg. In the grub.cfg search for "menuentry" and check for menuentry having "Windows " loader line.
Count the number of menuentries before Windows entry. Do not count Windows entry as menu entry start from 0. Set the counted value at:
set default="0" 
in the grub.cfg file as set default="5" now save the grub.cfg file and you are done. Just restart the computer and check if the changes are reflected on boot loader.
Alternatively you can do above easily with terminal as below.
  • Open the terminal by pressing buttons "Ctrl + Alt + T" ( Control + Alt + T). 
  • On terminal type following command:
           cat /boot/grub/grub.cfg | grep menuentry
  • This will print output as below 
  
  • Count the menuentry till the Windows entry. The counting should start from 0.
  • Now edit the file using command sudo -u root vi /boot/grub/grub.cfg
  • Update the counted value instead of set default="0" as lets say in above case it is 8 so, set default="5".
  • Save the file, and restart the computer. 
Note: While counting for "menuentry" make sure that count one menuentry for all "menuentry" present under submenu such as in above image submenu "Previous Linux versions"{ }. For this you will have to open file in text editor or cat completed file on terminal, to check what entries present under Submenu.

Undefined reference to `std::cout'

You may get the error "undefined reference to `std::cout'" while compiling C++ program in Linux/Ubuntu. 
In order to resolve the error check:
  • Have you included the iostream header file in your program. If no then include "iostream" in the code. OR
  • Are you trying to compile c++ program using gcc command. You should compile C++ program using g++ such as: $ g++ test.cpp

File format not recognized; treating as linker script

If you are getting error "file format not recognized; treating as linker script
while compiling C++ program using g++ in Ubuntu, then you might have used incorrect file extension for your code file.
As File names are is case sensitive in Linux the file extension that you have specified for your program code file also matters while compiling the code.
You should use ".CPP" (All in capital letters) or ".cpp" (All in small letters) extension to your code file.

How to install gcc on Ubuntu

To check if you have gcc installed on your Ubuntu type gcc on the terminal. If terminal shows you following error means you don't have gcc installed.
"gcc: fatal error: no input files"
To install gcc, all you need to do is to follow the below commands:
  •  sudo apt-get update
  •  sudo apt-get upgrade
  •  sudo apt-get install build-essential
Once the installation completed for essentials, you can check the installed gcc version by command
  • gcc --version

How to install the Utorrent in linux or ubuntu

1. Download utorrent from http://www.utorrent.com/. Right click the downloaded file and click 'Extract Here'.
2. Open the extracted folder.
3. Right click the file with name 'utserver' and make it executable.
4. To make it executable right click on utserver -> properties -> permissions -> add check the check box of "Allow executing file as program".
5. Now execute the file 'utserver' by double clicking it.
6. utserver runs as background program so you will not see any user interface on execution.
7. Open your browser like firefox , chrome etc.
8. Now type in URL : http://localhost:8080/gui/
9. It will prompt for the authentication. Type username: admin
   leave password field blank and press ok.

If you fail to see the ui of utorrent the reason could be you don't have a dependent lib that utserver required, check this post for resolving the error.

unable to see utorrent webui in Ubuntu / Linux

You have downloaded the Utorrent and trying to use the utorrent using webui. But if the webui is not showing up, then you need to check if the "utserver" is running or not.
You can check this by executing command
"sudo ps -e | grep utserver"
to see if utserver running.
If utserver is not running, execute the utserver by double clicking "utserver". Now check if the utserver is running. If it still fails to execute, then go to terminal, traverse to the directory where you have download and extracted the utorrent. Now execute the utserver by executing command
"./utserver".
If it fails to execute you may see the error on terminal. It might be case that you will be missing the dependent lib. Install the dependent lib and start utserver again. It should start successfully.

Caching is a technique used to store frequently accessed data in a temporary storage layer to improve system performance and reduce latency....