To append file1 onto the end of file2, enter at the Unix prompt:
cat file1 >> file2To view the contents of a file named myfile, enter:
cat myfileBecause cat displays text without pausing, its output may quickly scroll off your screen. Use the more utility (described below) or an editor for reading longer text files.
To print the contents of a file named myfile, enter: (this is not a standard Unix command)
cat myfile | ansiprt
To switch to a subdirectory (of the current directory) named myfiles, enter:
cd myfilesTo switch to a directory named /usr/dvader/empire_docs, enter:
cd /usr/dvader/empire_docsTo move to the parent directory of the current directory, enter:
cd ..To move to the root directory, enter:
cd /To return to your home directory, enter:
cd or cd ~
cp -i oldfile newfileTo copy a file named meeting1 in the directory /usr/dvader/notes to your current directory, enter:
cp -i /usr/dvader/notes/meeting1 .The period (dot) indicates the current directory as destination, and preserves the old filename meeting1.
To copy a file named oldfile in the current directory to the new name newfile in a subdirectory of your home directory named mystuff, enter:
cp -i oldfile ~/mystuff/newfileThe ~ character, or tilde, is interpreted as the path of your home directory.
Note that you must have permission to read a file in order to copy it.
To find out how much disk space you're using in your account, switch to your home directory with the cd command, and enter:
duThe numbers reported are the sizes of the files; on different systems, these sizes will be in units either of 512 byte blocks, or of kilobytes.
To learn which is the case, use the man command as described below. On most systems, du -k will give sizes in kilobytes.
To find all of the files that are named myfile.txt that exist in your current directory and all of its subdirectories, enter:
find . -name myfile.txt -printTo look in your current directory and its subdirectories for all of the files that end in the extension .txt, enter:
find . -name "*.txt" -printIn these examples, the period (dot) represents your current directory. It can be replaced by the full pathname of another directory to search. For instance, to search for files named myfile.txt in the directory /home/user/myusername and its subdirectories, without actually being in that directory, enter:
find /home/user/myusername/ -name myfile.txt -printOn some systems, omitting the final / (slash) after the directory name can cause find to fail to return any results.
As a shortcut for searching in your home directory, enter:
find "$HOME/" -name myfile.txt -print
To compile test.java and redirectly all the error messages to a text file, error.txt, enter:
javac test.java >& error.txtNote: the above command will only work under csh. To change your command shell, enter:
chsh cshAfter you login again, your command shell will be changed to csh.
Example:
ln -s source_file myfile OR ln -s /N/u/benwu/WWW s220In the example, source_file is an existing file (which can be any existing file or directory across the file systems), and
myfile is a symbolic link to it, created by the ln command. After the
symbolic link is made, you can do an operation on or execute myfile, just
as the source_file. You can use normal file management commands (cp, rm,
etc) on the symbolic link.
Note: once the source file is deleted or moved to a different location, your symbolic file still exists, and the only thing you can do is either delete or move it. If you try to use it for other purposes (edit, or execute, for example), the system will send a "file nonexistent" message.
When you need to remove the link, use unlink command.
You can find out more about symbolic links by typing:
man ln
To print a file named myfile on a printer named lp1 with lpr, enter at the Unix prompt:
lpr -Plp1 myfileTo print the same file to the same printer with lp, enter:
lp -dlp1 myfileWARNING: Do not print to a printer with an unfamiliar name and location; you may annoy its owners.
lsTo also see "dot" files (files that begin with a period, such as .login), enter:
ls -aTo see the file permissions, owners, and sizes of all files, enter:
ls -laIf the listing is long and scrolls off your screen before you can read it, combine ls with the more utility, described later. For example:
ls -la | more
To learn more about the ls command, enter:
man lsTo learn more about man, enter:
man manIf you aren't sure of the exact command name, you can use man with the -k option to help you find the command you need. If you enter:
man -k keywordman will display one line summaries of each reference page that contains the keyword you specify.
To create a subdirectory named mystuff in the current directory, enter:
mkdir mystuffTo create a subdirectory named morestuff in the existing directory named /tmp, enter:
mkdir /tmp/morestuffNote that to make a subdirectory in a particular directory, you must have permission to write to that directory.
To read the contents of a file named textfile in the current directory, enter:
more textfileThe more utility is often used for reading the output of other commands. For example, to read the output of the ls command one screen at a time, enter:
ls -la | moreNote: Don't use more with executables (binary files), such as output files produced by compilers. Doing so will display garbage and may lock up your terminal.
As with the cp command, you should always use -i to make sure you don't overwrite an existing file.
To rename a file named oldname in the current directory to the new name newname, enter:
mv -i oldname newnameTo move a file named hw1 from a subdirectory named newhw to another subdirectory named oldhw (both subdirectories of the current directory), enter:
mv -i newhw/hw1 oldhwIf, in this last operation, you also wanted to give the file a new name, such as firsthw, you would have entered:
mv -i newhw/hw1 oldhw/firsthw
pine
pwd
rm -i junkWARNING: Your file will be gone forever! Be sure you really want to get rid of a file before you use rm.
rmdir oldstuffNote that the directory you specify for removal must be empty. To clean it out, switch to the directory and (carefully!) use the ls and rm commands to inspect and delete files.
w
who
This is a modified version of UITS document, Introduction to Unix commands. For more information, see the UITS publications, "Unix Commands: A Quick Guide" and "Unix: The least you need to know", as well as the online manual pages.You can also view a collection of Unix tutorials and introductory help files on the Web at
http://www.mcsr.olemiss.edu/unixhelp/