Beruflich Dokumente
Kultur Dokumente
(v1.0)
Unix is the operating system on the Sun computers used by faculty and students on this campus. This handout describes some basic Unix commands for manipulating files and directories. More information on the Unix environment and other basic commands are available in the BEGINNER'S SET OF UNIX COMMANDS handout.
Directory
(A.K.A. Folders) For Macintosh and Windows users, the analogous concept for the File Folder or the Folder is called the directory on the Unix systems. Directories on Unix, like their counterpart on the desktop systems, are for collecting together files and subdirectories for better organization.
Location
Your home directory was created for you when you received your NIS account. You can think of this as your main directory, where all of your data and files are to be stored. Normally, the home directory is also the location, or the working directory, where you start from when you log on to a Unix machine. Within your home directory, though, you can create sub-directories, and then, subsub-directories within your sub-directories, and so forth. Of course, your home directory itself is located within some other directory on your server machine. Moving about within a large, multi-level hierarchy like this, you would need to verify where you are from time to time. pwd Example:
uranus% pwd /c/bus/uliu6 uranus% cd mail uranus% pwd /c/bus/uliu6/mail uranus% (An example of someones home directorys location.) (Change the current working directory to mail.) (Where user uliu6s mail directory is located.)
Examples:
ls ~/ ls -al ~/mail ls -F -a
(Lists the contents of the home directory) (Lists all contents of the directory mail located within the home directory, and displays the full details.) (Lists all the contents of the current directory, with trailing / for all the directories.)
Changing Directory
The command cd is used to change the current working directory. (For instance, to go from the home directory into a sub-directory.) cd dir_name cd .. cd Goes into the named directory. (i.e. Sets current working directory to the named directory.) Goes into the parent directory. (i.e. the directory where the current directory is located within.) Goes back to your home directory. (i.e. Sets the current working directory to the home directory.)
Creating Directory
To better organize your files, it is often helpful to create sub-directories within your home directory. For example, you can create a directory called Eng101 to store all your English 101 essays, and another directory called Anth250 to store all your Anthropology 250 papers. To create a directory, the command is mkdir. Keep in mind that the Unix file system is case sensitive; Soc101 and soc101 are treated as two different names, and so you can create two directories with those names, even though you probably meant to have just one of them. To make things easier for yourself, do not use any punctuation marks or spaces for your directory name, except the underscore _ symbol.
Deleting Directories
When a directory is not needed anymore, you can remove it to reduce clutter. There are two different ways of doing this: rm -r and rmdir. Delete only items you no longer need; you will not be able to retrieve them once they are erased! rmdir dir_name rm -r dir_name Deletes the named directory, if it is empty. Deletes the named directory and all of its contents.
Moving Files
To move a file from the current directory to another, use the mv command. mv file_name dest_dir mv dir1 dir2 Moves the named file into the specified directory. Moves the directory dir1 into the directory dir2.
Copying Files
To duplicate a file in another directory, or to make a copy under a different name, use the cp command. cp file_name1 file_name2 cp file_name dir_name cp -r dir_name1 dir_name2 Makes a duplicate of the file file_name1, under the name file_name2. Duplicates the file file_name, and places it inside the directory dir_name. Duplicates the directory dir_name1, and places the duplicate in dir_name2. Or, if dir_name2 doesnt exist, the duplicate would be named dir_name2.
Renaming Files
To change a file name, use the command mv. (Note: Since its the same command for moving files, if youre not careful and specify an existing directory name instead of a new file name, you will end up moving the file into the directory instead of renaming it.) mv file_name1 file_name2 mv dir_name1 dir_name2 Renames the file file_name1 to file_name2. Renames the directory dir_name1 to dir_name2.
Deleting File
Deleting files is similar to deleting directories. The command is rm. Files erased typically cannot be recovered, so be careful. rm file_name Deletes the file named file_name.
Displays the content of the file file_name, one screen full at a time. Displays the content of the file file_name, one screen full at a time. (Note: not all users have direct access to this command by default.)
When using either command, you will need to press the space bar to advance from one screenful of text to the next. Press B to go back to the previous screen. With the less command, you will also need to press Q to quit viewing the file, whereas more will quit automatically when you reach the end of the file.
is interested in learning more about vi. Those who want learn emacs are advised to check out online information, or browse through bookstores computer sections for references. For simple tasks, though, you can use pico instead. When running, all of picos commands are listed on the bottom of the screen. Each command is a combination of the Control key (often abbreviated as Ctrl on the keyboard) and a letter key. For example, to exit from pico and save, you would press Control X. (In picos command menu, the ^ symbol is a notation for the meta key, which nowadays is normally mapped to the Control keyit does not mean press Shift 6!)
pico file_name
Activates pico, and has it open the file file_name, for editing. It will let you create the named file if it doesnt exist yet.
Forwarding Mail
Unix is a very flexible operating system, with many configuration possibilities for the administrator and end users alike. Since most of those options are specified via text files, they can be edited via the text editors introduced in the last section. For example, should you find checking both your CSULA e-mail (via either Webmail) and your own ISPs e-mail to be tedious, you can have your CSULA mail forwarded to your ISP account (or Hotmail, etc.). This can be set by using the hidden file .forward to specify the forwarding address. To set up mail forwarding, you should first telnet to your server (named after some celestial objects, such as jupiter, sol, etc.). Then, type the command ls -aF to show all the items, including files which start with a period. Those files, not reported by ls without the -a option, are commonly called hidden files. (Users with lots of items in their home directories may need to use ls -aF | more instead.) Mail forwarding is controlled by such a file, called .forward, which you can create in your home directory. (It normally does not exist, unless you are already forwarding your mail.) Now, to set up the forwarding, just use pico (or any other text editor):
pico .forward
In pico, type out the address for the mail to be forwarded to, then exit and save. You're done! Just for fun, heres a quicker way of doing this, without using a text editor:
echo "username@hostname" > .forward
Directory Operation
ls ls -a ls -F ls -l
(to list the directorys content) (to list the hidden files as well) (to identify the sub-directories with a /) (to list all the information) (to list the named dir.s content)
ls dir_name
pico file_name (also to edit) rm file_name mv file_name dest_dir cp file_name1 file_name2 cp file_name dir_name
mkdir dir_name rmdir dir_name rm -r dir_name mv dir_name dest_dir cp -r dir_name1 dir_name2 mv dir_name new_name pwd cd dir_name cd .. (to go to the parent directory) cd (to go to the home directory)