Posts in the “linux-unix” category

An Nginx proxy pass example

As a quick note to self, as I configure my “Mini-Me” application, which has a client written with Sencha Touch 2, and a Play Framework server, I used this Nginx proxy pass configuration:

A few notes on installing and configuring a CentOS Linode server

I just got a new CentOS Linux server at Linode, and installed a bunch of software on it that I need to run a couple of Drupal websites and a Play Framework website, and here are my very cryptic notes from that installation process. (Sorry, these are more for me than for you.)

First, I installed all the necessary Linux stuff:

Linux file searching: Search for text in files with find and grep commands

Linux find/grep FAQ: How can I combine the Linux find and grep commands to search a large collection of files?

A lot of times when I need to find a file I know the text in the file that I'm looking for, but I can't remember the filename, or can't think of what directory it might be in, other than somewhere below my home directory. When this happens, and other search means like the "locate" command don't help, my favorite way of searching for text strings in files that are spread through a bunch of directories and sub-directories is this:

How to install a ‘deb’ file on Debian Linux (dpkg, apt)

As a quick note, this stackexchange.com page has some good background information on how to install a deb package file from the command line on Debian Linux (which in my case is Ubuntu 16.04). The short answer is that if you have a deb file named google-chrome-stable_current_amd64.deb, you’ll want to run these two commands, one after the other, as shown:

$ sudo dpkg -i google-chrome-stable_current_amd64.deb

$ sudo apt-get install -f

The complete example

To give you some more perspective on how this works, here are those two commands shown with all of the output that they produce. Note that I put my deb file in a temporary directory before running the commands:

/home/alvin/Desktop/tmp> sudo dpkg -i google-chrome-stable_current_amd64.deb
[sudo] password for alvin:
Selecting previously unselected package google-chrome-stable.
(Reading database ... 258250 files and directories currently installed.)
Preparing to unpack google-chrome-stable_current_amd64.deb ...
Unpacking google-chrome-stable (56.0.2924.87-1) ...
Setting up google-chrome-stable (56.0.2924.87-1) ...
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/x-www-browser (x-www-browser) in auto mode
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/gnome-www-browser (gnome-www-browser) in auto mode
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/google-chrome (google-chrome) in auto mode
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160701-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...

/home/alvin/Desktop/tmp> sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic
  linux-image-extra-4.4.0-31-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

After I ran those commands to install the deb file I removed the tmp directory I used during the installation process.

For more information see that stackexchange page. This debian.org page also has a good list of apt and dpkg commands, and this debian.org page shows how to list installed packages.

Hints for writing Unix tools

Marius Eriksen has a good article titled Hints for writing Unix tools. Some key points: a) consume input from stdin, produce output to stdout; b) output should be free from headers or other decoration; c) output should be simple to parse and compose. There’s much more to it than that, and it’s a good read (or reminder).

Ubuntu running on a 2008 27” iMac

As shown in the image, I just installed Ubuntu on my 2008 27” iMac. The UI is interesting, a combination of MacOS and Windows. From what I’ve seen, I think I’ll like the Ubuntu UI (Unity) more than Linux Mint, but I’m open. So far Ubuntu is also significantly faster than the latest versions of MacOS were on the same hardware, though that may be because MacOS had a few hundred thousand more files on it than Ubuntu has at the moment.

vim macros - how to create vim macros

vi/vim FAQ: Can you provide some examples of how to create vim macros?

Here's a quick example of how to define macros that you can use in the vim editor (or vi editor). As you can tell by looking at them, I use these particular vim macros when editing HTML files.

Define vim macros with the vim map command

Step 1 in the process or creating vim macros is to edit the vi/vim startup file in your home directory. On Unix, Linux, and Mac OS X systems, this file is named .vimrc.

So, move to your home directory like this:

An example vim vimrc configuration file

vim/vimrc FAQ: Can you share an example vim vimrc configuration file?

Sure. I don't use vim for programming much these days, so I don't have the vimrc configuration commands I used to use with various programming languages, but I'll be glad to share my vimrc configuration file that I use every day, along with a few extra lines to demonstrate some of the vim configuration possibilities.

Example vim vimrc configuration file

Here's an example vimrc file:

A Unix find and move command (find in subdirectories)

This is a dangerous Unix command, but if you want to move a bunch of files from their subdirectories into your current directory, this find and mv command works:

find . -type f -exec mv {} . \;

That command finds all files beneath the current directory, and moves them into the current directory. I just moved a bunch of files from their (iTunes) subdirectories into my current working directory, and that find and move command did the trick. (But again, it’s a dangerous command, be careful out there.)

The Linux ‘head’ and ‘tail’ commands

Linux head/tail FAQ: Can you share some examples of the Linux head and tail commands?

Sure. The Linux head and tail commands are very similar, so I've included them here together. The head command command prints lines from the beginning of a file (the head), and the tail command prints lines from the end of files. There's one very cool extra thing you can do with the tail command, and I'll show that in the tail example commands below.