The key files that may be read during login include:
A shell is a program that is used by a user to communicate with the operating system kernel. The default shell for MSDOS is 'command.com'. The shell has two main jobs:
Linux has several popular shells including:
Hierarchical file system
The files in a system form a hierarchy as in MSDOS, but unlike MSDOS there is, usually, only one file system on a computer running Linux. The single file system may be distributed across more than one physical disk drive. Within the file system each user:
The following symbols represent important directories and can be used in commands:
Each Linux file has a filename that can have a maximum of 255 characters (depending on the file system in use). If the file is not in the current directory, the directory in which it is located is also required to give a full file specification. e.g.
Many characters have a special meaning in Linux and should not be used in filenames. The safest characters are :
Filenames are case sensitive - FRED, Fred and fred are different names.
The initial Linux prompt appears as:
At the prompt type in your account name. Different systems require different actions to achieve the 'login' prompt. After typing your account name at the 'login' prompt, you will be asked to enter a password.
Type in your password - note that it does not appear on the screen as you type it. If your password is entered correctly, a shell is loaded and a prompt displayed.
The command to leave the system depends on which shell you are using:
|Any - EOF code|
^D (Control + D)
^D is the Linux end of file character and will cause the shell to terminate, thus ending the login session.
If you are not sure which shell you are using type:
Linux commands lines, typed at the shell prompt, have the form:
command [Options] [Arguments]
Arguments are usually files and/or directories. Many commands require a list of one or more files to process. These files are mostly used only as input data and are not changed by the command. If a command requires input data and no files are specified, the command will read from the keyboard.
Options are preceded by a '-'. Most commands have several options which alter the output produced. Options can be listed separately or grouped together:
ls -l -tis the same as
Commands for creating, removing and changing to directories are very similar to those used in MSDOS:
|change directory to $HOME - the user's login directory|
|make the specified directory current|
|create a new directory|
|remove a directory|
A Linux shell interprets * and ? as wild cards in the same way that the MSDOS shell 'command.com' does.
The pattern [...] matches any characters placed inside the brackets
echo is a useful command that displays its arguments on the screen. It is especially valuable for experimenting with the meaning of wild card and other characters. Try:
echo hello world! echo * echo .*
Linux supports pipes and input-output re-direction using the same symbols as MSDOS.
Some of the more frequently used commands and options are introduced in this section. Refer to 'Commands reference' for more detailed descriptions.
List - ls
A list of files and sub-directories can be obtained using ls:
A more detailed listing can be obtained with the l option:
Concatenate - cat
To look at the contents of a (text) file type 'cat filename' e.g.
In general cat takes a list of files as input and displays them one after another. If no filenames are provided, cat will read from the standard input, the keyboard, until Ctrl-D (end of file) is entered.
Page - pg
Larger files may disappear off the top of the screen before you can read them. Either use Ctrl-S and Ctrl-Q or use pg
The pg command can be used to scroll through the file. At the : prompt type h for help. pg is often used with pipes:
ls /usr/bin | pg
Copy - cp
To make a copy of a file 'cp oldfile newfile' e.g.
cp .profile prof
Move a file - mv
This command performs the same function as MSDOS ren: 'mv oldname newname' e.g.
mv prof new.prof
mv can also be used to move a file from one directory to another.
mkdir spare mv new.prof spare
Remove a file - rm
This command performs the same functions as MSDOS del:
Linux assumes that you know what you are doing. It may not ask for confirmation, even for *, unless the -i (interactive) option is used. Take care.
Carry out the following operations and make a note of the commands used:
ls -l /usr/bin > junk
ls .*what is happening here?
The find command is a very useful tool for searching the file systems for files and carrying out actions on them. It takes the form
find <start from> <pattern type> <pattern> <action>The default action is to just list matching files. For example:
find . -name *.txtSearches the file system, starting from the current directory, for files ending in '.txt'. This example finds all files in the system that have been modified in the last day:
find / -mtime 1You can avoid a lot of error messages by su'ing to root before trying these.
The grep command is a very useful tool for patterns within text files. It takes the form
grep <pattern> <file list>For example:
grep "fred" *.txtSearches for the pattern fred in files ending in '.txt'. If the pattern expression is simple, as in this case, the quotes can be ommitted. This example finds all in the directory /etc and sub-directories that contain the pattern "eth0".
grep -R eth0 *
|ls||list names of all files in current directory|
|ls filenames||list only the named files|
|ls -t||list in time order, most recent first|
|ls -l||list long; more information; also ls -lt|
|ls -R||list recursive|
|ls -a||list all files, including names starting with . (normally hidden)|
|cp file1 file2||copy file1 to file2, overwrite file2 if it exists|
|mv file1 file2||move file1 to file2 (rename), overwrite file2 if it exists|
|rm filenames||remove named files (delete)|
|cat filenames||print contents of named files (type)|
|wc filenames||count lines, words and characters for each file|
|wc -l filenames||count lines for each file|
|echo args||print arguments on the\screen|
|sort filenames||sort files alphabetically by line|
|tail filename||print last 10 lines of file|
|tail -n filename||print last n lines of file|
|tail +n filename||print file starting from line n|
|cmp file1 file2||print location of first difference|
|diff file1 file2||print all differences|
|cd||change directory to $HOME, login directory|
|cd path||change to specified directory|
|cd ..||change to directory above this one|
|pwd||print working directory, current|
|mkdir dirname||create a sub-directory|
|rmdir dirname||remove a sub-directory|
|find ...||Search for files|
|grep pattern files||Search files for text patterns|