Fundamentals of Computer Science I

Linux Command Reference

A list of commands you can enter in the Terminal.

Operation Command Usage Example
Find your present working directory. pwd pwd (Displays the full pathname of your current directory)
List the files in the current directory. ls

ls (Lists just the names of the files in the current directory.)
ls -l (Gives a long listing that includes the file name, permissions, the owner, The size, and the date.)
ls -a (Lists all files in the directory, including some system files whose names start with a period.)
ls -la (Gives a long listing of all files.)
ls -l s* (Gives a long listing of all files whose name starts with s.)

Create (make) a new subdirectory of your current working directory. mkdir directory_name mkdir lab1 (Creates a directory named lab1 within your current directory.)
Change to another directory. cd pathname

cd lab1 (Changes to the lab1 subdirectory of your current directory.)
cd ~jdoe/cs120/Labs/lab1 (Changes to user jdoe's lab1 directory.)

Copy a file

cp originalFile newFile
cp originalFile newDirectory

cp my_program.py ~prof/cs120/assignments (Copies a file named my_program.py into the assignments subdirectory of user prof.)
cp my_program.py new_try.py (Copies a file named my_program.py into a file named new_try.py, in the same directory. WARNING: If there was already a file named new_try.py it would be wiped out!) cp ~cpsc/example.py . (Copies a file named example.py in the cpsc home directory to the present directory. Note, the dot means present directory.)
Rename a file (same as moving it to a file with a different name). mv oldName newName mv my_program.py hello.py (Renames the file my_program.py. The new name is hello.py. WARNING: If there was already a file named hello.py it would be erased by this command.)
View a file in the terminal. more filename
less filename
more my_program.py (Displays the contents of the file my_program.py in the terminal one page at a time. Press the space bar to go to the next page. Press b to go back to the previous page. Press q to quit.
less my_program.py (Same as more.)
Delete (remove) a file. rm filename rm my_program.py (Deletes the file my_program.py in the current directory.)
Delete (remove) a directory. rmdir directoryName rmdir lab1 (Removes the directory lab1 from the current directory. The directory must be empty to remove it.)
Zip (create archive file of) files. zip archive.zip files zip assignment1.zip * (creates a zip file called assignment1.zip that contains all of the files in the present working directory (the * means all files in current directory).)
Unzip (copy files out of) a zip file. unzip archive.zip unzip assignment1.zip (copies all of the files in the zip file assignment1.zip to the present working directory.)