Why Did Apple Call One of Their Computers Macintosh?

Question
Why did Apple call one of their computers the Macintosh?

Answer
It was based on a type of apple that you eat (e.g., golden delicious, Fuji, etc.). It would have been called the McIntosh, but there were legal reasons for adding the letter “a”. To read more about how the name was chosen, see this page.

 » Read more..

How Do You Delete Files from a Directory That Are Smaller Than 10 KB with a Bash Command?

Problem scenario
You want to delete all the files (but not subdirectories) that are less than 10 KB in Linux’s /tmp/ directory. How do you do this?

Solution
Run this command: find /tmp/ -maxdepth 1 -type f -size -10k -ls | awk ‘{print $NF}’ | rm -rf

 » Read more..

How Do You Get the “Up” Arrow to Show a Previous Command in Linux?

Problem scenario
When you press the up arrow on the keyboard you see ” ^[[A”. You want to see the previous command that was entered. How do you enable history at the command line?

Solution
Root cause: The /etc/passwd file has an entry like this:

cooluser:x:1001:1002::/home/cooluser:

(This could be caused if you created the user quickly with a useradd command.)

Procedures

Run this command: sudo cat /etc/passwd | grep $(whoami)

Do you see a /bin/bash at the end?

 » Read more..

How Do You Zero out a /var/log/mail File?

Problem scenario
You backed up /var/log/mail to a different file. You want the /var/log/mail file to start empty so you can review it without looking at old activity. What do you do?

Solution
Run these four commands:

sudo su –
cd /var/log
mail
exit

Now you /var/log/mail file will still exist and record activity as normal. It will not have anything in it before the time you ran the above “>

 » Read more..

How Do You Delete Files That Were Modified More Than Three Days Ago?

Problem scenario
In Linux you want to delete files that have not been modified in the past three days from the /tmp/ directory. What do you do?

Solution
Run this: find /tmp/ -maxdepth 1 -type f -atime -3 -ls | awk ‘{print $NF}’ | rm -rf

 » Read more..

What Does “__” Mean in Python?

Problem scenario
You see two underscores or two underbars before a function in Python. What does this syntax signify?

Possible Solution #1
The answer is best explained by running this program once with no modification and a second time with a modification.

class ContintClass():
def __init__(self):
self.__completelyprivate = “1111111111”
self._semiprivate = “2222222”

foo = ContintClass()
#print(foo.__completelyprivate)

print(“Above is an attempt to print a completely private data member of an object”)

print(“Below is an attempt to print a semi-private data member of an object”)
print(foo._semiprivate)

Before you run the program the second time,

 » Read more..

How Do You Get the ElasticSearch, LogStash or Kibana Service to Remain On?

Problem scenario
The elasticsearch, logstash or kibana services will start, but when you check the status, it does not remain on. It keeps stopping. You see the status as “failed.”

Solution
Possible Solution #1
Add more memory or swap space to the system. If you need assistance with either of these, see this posting.

 » Read more..

Why is Your Python Programming Printing Duplicate Lines?

Problem scenario
You have a Python program with print statements. When you run the program, you get twice as many print statements as you expect. What could be wrong?

Solution
Do not name the program re.py or string.py. When you name the program re.py and have an import re statement, Python may print every line it is supposed to print twice.

 » Read more..

How Do You Write a Python Program to Create a .txt File with 50 Key-Value Pairs?

Problem scenario
You want to create a .txt file that has 50 key-value pairs. You want the keys to be whole numbers. You want the values to be five-character strings. What should you do?

Solution

import random
import string
import sys

def randomword(length):
letters = string.ascii_lowercase
return ”.join(random.choice(letters) for i in range(length))

def printer(counter, webstera):
webstera[counter] = randomword(5)
if (counter <  » Read more..

How Do You Install ElasticSearch on CentOS/RHEL/Fedora?

Prerequisites
This assumes you have installed Java. If you need assistance with installing Java, see this posting. This assumes you have a server with 4 GB of memory (e.g., virtual memory and RAM in an amount greater than 4 GB). The command to run to see how much memory you need is this one: free -mh If you need more memory, see this posting.

 » Read more..