Basic Unix Commands

publishing guidelines

An alternative crib sheet is available (old but still useful).

Data associated with a file or directory
ls -l output

-rwxr-xr--   1 mlb  cur      1350  May 10 16:17 index.html
permissions  owner  group    size  date   time  file name
            
File Permissions
permissions meaning
drwxr-x--- d indicates a directory:
rwx owner can list, read and write to the directory;
r-x group members can list the directory contents;
--- other users do not have access to the directory
-rwxrw-r-- - indicates a file:
rwx user can read, write/delete and run a file;
rw- group can read and write/delete a file;
r-- other users can only read a file
 
Directory Shortcuts
Shortcut description example
. current directory  
.. parent directory  
/ top-level (root) directory /web/cs/docs
/home/cur/mlb
~login home directory belonging to login ~mlb is the home directory for Maggie Bowman

 

Useful commands
Command description example
groups login lists the unix groups of which login is a member groups mlb
more filename safe way to list the contents of a file more index.html
man manual page for the specified command man chmod

 

Files and Directories
General Commands
Command Description Example (% is a response from the operating system)
pwd print current (working) directory: it tells you what directory you are currently in pwd
% /home/cur/mlb
cd change directory

cd subdirectory
cd subdir1/subdir2/subdir3
cd ..

ls list files in the current directory ls
ls -l list files in the current directory: include file date and size ls -l
ls -l directoryName list files in the named directory: include file date and size ls -l /web/cs/docs
ls -l fileName list the named file only: include file date and size ls -l /web/cs/docs/welcome.html
 
Files  
cp make a copy of a file cp oldfile newfile
cp olddir newdir
mv rename a file (move file)

mv oldfile newfile
mv oldfile ../newdir

rm delete (remove) a file rm filename
chmod to change the permissions (use with caution: see Unix manual page for help) chmod g+w somefile.doc
 
Directories  
mkdir create a new directory (folder) mkdir newdir
mv rename a file (move file)

mv olddir newdir
mv olddir ../newdir

rmdir delete (remove) an empty directory (one which contains no files or directories):
remove any files inside the directory first using rm
rmdir dirname
chmod to change the permissions (use with caution: see Unix manual page for help) chmod g+w somedirectory
 
Miscellaneous
pico file editor on UNIX machines pico filename
vi file editor on UNIX machines vi filename
pfe file editor on Windows
notepad file editor on Windows
wordpad file editor on Windows