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 (that is what the dot means))
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 enscript -2rG filename

enscript -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.)