Many times I found myself typing history into the terminal and then copy/paste the command I was looking for. But, then I found the below tricks to help repeat that command faster and more efficiently.
I found this to be the most beneficial for me. It will do a reverse search really fast! Just press enter when you see the command you need to retype.
Repeat the previous command quickly
This is useful if you know you recently typed a command. You can use the following key combinations:
Use the up arrow to view the previous command and press enter to execute it.
Type !! and press enter from the command line
Type !-1 and press enter from the command line.
Press Control+P will display the previous command, press enter to execute it
Execute a specific command from history
For example, you can display history as usual:
history | more
1 service apache2 restart
4 cat /etc/hosts
If you want to repeat command #2, you will type !2 as show below:
Inserting data into MySQL tables is easy, but I tend to forget little details once in a while. I was having the best espresso coffee and trying to remember this one. Below is how you insert a new row into a MySQL table.
Assume you created the following table:
CREATE TABLE IF NOT EXISTS mytable (
mytable_id INT AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
priority TINYINT NOT NULL DEFAULT 3,
PRIMARY KEY (task_id)
And then you want to insert a new row into this MySQL table. Run the command below:
INSERT INTO tasks(title,priority)
VALUES('Learn MySQL INSERT Statement',1);
You should get the below from MySQL:
1 row(s) affected
That’s all! Contact me if you need help. Write in the comments section if you have questions.
The other day my sound stopped working on Ubuntu 18.04 desktop. I have no clue why. The sound stopped working overnight for some reason. After some research I found the below command to restart the sound service on Ubuntu:
pulseaudio -k && sudo alsa force-reload
All works now! Give it a try and let me know if it works for you. Follow me on Twitter @itprohelper
I started an Ubuntu EC2 the other day hoping to run Ansible on it and was surprised that Python was not installed. A requirement for Ansible to run on target machines is to have a modern version of Python.
You can just run sudo apt install python but this is not ideal if you need to install python on let’s say 200 Ubuntu Servers.
The raw module to the rescue
Before writing the playbook, you will need to make minor changes to how Ansible connects to remote hosts.
Create a new file in your current directory and call it ansible.cfg. This file will override settings in the default /etc/ansible/ansible.cfg. Example:
[defaults] inventory = hosts remote_user = ubuntu # Use the below if you’re connecting for the first time host_key_checking = False # Location of your .pem you got from AWS private_key_file = ~/.ssh/yourkey.pem
Now create a hosts file:
[ubuntu_server] 188.8.131.52 # This is a sample IP address. Use your IP.
The playbook using the raw module
This playbook will install python on the target host Ubuntu EC2 server:
A .gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Normally, this is placed in the root directory of your repository. This is the recommended way. The patterns in the .gitignore file are relative to the location of the file.
Easiest pattern is a literal file name:
This will ignore any files named .DS_Store which is common in MacOS.
You can ignore entire directories by including their paths and putting a / at the end:
node_modules/ logs/ secret_directory/
If you leave the slash ‘ / ‘ at the end you will match both directories and file names.