Archive for the 'Unix' Category
Posted in Mac, Unix | Wednesday, May 6th, 2009 | 2 Comments »
If you're new here, you may want to subscribe to my RSS feed.
If you’re ever using Emacs (Extensible Macro System) as an editor and feeling bored, you can always play Tetris in it. Playing Tetris in Emacs only works in the GNU environment which Mac OS X also runs under. The steps for running Tetris in Emacs have been provided below:
- In Terminal, type
emacs at the comment. Emacs will then appear for you.
- In the Emacs window, press <ESC>. This will bring you to the note buffer section (shown below).

(more…)
Posted in Lessons, Unix | Tuesday, March 10th, 2009 | No Comments »
Having trouble finding a needle in a haystack? You can always use grep --color to find what you are looking for. This method is best used for finding a specific piece of text in a document that is all on one line, or a unique string of text within a repetitious document. I have provided the syntax for this grep option below:
grep --color "text" filename
Example:

Posted in Lessons, Unix | Wednesday, February 4th, 2009 | No Comments »
The commands listed in this post are more for Linux than Unix. To find out information about the hardware of your computer, you can run an lspci command. Lspci will output the specifications of your hardware in a list style arrangement as shown below:

If you want to get more specific in your lspci output (e.g. wanting just to display a certain brand), you can always do lspci | grep -i "Productname" which will only return results that includes the string from your grep command. For example, if I wanted to find all of the hardware made by Broadcom, I would do lspci | grep -i "broadcom" and the results would return only hardware that mentions Broadcom.
(more…)
Posted in Lessons, Unix | Thursday, January 22nd, 2009 | 1 Comment »
Have you ever tried to grep in a directory that has a vast amount of files and you received an error like this? (below)

If so, there is a simple way around this. Just use this: find . | xargs grep "yahoo" * | more. I will break down these processes for you:
find . - Find is a command that outputs the location of a file. In this case by specifying a ., the search will only be done in the present directory.
xargs - This allows a command to be executed from standard input. This also helps force the grep command (coming next) to return output, even when the directory is too large.
grep - The way we will be using this command is to search through a file for a specific string. If you are looking for straight text, it is best to use quotes (e.g. “text”) to help the command line decipher exactly what you are looking for. More info on grep can be found on this earlier post.
more - This command is optional for this process. More would be best used if you were expecting a full page of output returned from your search, and want to be prompted for the next page. This option would be very beneficial if the string you are searching for would be common in your results.
Posted in Definitions, Lessons, Unix | Thursday, January 8th, 2009 | 2 Comments »
Ever wanted to use a command to do something, but couldn’t quite figure out the actual command to accomplish what you need done? Try using apropos! Apropos is a way to browse through the help area of the Unix/Linux operating system for a command that will help achieve your goal. For example, if I wanted to find commands that relate to “secure”, I would enter apropos secure at the command line, and the kernel would return the results listed below along with any services that involve ’secure’:

As always, if you wanted to get a more elaborate description on a command or service, you can always use man (shortened for: manual). This will display a full description, and various options of a command which you have found using apropos.
Posted in Lessons, Mac, Unix | Thursday, October 16th, 2008 | 2 Comments »
The alias command is very useful. It is kind of a shortcut in some ways. I get tired of tying ls -la so I can see all the info for my files so what i do is type alias ls 'ls -la'. What this command does is that it sets up an alias so that every time I type ls the computer treats is as though I typed ls -la. There are many other things you can do also. Say you have a long command you run a lot. You can alias it to something like mc.
Ex: alias mc 'locate log_error | grep -R 192.168.1.1 *'
Your command can be as long or as short that you want to alias. I also use it to setup ssh connections.
Ex: alias con1 'ssh usrname@192.168.1.1'
Now any time I type con1 it will try to make an ssh connection to that ip address.
Posted in Lessons, Mac, Unix | Tuesday, August 12th, 2008 | 4 Comments »
The diff command is a very useful command to see the differences between two files. An example of this command would be
diff file1.txt file2.txt
It takes file2.txt and compares it to file1.txt and displays the differences that are in file2.txt. You may also want to use the -b options in the command because that will allow it to ignore differences in white space. This command is very useful in programming when you have a backup version of a script that you just modified. If the script no longer works it can help you track down bugs, by looking at backup version of the script that does work.
Posted in Lessons, Mac, Unix | Monday, June 16th, 2008 | 2 Comments »
Today we are going to look at a command that you don’t use very much in a Unix environment. The kill command. It is used when an application is stuck or not responding. The basic form of the command is kill [option]… PID. The PID is the process ID, you can get it by using the top command that I talked about previously. The most common option for the kill command is the -9 option. It will kill the process immediately.
Example
kill -9 2342
If you type top again you should see that the process that was associated with that PID is no longer running.
Posted in Lessons, Mac, Unix | Thursday, May 1st, 2008 | No Comments »
Top is a great command when you are trying to see all of your running processes. It also gives a great deal of other information. It is broken down into four categories - tasks, cpu, mem, and swap. Tasks tells you about the processes that are running. Cpu tells you your processor load. Mem tells you about the total memory you have, how much is being used, and how much is free. Swap Is just like mem except it deals with your swap partition.
Below, you will see all the processes that are running on your computer. It gives most of the info about the processes that you will ever need to know. The main columns I focus on are PID, USER, %CPU, and %MEM. They are to me the most useful. PID is the process ID which is very useful when a program freezes. USER is who is running the program. %CPU is the amount of processing power the program is using. %MEM IS the amount of memory the program is taking up.
Top by itself only gives you information on what is running, but when you combine it with other commands, it makes it very powerful. We will get into that next time.
Posted in Lessons, Mac, Unix | Friday, April 4th, 2008 | 1 Comment »
To accomplish this I am going to show you a new command and then use | and grep with it. The command is locate. Your computer has a database that has the path names and files that are publicly accessible on your computer. Locate searches that database for all the pathnames and finds the one you are looking for. It is probably the easiest command to remember and use. You just type locate then what you are looking for.
Example:
locate report
You can also search for all files with a certain extension.
Example:
locate '*.jpg'
You may be saying why would I want to do such a specific search? Well lets say you are a web designer that need to modify a template file for all your websites that contain a certain function. Say the function was called capcha and all your template files end in .tpl. You would use you the | command to combine the two function together to accomplish this.
Example:
locate '*.tpl' | grep -R 'capcha' *
This works by running the locate command and then using grep on just the file names that locate returns. Yes you could just type grep -R 'capcha' *, but you would have to be in the root directory of your hard drive and the grep command would search every file on our computer. That would take a long time to complete, and if you are running the search on a web server you could bring it to its knees.