Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Monday, 30 July 2012

JQuery Accordion Style vi Cheat Sheet

JQuery LogoOver the weekend I was able to complete an accordion style vi cheat sheet using JQuery on the Tools section of my web site. It is based on a really good cheat sheet that is linked at the bottom of my page. I just added some style changes, reordered it and made it expand or collapse sections.



If I can find the time, I'll try to make a offline version of the cheat sheet using HTML5.

Tuesday, 1 November 2011

Bash Command Line History Tricks

Linux LogoThis week in a training course I was using a Red Hat based Linux that had the up arrow assigned to taking a snapshot of the screen. Since I like to use the up and down arrows to navigate command lines in the Bash shell this was a bit of a bummer. However, I vaguely remembered some alternatives. Here is what I find.



EMACS Commands

By default Bash supports the use of EMACs commands to navigate through your command line history. You can move backward through the command history using Ctl-p and move forward through it with Ctl-n. Pretty much replaces the arrows.



In addition, I found out you can use Ctl-r to search through the history. After typing Ctl-r, enter the letters you are searching for and the command that best matches, is displayed. You can also modify the matched command line.



History Commands

In addition to EMACs, there are a number of commands that work with the command line history. You can use !! to run the previous command and !3 to run the command on line 3 of the history list.



I also figured out if you echo the command, (e.g., echo !5) you can use Ctl-p to go back and edit the line.



Movement Commands

Ctl-p - Display previous command line

Ctl-n - Display next command line

Ctl-a - Move to the start of the line

Ctl-e - Move to the end of the line





Search Command Lines

Ctl-r - Searches backward through the history for the letters you type

Just start typing the text you are searching for. The closest match will be displayed. The matched command line can be edited and modified.



History Command



history - Display the command history

!! - Repeat the last command

!# - Repeat the line number in the history

echo !! - Echo the previous command to standard out


Wednesday, 18 May 2011

How to Find and Stop a Stuck Process in Solaris

Sometimes an application in Solaris gets stuck when it does not exit properly. For example, you exit a GUI application in Solaris. When you try to start the application, nothing happens. The application was just working. What the heck?



Typically this is a symptom of an application that did not exit properly and is still running. So how do I find the application and stop it? Here's how.



(1) To look at all the running processes on Solaris use this command:

ps -ef



This gives you a big list of all running applications. However, we can make things a lot easier. Let us say firefox did not exit cleanly.



So to search just for firefox processes, use grep. For example:

ps -ef | grep firefox



This will show all the running firefox processes. Note the process number for each process. For example, process 5555 is stuck.



To stop it, use the kill command:

kill -9 5555



Repeat the kill command as necessary if there are other stuck processes.



To make sure the stuck process has been removed use ps with grep again.

ps -ef | grep firefox



There should only be a listing for your grep command line.



That's it.

Monday, 4 October 2010

Ever want to Customize VIM?

Linux LogoHave you ever wanted to customize VIM but you have no idea where to begin? Check out: How I boosted my VIM



It will at least give you an idea of what you can do.

Tuesday, 14 September 2010

A Real Linux/Unix Terminal for Windows with Cygwin

Linux LogoIf you have not heard of it before, Cygwin is a set of Linux/Unix utilities made to run on Windows. Cygwin includes a plethora of tools including databases, programming languages, and command line utilities. But what I use it for mostly is to have a bash shell for Windows. That allows me to use most of the aliases, symbolic links, and other tricks I use to navigate Linux or Mac OS/X on Windows. It also makes file manipulation a lot easier.



The default Cygwin installation uses the same command window as the Windows command prompt. Which is a little clunky, to say the least. Specifically, cutting and pasting text is a pain in the rear. You have to jump back and forth to the menu to cut and paste text. It is slow, clunky, and annoying.



The solution. Install rxvt with Cygwin. This is a terminal emulator that gives you all those cool cut and paste shell features on Windows. Just install rxvt from the shell options as part of your Cygwin install. Then, create a batch file like this in your Cygwin directory.



