linux-unix

recent posts related to linux and unix

The Linux top command

I was just writing a friend about how to use the Linux ps command, when I thought why bother, what he really needs to see right now is the Linux top command. The Linux top command is an interactive utility that displays a character-based screen of all processes running on the current system. The screen updates itself every few seconds, and you can sort the screen contents by characteristics like CPU Usage or Memory Use.

How to create a formatted date in a Linux shell script

Linux date FAQ: How do I create a formatted date in Linux? (On the Linux command line, or more likely, in a Linux shell script.)

I just ran into a case where I needed to create a formatted date in a Linux shell script, where the date format looks like this:

2010-07-11

To create this formatted date string, I just used the Linux date command, using the "+" sign to specify that I want to use the date formatting option, like this:

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:

The Vim goto line number command

Vim FAQ: What is the Vim goto line number command?

Use the capital letter 'G' in Vim command mode to move to a specific line number. Here are several Vim goto line number example commands:

G   - go to the last line in the vim editor (last line in the file)
1G  - goto line number 1
20G - goto line number 20

 

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 Vim page up and page down keystrokes

Vim FAQ: What are the Vim page up and page down keystrokes?

Short answer:

The Vim page up keystroke is [Control][b]. You can remember the 'b' by thinking "back".

The Vim page down keystroke is [Control][f]. You can remember the 'f' by thinking "forward".

More Vim page up and page down keys

I use those two Vim keystrokes most of the time, but you can use other keystrokes in Vim to move up and down, as shown here:

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 end of line command

Vim FAQ: What is the Vim end of line command?

Short answer: The '$' key.

Longer answer: Use the '$' key in vim to move to the end of the current line. Also, you can use the '0' key (the number zero) to move to the beginning of the current line.

You can find these answers and many more in our Vim navigation video tutorial, and in our collection of Vim tutorials.

The vim copy and paste commands

Vim FAQ: What are the vim copy and paste commands?

In vim you can copy and paste content fairly easily, but being an older text editor, these commands aren't obvious. Let's take a look at how to use copy and paste in vim.

The vim copy command

In short, the vim copy command is "yy" -- the letter 'y', typed twice. This command copies the current line -- placing it in a vim buffer -- so you can easily paste it somewhere else. You use this copy command while in the vim command mode.

The vim cut and paste commands

Vim FAQ: What are the vim cut and paste commands?

In vim you can cut and paste content fairly easily, but being an older text editor, these commands aren't obvious. Let's take a look at how to use cut and paste in vim.

The vim cut command

In short, the vim cut command is "dd" -- the letter 'd', typed twice. This command deletes the current line, but places it in a buffer, so you can easily paste it somewhere else. You use this command while in the vim command mode.

Syndicate content