|
Software
Files Different types of file
Directory Shell
Networking Reference
|
Different types of fileTo the user, it appears as though there is only one type of file in UNIX - the file which is used to hold your information. In fact, the UNIX filesystem contains several types of file.
Used to store your information, such as some text you have written.This is the type of file that you usually work with.
This type of file is used to represent a real physical device such as a printer, tape drive or terminal. It may seem unusual to think of a physical device as a file, but it allows you to send the output of a command to a device in the same way that you send it to a file. For example: cat scream.au > /dev/audio This sends the contents of the sound file scream.au to the file /dev/audio which represents the audio device attached to the system. The directory /dev contains the special files which are used to represent devices on a UNIX system. /dev/null There is a special device know as /dev/null to which you can redirect unwanted output. This is a null (non-existent) device represented by the file null in the directory /dev . To carry out a conditional action: if who | grep -s keith > /dev/null then echo keith is logged in else echo keith not available fi This lists who is currently logged on to the sytem and pipes the output through grep to search for the username keith. The -s option causes grep to work silently and any error messages are directed to the file /dev/null instead of the standard output. If the command is succesful i.e. the username keith is found in the list of users currently logged in then the message keith is logged on is displayed, otherwise the second message is displayed.
UNIX allows you to link two or more commands together using a pipe. The pipe acts a temporary file which only exists to hold data from one command until it is read by another. The pipe takes the standard output from one command and uses it as the standard input to another command. command1 | command2 | command3 The | (vertical bar) character is used to represent the pipeline connecting the commands. For example : To pipe the output from one command into another command: who | wc -l 342 This command tells you how many users are currently logged in on the system: a lot! The standard output from the who command - a list of all the users currently logged in on the system - is piped into the wc command as its standard input. Used with the -l option this command counts the numbers of lines in the standard input and displays the result on the standard output. |