@echo off

C:

chdir \cygwin\bin

start rxvt -sr -sl 10000 -fg white -bg black -fn Consolas-20 -fb Consolas-20 -fm Consolas-20 -tn cygwin -e /bin/bash --login -i






I called my file, term.bat. Run the bat file and you get a bash shell and window that behaves just like it would on Linux or a Mac. Yays!



Credit to c2.com for a pointer that got me started on this.

Friday, 18 June 2010

Win7Tip: Change File Time Stamps with Cygwin and Touch

Problem: I need to change the time stamp of Windows files, but I don't what to buy or install some silly shareware application.



Solution: Install Cygwin and use the Unix touch utility to modify the timestamp.



  1. Start Cygwin.

  2. Change to your C: drive: cd /cygdrive/c

  3. Navigate to your file.

  4. Use the touch command.

  5. For example, set the date to Jan 6, 2010 at 4:20pm:

    touch -d '6 Jan 2010 16:20' myfile.txt



That's all there is too it.

Tuesday, 23 February 2010

Unix: Add a User Account in Solaris

Since it seems like I have to set up a new Solaris VM every year or two, adding a new user is a part of the process. So instead of having to look this up again, I thought I would write down the steps this time.



  1. Log into Solaris as root

  2. Type the following command to add a user:



    useradd -d /export/home/username -m -s /usr/bin/bash -c "User Full Name" username

  3. The -d option specifies where to create the users directory. The -m option actually creates the directory if it does not exist. The -s option sets your default command line shell. -c sets the users full name. The new username is the last option on the command line. This sets up the account, but does not set the password.

  4. To set the password type: passwd username

  5. When prompted enter the new password twice.

That's it. You should have a new user account all set up. Log out as root and you can log into your new account.

Tuesday, 8 December 2009

Word Wrap in Linux/Unix/OS X



Have you ever needed to word wrap a text document at a specific width?  Well I did and I found out there is a Unix utility that called fold that does this. Check out an explanation on the nixCraft blog.

Monday, 23 February 2009

tar: write error: unexpected EOF

I got this error trying to tar up a file on Solaris 10: tar: write error: unexpected EOF. So what does it mean?


Well, the most likely cause is the Unix file system you are trying to write too is full. Since the operating system can not add any more files to the tar, you get this error.


On Solaris, to see how much space you have on a file system, just type: df -k. This gives you a list of filesystems and shows by percentage how full they are.


To fix the problem, either free up space on the file system you are trying to write to, or write to a filesystem that has the free space you require.


Decided to write this post because the explanations on Google for this were mostly really lame. Back in the day, doing tech support, the most important lesson I learned was, check the most obvious cause first. About 90% of the time, the most obvious cause for the problem, is the cause of the problem.

Thursday, 14 August 2008

Getting an Approximate File Count

A quick Unix tip I thought I should share. If you need to get an approximation of how many files are in a directory and its subdirectories, the du command is a great help. By default, to use the du command you would type something like this:


du .


This command lists all the subdirectories of the current directory and their size in 512 byte blocks.


The following is a more useful version of the command.


du -ak .


That command lists all the subdirectories and files in the current directory and lists their size in kilobytes. This command can be very useful when used with grep to do quick searches.


Finally, if I want to get a line count, I add the following:


du -ak . | wc -l


The wc -l command counts the number of lines in the output of the du command. Since there is one line per directory and file its not an exact file count, but it can be real useful for quick comparisons and the like.



Thursday, 5 June 2008

vi not working with OS X Terminal

I was just doing some troubleshooting on an old Solaris box from my Mac. After sshing in, I tried to use vi to edit a file and the system told me it didn't understand my terminal. By default, OS X sets the terminal to TERM=xterm-color.



To get vi working, simply set the term to an old terminal type like a vt100. That was a pretty standard type back in the day. To do this at the command line type (i'm using the bash shell):

export TERM=vt100



That seems to fix things up. I think the ansi terminal is based on a vt100. Not sure though. If anyone knows, please post a comment.