linux-unix

recent posts related to linux and unix

Customizing Ubuntu with themes alvin January 12, 2017 - 10:31am

This image is from an article about Ubuntu named, How to make your desktop look like my desktop. makeuseof.com has another article on customizing the Ubuntu UI with themes.

The best Linux laptops of 2016 alvin January 11, 2017 - 7:09pm

This is a nice article on the best Linux laptops of 2016, including what to look out for in graphics chips and other hardware issues. As I become more disgruntled with Apple and the direction of Macs and MacOS, I thought I’d start looking for a Linux laptop.

A Unix find and move command (find in subdirectories) alvin September 11, 2016 - 3:52pm

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.)

How to use ‘awk’ to print columns from a text file (in any order) alvin August 29, 2016 - 11:14pm

Printing columns of information from Unix text files is easy, especially using commands like awk, perl, and more recently, ruby. This short tutorial shows my old-school awk way of doing this.

awk column printing examples

Suppose you have a file named foo with contents like this:

1 2 3
a b c

You can easily use awk to print columns of information from this file. Here are a few examples that show how to print the data columns from the file:

Nginx configuration: How to drop the query string on a rewrite alvin July 31, 2016 - 12:58pm

As a quick note, if you need to drop the query string when configuring an Nginx rewrite request, this syntax works:

rewrite ^/foo/bar.*$  /bar?  permanent;

The key is to use the ? character at the end of the URL/URI you are redirecting users to. That drops the query string, so the user will be redirected to the exact /bar URI.

For more information, see the Nginx rewrite module page.

What is the Unix/Linux “bit bucket”? alvin July 21, 2016 - 10:44am

Unix/Linux FAQ: What is the “bit bucket”?

The bit bucket is a way of referring /dev/null. Sending output to the /dev/null device file is like sending output directly to the trash. That’s why you see code like this a lot of times:

aCommand 2> /dev/null

That’s a way of saying, “Run the command aCommand and send it’s error output to the bit bucket.” In use like this, “error output” refers to STDERR, and redirecting STDERR to the bit bucket is the same as throwing it into the trash (or throwing it into a black hole, if you prefer).

Another way you can demonstrate this is by sending STDOUT to the bit bucket. In this next example, I send the output from the ls command to the bit bucket:

ls -l > /dev/null

If you run that command, you won’t see any output because the standard output — STDOUT — is redirected to /dev/null. There’s no practical reason for doing this in the real world; I just wanted to demonstrate that you can redirect both STDOUT and STDERR to the bit bucket, if you ever need to.

For more information, here’s a short tutorial on How to redirect Unix STDOUT and STDERR to the same location.

How to use the Linux sed command to delete a range of lines

In a previous blog post I demonstrated how to use sed to insert text before or after a line in many files, and in this example I'd like to demonstrate how to delete a range of lines using sed.

sed delete - How to delete a range of lines using sed

The problem I had today was that I just re-generated 99 HTML files for my Introduction to Unix/Linux tutorial using Latex2HTML, and it generates a bunch of "junk" in my HTML files that looks like this:

Sorting ‘ls’ command output by filesize alvin July 17, 2016 - 1:01pm

I just noticed that some of the MySQL files on this website had grown very large, so I wanted to be able to list all of the files in the MySQL data directory and sort them by filesize, with the largest files shown at the end of the listing. This ls command did the trick, resulting in the output shown in the image:

ls -Slhr

The -S option is the key, telling the ls command to sort the file listing by size. The -h option tells ls to make the output human readable, and -r tells it to reverse the output, so in this case the largest files are shown at the end of the output.

vim: How to go to the last position when reopening a file alvin July 4, 2016 - 5:54pm

vim tip: If you reopen a file with vim and want to go to your last position in that file, type '"

(That’s an apostrophe followed by a double-quote.)