The 15 Essential UNIX commands

applelinuxmisc

Learning UNIX is a seemingly daunting task, there are thousands of commands out there, each with hundreds of options. But in reality you only need to know a few of them.

I use unix quite a bit, usually either on one of our Linux servers, or on my Powerbook with OS X. And these are the 15 commands that I use most. If you can memorize these 15 commands, you can do quite a bit on a unix operating system, and add unix as a skill on your resume.

The 15 Most Important UNIX commands

  1. man - show manual for a command, example: man ls hit q to exit the man page.
  2. cd - change directory, example: cd /etc/
  3. ls - list directory, similar to dir on windows. example: ls /etc, use ls -l /etc to see more detail
  4. cp - copy a file or directory, example: cp source dest if you want to copy a directory use the -R option for recursive: cp -R /source /dest
  5. mv - move a file, example: mv source dest
  6. rm - remove a file, example: rm somefile to remove a directory you may need the -R option, you can also use the -f option which tells it not to confirm each file: rm -Rf /dir
  7. cat - concatenate, or output a file cat /var/log/messages
  8. more - outputs one page of a file and pauses. example: more /var/log/messages press q to exit before getting to the bottom. You can also pipe to more | more from other commands, for example ls -l /etc | more
  9. scp - secure copy, copies a file over SSH to another server. example: scp /local/file user@host.com:/path/to/save/file
  10. tar - tape archiver, tar takes a bunch of files, and munges them into one .tar file, the files are often compressed with the gzip algorithm, and use the .tar.gz extension. to create a tar tar -cf archive.tar /directory, then to extract the archive to the current directory run tar -xf archive.tar to use gzip, just add a z to the options, to create a tar.gz: tar -czf archive.tar.gz /dir to extract it tar -xzf archive.tar.gz
  11. grep - pattern matcher, grep takes a regular expression, or to match a simple string you can use fast grep, fgrep failure /var/log/messages, I'm usually just looking for a simple pattern so I tend to use fgrep more than regular grep.
  12. find - lists files and directories recursively on a single line, I usually pipe grep into the mix when I use find, eg: find / | fgrep log
  13. tail - prints the last few lines of a file, this is handy for checking log files tail /var/log/messages if you need see more lines, use the -n option, tail -n 50 /var/log/messages you can also use the -f option, which will continuously show you the end of the file as things are added to it (very handy for watching logs) tail -f /var/log/messages
  14. head - same as tail, but shows the first few lines the file
  15. vi - text editor, there are several text editors such as emacs, and nano, but vi is usually installed on any server so its a good one to learn. To edit a file type vi file to edit a line press Esc i then to save changes and exit use Esc wq, or to quit without saving use Esc q!. There are a million other commands, but that will enable you to edit files at a basic level.

Once you learn these commands, and are comfortable with them, you shouldn't stop there, there are lots of other commands that can make your life easier.

Did I miss any commands that you think are essential to using a UNIX based operating system?



Related Entries

260 people found this page useful, what do you think?

Trackbacks

Trackback Address: 426/1044C08BBC36A1163BEA4CAB370DDDE8

Comments

On 07/29/2005 at 3:31:54 PM EDT Dutch Rapley wrote:
1
I prefer less to more

i.e. $cat filename | less OR you can do just $less filename

less allows you to scroll up and down, more is only one way scrolling.

another good one to keep in mind is ps

i.e. $ps -A (this shows all running processes)

chown and chmod are good to know too

On 07/29/2005 at 4:04:02 PM EDT Dutch Rapley wrote:
2
Oh yeah, one more - ln comes in handy when creating links to files, you can create symbolic links with $ln -s [source] [destination]

symbolic links are a must when creating virtual hosts on Linux, b/c the Flash forms will not work without them.

Explanation

