|
Navigating the directory tree and listing filesLast revision August 3, 2004
One of the attributes of any process, including your login shell, is that it has a working directory. That is, files referenced by commands and programs are assumed to belong in that directory unless you explicitly indicate another directory. Here are descriptions of basic commands that you use to show, set, and list your working directory. pwdTells you the name of your current working directory. There are no arguments to this command. Use anytime to verify a directory change or just see where you are.
cdUsed to change your working directory. Give it a single argument which is the name of the new directory that you want to set as your working directory. Can give a relative pathname, which means to go further down the directory tree from current position. In this case, do not start relative pathname with a slash; rather, start it with the name of the next sub-directory in line. Or can give an absolute pathname. Start this with a slash, and then specify all the sub-directories in the path beginning from the root directory. If you do not give any pathname argument at all, cd just returns you to your own home directory. Relative and absolute pathnames are concepts used by all commands that refer to files. Use ../ followed by a sub-directory name in order to move over to another sub-directory at the same level (remember that .. is a reference to the parent directory of the current directory).
lsUsed to display a list of the files within a directory. If no options are given, ls lists the files in the current working directory. If one or more directory names are given as filename arguments, ls will list the contents of those directories. If specific filenames (either relative to the current directory or with an absolute pathname) are given as arguments, ls will list them if they exist - one way to see if a file exists, or to get more information about it. When invoked without any options, ls just shows the names of files, usually in several columns to conserve space on the screen. The most useful option is -l (letter "ell", not numeral "one"). This gives the long listing, which has complete information about the file. Note that the exact format of the ls -l command output may differ slightly from one system to another. Like most Unix programs, the output from the ls command is terse and contains no explanatory headers. You need to reference the on-line manual or notes like these to explain the meanings of the various columns of output. For example, in the gp111ins home directory on pangea, the command pangea> ls -l symlink.awk yields the output: -rw-r--r-- 1 gp111ins class 115 Oct 29 1987 symlink.awk The output of the ls -l command is interpreted as:
Other options to
ls
provide different types of information.
You can combine several options, either separately listed, like -a -l, or with concatenated letters, like -al.
Other potentially useful options are those that sort the output list before
displaying it. Output is normally sorted alphabetically by filename. Usually,
you would use these in conjunction with the
-l
option so the relevant sort field is displayed.
fileMakes a guess to determine the type of contents of a file. Its argument is a list of files or directories, either relative or absolute pathnames. It then looks at the first few bytes of each file and tries to guess whether the file is a directory, an executable command, a C program, a Fortran program, numeric data, English text, etc.
|