Linux Command Reference

Operation Command Usage Example
Find out where you are ... your present working directory pwd
pwd

(displays the full pathname of your current directory)
List the files in the current directory ls

OR

ls -l

OR

ls -a
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. (There are lots of other variations!)
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

OR

cp originalFile newDirectory

cp myProgram.java ~prof/cs120/assignments

(copies a file named myProgram.java into the assignments subdirectory of user "prof")

cp myProgram.java newTry.java

(copies a file named myProgram.java into a file named newTry.java (in the same directory);

WARNING: if there was already a file named newTry.java it would be wiped out!)

cp ~cpsc/example.java .

(copies a file named example.java in the cpsc home directory to the present directory)
Rename a file (same as moving it to a file with a different name) mv oldName newName

mv myProg.java hello.java

renames the file myProg.java; the new name is hello.java
WARNING: If there was already a file named hello.java it would be erased by this command.
Print a file nenscript -2rG filename

nenscript -2rG myProgram.java


(prints the file myProgram.java in a nice format (that saves paper!) to the lab printer)

View a file on the screen
more filename

OR

less filename
more myProgram.java


(displays the contents of the file myProgram.java on the monitor one page at a time. Press the space bar to go to the next page; type b to go back to the previous page; type q to quit. less is similar.)
Delete (remove) a file rm filename

rm myProgram.java


(deletes the file myProgram.java 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.)