Basic Unix Commands


File/Directory Basics
ls List files
pwd Print current working directory
cd Change directories
cp Copy files
mv Move/Rename files
rm Delete files
mkdir Create directory
rmdir Delete directory
File Viewing
cat View file contents
less Page through files
head View file beginning
tail View file ending
nl View file with line numbers
File Creation and Editing
emacs Text editor
vi Text editor
gedit Text editor
File Properties
stat Display file attributes
wc Count bytes/words/lines
file Identify file types
chown Change file owner
chgrp Change file group
chmod Change file permissions
Programming
g++ Compile a C++ program
gdb Starts the debugger
Usage Examples
$ ls lists files of your current working directory.
$ cd /home/m012345/ change your working directory to your home directory using a full, or absolute, pathname
$ cd change your working directory to your home directory using a shortcut
$ mkdir lab creates a lab subdirectory in your current working directory
$ cd lab change your working directory to the lab directory in your home directory in this case
$ cd .. change your working directory to the parent directory, which is your home directory
$ gedit main.cpp creates the file main.cpp, if it doesn't already exist, and opens it in the gedit editing window
$ cp main.cpp lab/ copies the file main.cpp to the lab directory
$ mv main.cpp test.cpp renames main.cpp to test.cpp
$ mv test.cpp lab/lab1.cpp moves main.cpp to the lab directory under the new name of lab1.cpp
$ ls -l lab lists files in the lab directory in more detail
$ cat lab/main.cpp shows file contents of main.cpp, which is located in the lab directory
$ rm lab/main.cpp deletes main.cpp from the lab directory
$ rm lab/lab1.cpp deletes main.cpp from the lab directory
$ rmdir /home/m012345/lab deletes the lab directory using its absolute pathname.
 
$ g++ new.cpp compiles and links new.cpp and creates an executable file called a.out
$ g++ -o run new.cpp does the same as above, except creates an executable file called run
$ g++ -Wall -o proj proj.cpp compiles proj.cpp, but with all warnings enabled and creates executable file called proj

LT J Schultz

Valid XHTML 1.0 Strict