If youre running a web server, you will probably have it configured to run virtual hosts. This may create an issue, if youve decided to use CFMX 7s Flash forms. Flash forms reference files in the {virtual host webroot}/CFIDE/scripts directory. The CFIDE directory is located in the directory you specified upon installing ColdFusion MX 7. When you create a virtual host, the CFIDE directory doesnt exist for the virtual host. Here, there are two things you DO NOT want to do.

1. DO NOT copy the CFIDE directory to your virtual host directory. When coldfusion is upgraded, changes that may occur will not be implemented in files that your virtual host may reference. Copying CFIDE will also allow access to the CF administrator from your virtual host 2. DO NOT explicitly create a symbolic link to the CFIDE directory. This will allow access to the CF Administrator from a virtual host, which should be avoided at all costs.

The best solution is to create a CFIDE directory in your virtual hosts, and then create a symbolic link to the CFIDE/scripts directory. Follow the steps below:

1. go to the directory of your virtual host 2. $mkdir ./CFIDE 3. $ln s ./CFIDE ./cfide 4. $cd ./CFIDE 5. $ln s {path to default host}/CFIDE/scripts ./scripts

Note: By default, Apache may not resolve symbolic links. If your apache installation doesnt resolve symbolic links, youll need to make the change in the apache configuration file.

On 07/29/2005 at 6:44:14 PM EDT Anonymous wrote:
3
cut is another good one.

On 07/29/2005 at 9:51:31 PM EDT mike wrote:
4
ps is a good one and kill is very helpfull oh and df. theres always hostinfo hostinfo Mach kernel version: Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; root:xnu-792.2.4.obj~3/RELEASE_PPC Kernel configured for up to 2 processors. 2 processors are physically available. Processor type: ppc970 (PowerPC 970) Processors active: 0 1 Primary memory available: 4.00 gigabytes Default processor set: 127 tasks, 433 threads, 2 processors Load average: 0.43, Mach factor: 1.56

On 07/29/2005 at 9:52:47 PM EDT kon wrote:
5
one I use all the time is TOP givs you a list of processes that might be taking up CPU.

Also another must know is KILL use it with TOP to get the Process ID and use that with the KILL command

On 07/30/2005 at 12:53:26 AM EDT Rajneesh Gag wrote:
6
Check out http://rgarg.blogspot.com/2005_07_26_rgarg_archive.html for a few more UNIX commands.

On 07/30/2005 at 3:16:55 AM EDT nixer wrote:
7
For novices, this is a good site to bookmark; http://unixhelp.ed.ac.uk/

On 07/31/2005 at 8:49:04 PM EDT HKS wrote:
8
Don't forget to mention that commands can be chanined together.

For example: tail -f foo.log | grep "[ERROR]" will stream a log file, showing only lines that have "[ERROR]" in them.

grep also has the -v option, that inverts the match. So: grep -v "[ERROR]" will show you all lines that don't have "[ERROR]" in them.

Oh, and don't forget that on most linuxes, more is actually less, and vi is actually vim :D

On 08/01/2005 at 9:33:16 AM EDT Patrick McElhaney wrote:
9
I haven't used Unix in years, but isn't chmod fairly critical?

On 12/19/2005 at 10:02:57 AM EST mihaic wrote:
10
16) $pwd 17) $logout ( maybe CTRL+D)

On 12/31/2005 at 6:22:17 AM EST Brad wrote:
11
For RH boxes, "locate" may be a good addition. Can replace find for the quite and simple searches. Only downside is it requires a database for searches and may require updating multiple times a day. Still pretty quick once it is good to go. By the way, how you liking the new server?

On 01/03/2006 at 9:53:48 AM EST doof wrote:
12
Ctrl+C to cancel your current task is always useful, i tend to use it when i get scared because something is taking too long! :)

On 02/14/2006 at 10:16:08 PM EST Trullo wrote:
13
what about sed, awk, tr? i cant be alive without them!

On 03/03/2006 at 1:31:29 PM EST Rob Wilkerson wrote:
14
Personally, I use 'locate' on a daily basis - both on my Linux machines and on my Windows box (via Cygwin).

