Table of Contents
Basic Unix Commands
Unix has a lot of useful commands. If you want to find out more information about any of these commands, use the
man command, which stands for manual. For example, to find out more about the
ls command, use
> man ls
| ||change directory|
| ||list the contents of the directory, current directory if no directory is given|
| ||create a directory|
| ||delete a directory; only works if the directory is empty|
| ||to see the Present Working Directory (the directory that you're currently in)|
ls has a lot of optional command-line arguments:
| ||a long listing of the files|
| ||reverse order|
| ||sort by creation time|
ls -lrt lists the files in the current directory by creation time, from most recent to least recent, and lists all the information about the files
Copy Files and Directories
To make a copy of a file (
source) and name it
cp <source> <destination>
cp myfile.txt myfilecopy.txt
To copy a directory and its contents, use the
-r means recursively. For example,
cp -r my_src_directory destination_directory
Move or Rename Files
mv command to move or rename files:
mv <source> <destination>
If the destination is a directory, then the file(s) are moved into that directory.
For example, to rename
mv myfile.txt newname.txt
rm <file>- deletes
View contents of Files
- To view the contents of a file, you can use
cat <file> more <file> less <file>
- ~ - your home directory. Example use to go into your home directory:
- . - the current directory
- .. - the parent directory
- * - wildcard, matches anything. Example use to list all the java files in a directory:
ls -l *.java
find command is very useful and powerful.
find . -name "*.java"
The above command finds all the files that end with .java in the current directory and its subdirectories.
Finding Files Containing Text
grep command to find files that contain particular text. For example, to find all the Java files that contain the text
grep main *.java
grep stands for Gnu Regular Expressions, so you can also search for regular expressions in files.
To print from the command-line, you can use the
lpr command. Do not try to print PDF files or images this way. The syntax of the print command is
lpr -P<printername> filename
lpr -Pcslab test.py
The printer name is
cslab when you're in P405 or
advlab if you're in P413.
lpr means to print the file. The option 'P' says which printer to use (one of the CS lab printers), and the argument says which file to print–in this case
Creating Printable Files
To create a condensed, printable file of your lab, use the
The syntax of the command is
For example, if you're in your
labs directory, to print lab1, you'd write
Changing Your Password
To change your password, use the
An example run will look something like:
> passwd Changing password for username. Old Password: New Password: Retype new password: passwd: all authentication tokens updated successfully.
Note that what you type for the passwords does not show up on the screen for your security.