Posts in the “linux-unix” category

A tmux cheat sheet

I just started using tmux last week, and created a cheat sheet to help me remember the basic tmux commands, and I thought I'd share that here.

The cheat sheet has a few things that are specific to my configuration file, so to begin with, here is my ~/.tmux.conf file:

How to easily determine the blocksize of a filesystem

I just saw that this is a way you can easily determine the blocksize of a filesystem, at least a Mac/Unix/Linux filesystem:

$ echo foo > foo

$ du -h foo
4.0K    foo

I tried to do the same thing with touch foo, but that didn’t work. Without digging into it more, the key seems to be in having very little text in the file, at which point the du command shows the minimum block size for the file.

Mac OS X: Unix sed commands I use to clean MacDown HTML output

FWIW, this is the source code for a sed script I use on my Mac OS X system to convert HTML output generated by MacDown into a format I need. MacDown generates some extra “cruft” that I don’t need, so I use these sed commands to clean up that HTML output:

A Linux shell script (and commands) to find large files

I made a mistake in configuring logrotate on a new Linux system, and almost ran into a problem because of that. Fortunately I saw the problem before it became a BIG problem, but as a result, I decided to add a script to my Linux system to check for large files, typically log files that have grown out of control for one reason or another.

Here then is a simple Linux shell script I named LargeFileCheck.sh, which searches the filesystem for files that are larger than 1GB in size:

How to use the Linux top command

Linux processes FAQ: Is there a utility to show Linux processes interactively, like the Unix/Linux ps command, but more like a GUI ro character-based interactive tool?

Unix find command: How to move a group of files into the current directory

I just bought a bunch of MP3 music files from Amazon, and when I downloaded the zip file they provide onto my Mac, it was a bunch of files in a bunch of subdirectories; not really convenient to work with when you’re trying to import them into iTunes. So I used this Unix find command to move all of the music files from the subdirectories they were scattered in into the root directory that was created when I expanded the zip file:

cd Amazon-Music-Folder
find . -type f -exec mv {} . \;

If you ever need to either copy or move a bunch of files with a single command, I hope this example shows the correct find command syntax for your needs. (If you need to copy the files, use the cp command instead of the mv command.)

Handling spaces in Linux shell script input (and for loops)

Linux shell script FAQ: How can I deal with spaces (blank spaces) in my input data when I'm writing a shell script for loop or while loop?

I was just working on a Linux shell script, and ran into the ages-old problem of handling data that has spaces (space characters) in it. I run into this any time I try to read a data file with blank spaces in it, or when I run into files and directories with spaces in their names. Whenever I try to work this data like this in a shell script for loop, the spaces always ruin what I'm trying to accomplish.

A Bourne shell script that loops through all files in the current directory

Linux shell script for loop FAQ: Can you share an example of a Linux shell script for loop, for instance, to do something for every file in the current directory?

Here's a shell script that you'll find on all the Unix, Linux, and Mac OS X computers I've worked on. The general process of this script is "for every file in the current directory do XYZ".

How to run a sed command from the Linux command line

Linux sed FAQ: How do I run a Linux sed command from the command line?

I usually only use the Linux sed command in sed scripts, but today I needed to do something much easier than normal, and as I thought about how to run a sed command from the Linux command line, I had to pause for a few moments. Finally I remembered the sed command line syntax, and it looks like this:

sed 's/THE_DATE/2010-07-11/' < sitemap-orig.xml > sitemap.xml

This sed command can be read like this:

Debug Linux shell scripts with ‘-x’

If you ever need to debug a Unix or Linux shell script, you can just add the -x option to the interpreter when you invoke it. You can add the shell's debug option on the command line like this:

sh -x misbehaving_script.sh

or at the end of the first line in your shell script (the she-bang line), like this:

#!/bin/sh -x

I was just working on a shell script related to fonts on a Mac OS X (Unix), system, and when I tried to run it normally, all it gave me was this error message:

A Linux wget command shell script

Linux wget command FAQ: Can you share an example of a wget command used in a Linux shell script?

Here's a Unix/Linux shell script that I created to download a specific URL on the internet every day using the wget command. Note that I also use the date command to create a dynamic filename, which I'll describe shortly.

How to download files with the Linux wget command

Linux wget FAQ: Can you share an example of the Linux wget command?

Suppose you're working on a Unix or Linux machine remotely through an SSH session, and then you need to get a resource (like a tar or gzip file) that's on the Internet over to that machine. You could download that file to your local machine, and then use scp to copy it to your remote Unix box, but that's a lot of work.

How to use `curl` to get headers from a URL

Curl FAQ: How do I use curl to get the headers from a website URL?

Short answer: Use curl's -I option, like this:

$ curl -I URL

Here's a specific example, including a real URL and results:

Linux free memory: How to show the free memory on a Linux system

How do I show the free memory on a Linux system?

You can show free memory on a Linux system with the free command, like this:

free

That command returns results like this:

            total       used       free     shared    buffers     cached
Mem:       8145044    8097552      47492          0      74252    1189464
-/+ buffers/cache:    6833836    1311208
Swap:     12578884    6205424    6373460

If you prefer to see information in MB you can use the -m parameter, like this:

How to install Java, Scala, and SBT on Linux Mint

Lately I’ve been in the process of “making the switch” from macOS to Linux Mint, and to that end, I just installed the Java 8 JDK/SDK, Scala 2.12, and SBT 0.13 on a new Linux Mint system, and I want to note here how I did that while it’s still fresh in my mind. Here are my notes in a compact form.

Update: Possible alternative

I haven’t looked into this yet, but it may be possible (and easier) to install OpenJDK rather than Oracle’s version of Java (which I describe below). I describe that process on my notes on how to configure a new Ubuntu server, but the basic command to install the OpenJDK JRE is:

apt-get install default-jre

and the command to install the OpenJDK JDK/SDK is:

apt-get install default-jdk

Linux gzip: How to work with compressed files

If you work much with Unix and Linux systems you'll eventually run into the terrific file compression utilities, gzip and gunzip. As their names imply, the first command creates compressed files (by gzip'ing them), and the second command unzip's those files.

In this tutorial I take a quick look at the gzip and gunzip file compression utilities, along with their companion tools you may not have known about: zcat, zgrep, and zmore.

Installing security updates only with CentOS yum

If you want to install only security-related updates to your CentOS Linux installation using the yum command, it looks like the yum-plugin-security plugin might be a good option. (I’m having a few problems with it at the moment, so I can’t say that this is the absolute solution.) I found it on this page and this page.

My vi/vim tutorial goes over 200,000 views

Way back when I lived in this low-income apartment complex in Wasilla, Alaska — technically I had no income at the time, and it’s ridiculously hard to find a place to live in Alaska in the summer — and spent as much time as I could meditating in the mountains, I created a vi/vim editor video tutorial and put it on YouTube. I just noticed that video has now exceeded 200,000 views. It feels a little weird to think that over 200K people have started to learn vi/vim from that video.

A funny thing about making that video is that the walls in that apartment complex were paper-thin. I could hear everything my neighbors did in their apartments (use your imagination and you won’t be wrong), and they could hear me, so I intentionally tried not to talk too loud in the video. I had to edit the video at several points to crop out some of my neighbors yelling at each other.