Maybe my memory just isn't what it used to be, but having a quick way to find out where a file is often proves invaluable.

Following on Brad's comment (from 2 months ago), I update the locate database via cron job every morning @ 3am. That keeps the database current enough for my needs.

On 03/15/2006 at 2:05:46 PM EST jose wrote:
15
I think "apropos" should be number 2 after man. It is essential for finding commands to do tasks that you want to do, when you don't know the proper command.

On 09/05/2006 at 3:23:19 AM EDT Raja wrote:
16
Hello guys i am a new to this unix i want to know is there any command like than who am i other than whoami, please if any body knows please inform me.

thanks and regards raja.p

On 09/05/2006 at 3:14:39 PM EDT Rob Wilkerson wrote:
17
Look at "w" and "who". Each gives a variation of the same information. Is that what you're looking for?

On 12/06/2006 at 5:24:09 PM EST Anonymous wrote:
18
What about 'Comments"

On 01/03/2007 at 5:34:40 PM EST duane wrote:
19
I'm looking for a means to 'copy 400 lines of a file into a new file beginning at line n'. Used for: a log where an exception was thrown... to move this data to a local file, share it with collegues or for quick reference. I thought a solution would include less -n ### > newFile.txt. Then scpy the new file to a local drive. But how do I get the # of lines to be limited to 400?

On 01/03/2007 at 8:53:34 PM EST tunaranch wrote:
20
You can head (or tail) -n 400 to get the first (or last) 400 lines.

On 01/04/2007 at 7:41:54 PM EST max wrote:
21
You must know "ps" and its variants to handle hung processes.

On 10/13/2008 at 3:30:46 PM EDT sangramsinh.takmoge wrote:
22
Hi Everybody! Is there any command in Unix to Undo the effect of previous command. say, I do rm *.* on the root (!!) and then wish I could Undo this?

On 10/13/2008 at 3:38:44 PM EDT Rob Wilkerson wrote:
23
Nope. "Undo" isn't really part of the Unix lexicon. The OS is generally optimistic and assumes that you know what you're doing.

On 11/21/2008 at 10:01:06 AM EST A wrote:
24
Less is far greater than more ;)

I use 'less' with tailing/following ('F') far more than 'tail -f' because I always have the option of stopping following and just browsing through the file (great for log files).

That said, I think less originated with GNU, so it may not be accross-the-board Unix per se.

On 12/04/2008 at 8:37:38 PM EST amalan wrote:
25
hello, i want to run two commands in a single line. is there any command to run two commands in a single line. i don't want to merge two commands using | pipe. but i want to run both seperately. thank you!

On 01/08/2009 at 5:51:13 AM EST Jason wrote:
26
Following on tunaranch's idea of using "head (or tail) -n 400 to get the first (or last) 400 lines", what if u want to insert 400 lines in between the entire file into a new file(not necessarily beginning or end). Any ideas?

On 03/31/2009 at 4:10:02 PM EDT Tom wrote:
27
Jason:

head -500 filename | tail -400

where the first record is #101, i.e. skips the first (500-400) records.

On 09/08/2009 at 5:48:17 AM EDT sudheer wrote:
28
what about $history command..? i think it shows only last 500 commands only but i want to see all over the commands,which are i typed still now...

On 10/22/2009 at 9:36:48 PM EDT Smith wrote:
29
mkdir you have to know how to make a directory

On 03/31/2010 at 12:06:33 PM EDT Deepak kr Sharma wrote:
30
In unix ps shows the process.if u want to show only process for perticuler term then u can use ps -t and every all process wih full listing you can use ps -aef .

On 10/31/2011 at 4:37:09 AM EDT Anonymous wrote:
31
I need all basic unix commands for dba with full description

On 10/26/2012 at 2:43:27 AM EDT sarenza kickers wrote:
32
The sister aren't a mate, nevertheless a mate will almost allways be some sister. sarenza kickers http://www.chile62sarenza.com/

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?