Manuel Amago: UnixBasics

Making life taste better…


Page actions: RecentChanges | PrintableView | PageHistory | EditPage



Contents


Introduction

Unix is an operating system, or family of operating systems, characterised by the use of a hierarchical file system, plain text files and a shell or command line interpreter. It also makes use of a number of small specialised programs that can be easily combined using pipes and filters to execute complex tasks.

Pipes and filters

A pipe is a way of connecting programs by passing the output of one program as the input into the next program. This allows you to combine programs in a simple way to achieve complex tasks. A pipe is written as a vertical bar '|'. So to pass the output of the cat command into the more command you would write: =code cat | more

A filter is a program that manipulates its input. One of the simplest examples is the grep command. The grep command reads each line of its input and searches it for a given word or pattern, if the pattern is found it prints out that line, otherwise it ignores it. So, for example, if you wanted to search all files in a directory for those containing the word 'today' you could do that as follows: =code ls | grep today

Essential commands

ls

Lists the files in a given directory. The ls command can also take arguments for sorting the files (by name, size, date and time, …), listing additional file details, listing directories recursively, and much more.

For more information on the ls command, type man ls at a Unix command prompt.

cat

Once you have found the command you are looking for by using the ls command, you can view the files contents using the cat command.

The real use of the cat command is to concatenate (to join) several files together. Passing only one argument to cat causes it to display the contents of that single file. However, you will find that if the file is larger than the display you are using, the file will scroll quickly before your eyes and you won't be able to really see the contents. For proper browsing of the contents of a file more appropriate commands are more or less.

more

more is used to view a file in a paginated way, one screen at a time. When more display's its input, it will output as many lines as can fit on one screen of the display, and then prompt the user for when to display the next screen of data. Traditionally, more only allows for forward navigation in a file, so once a screen of data has scrolled off the display you won't be able to go backwards to see it again. Newer version of more do allow limited backward movement, as well as search capabilities.

less

The less command does much as the more command before it and displays paginated input. less fills in for more's weaknesses and allows full forward and backward pagination through files, and a number of other nice to have's like searching, etc.

find

grep


Page actions: RecentChanges | PrintableView | PageHistory | EditPage