Posts in the “linux-unix” category

Vim insert commands

Vim FAQ: What is the Vim insert command?

Short answer: Type the letter 'i' while in Vim command mode. You'll then be able to type text into your document, right where the cursor is currently positioned.

Vim insert commands

Longer answer: There are several other variations of the Vim insert command you can use:

The Vim next file command

Vim FAQ: I've opened multiple files in Vim; how do I move to the next file?

When you have multiple files open, to move to the next file in Vim, use this command:

:n

(Just think of "next", and you can remember this Vim command.)

Or, if you want to save your changes to your current file and also move to the next file, use this Vim command:

:wn

This Vim command means "write the current file to disk, and move to the next file".

I hope these "Vim next file" examples have been helpful.

The Linux cancel command (cancel a print job)

The Linux "cancel" command lets you stop print requests from printing (cancel them).

Linux printing requests can be canceled by either (a) using the printer-id or (b) by specifying the printer name. Here are examples of each approach.

cancel laser-101

This first command cancels the print request identified as "laser-101". (You would have gotten this identifier using an lpstat command.

The Linux lp printing command

The lp command is used to print files on Unix and Linux systems. The name "lp" stands for "line printer". As with most Unix commands there are a fairly large number of options available to enable flexible printing capabilities.

Let's look at some lp printing commands examples.

Linux lp printing command examples

lp /etc/passwd

This command prints the "/etc/passwd" file to the default printer. If you do not use the "-d" option, the file is printed to the default printer destination.

The Unix/Linux lpstat command

The Linux lpstat command lets you look at the progress of your print request(s). The name "lpstat" stands for "line printer statistics".

lpstat command examples

The "lpstat" command, used with no options, may return no output if there are no print jobs queued.

The Unix compress command

The Unix compress command is rarely used any more, and has largely been replaced by the Unix/Linux gzip and bzip2 commands. However, on some Unix systems the compress command is still used, so for them, here are a few examples of how to use it.

Unix compress command examples

The following command will compress the file named foo.tar into a new file named foo.tar.Z:

The Linux pwd command (and Linux command line prompts)

Linux current directory FAQ: How do I show what directory I'm currently in on a Unix or Linux system?

Just use the Unix/Linux pwd command, like this:

pwd

If you're in a directory named /home/al, the output looks like this:

$ pwd
/home/al

If you're in a directory named /tmp, the output looks like this:

$ pwd
/tmp

That's all there is to the pwd command.

The Linux who command

The Linux "who" command lets you display the users that are currently logged into your Unix computer system.

The basic who command with no command-line arguments shows the names of users that are currently logged in, and depending on which Unix/Linux system you are using, may also show the terminal they're logged in on, and the time they logged in.

who

Since I'm the only one logged into my Linux system right now, I see output like this:

The Linux file command

Linux file information FAQ: How can I tell what type of file a file is on a Unix or Linux system?

The Linux file command shows you the type of a file, or multiple files. It's usually used when you're about to look at some type of file you've never seen before. When I first started working with Unix and Linux systems I used it a lot to make sure I wasn't about to open a binary file in the vi editor, amongst other things.

You issue the Linux file command just like other commands, like this:

The Linux more command

The Linux more command lets you view text files or other output in a scrollable manner. It displays the text one screenful at a time, and lets you scroll backwards and forwards through the text, and even lets you search the text.

Looking at a Linux file with the more command

A common way to use the Linux more command is to display the contents of a text file. Where you might normally "cat out" the contents of a text file with the cat command, like this:

The Linux copy command (cp)

Linux file copy FAQ: How do I copy Linux files and directories? (Or, Can you share some cp command examples?)

You use the cp command to copy files and directories on Linux systems. Let's look at some copy examples to see how this works.

Using Linux cp to copy files

At its most basic, here's how you copy a Linux file:

Move Linux files and directories with the mv command

Linux move/rename files FAQ: How do I rename or move Linux files and directories?

You use the Linux mv command to rename or move Linux files and directories. Let's look at some move/rename examples.

Using Linux mv to rename files and directories

At its most basic, here's how you rename a Linux file:

mv Chapter1 Chapter1.old

This mv command renames the file Chapter1 to the new filename Chapter1.old. (Renaming a file is the same as moving it.)

Refactoring - thoughts on software not growing right

It's interesting how, when a software program grows, it may not evolve exactly as it should.

I was working on my anti-spam program two nights ago, and I noticed it had this growth problem. When I first starting creating the program it was supposed to mark email messages w/ varying levels of suspicion, kind of a Bayesian algorithm. But, in practice, I found that this wan't really necessary; a message was either spam, or it wasn't.

However, as my program grew I ended up leaving code in it like this:

PHP check your libxml2 installation error

I was installing PHP on a CentOS (Linux) server yesterday (using the configure script), and ran into an error related to my libxml2 installation. Here's the complete error message that shows up at the end of the configure script output:

Linux chmod - how to make a Perl script executable

Linux chmod FAQ: Can you share an example of how to make a shell script executable with the Unix/Linux chmod command?

A lot of times in the web world you're given a Perl script by someone, and they say, "Put this script on your server, make it executable, and yada yada yada." Skipping the yada-yada part, some times people gloss over the "Make this file executable" part. So, here's a quick lesson of how to use the Linux chmod command to make a Perl script (or any Unix file) executable.

tar gzip example - How to work with files that are tar'd and gzip'd

tar gzip FAQ: How do I work with tar archives that have been created with tar and gzip?

When you work on Unix, Linux, and Mac OS X systems, you'll quickly find that tools like tar and gzip are your good friends, so learning how to work with them is very important. Here's a quick look at how to work with the most common tar/gzip scenarios.

Common vi/vim navigation commands

Here's a quick list of the most common vi and vim editor navigation commands I use every day.

Moving on the current line

Here are the most common navigation commands for moving around the current line:

The vim line wrap command

Vim FAQ: How do I configure Vim to wrap lines (or not wrap lines) of text?

Answer: To get Vim to not wrap text, issue the "vim set nowrap" command, like this:

:set nowrap

By default vim will wrap long lines in the editor, but this command changes that display, so long lines will now go off-screen to your right.

vim set wrap - how to get back to wrapping mode

Getting back to the vim editor's normal line wrap mode is also simple. Just issue a very similar "vim set wrap" command: