Unix Tutorial


What is Unix?

Getting started

Hardware

Software

Basic Commands

vi Commands

 

Files

File Commands

Different types of file

File Redirection

Permissions

Pipelines / Filters

 

Directory

Directory Structure

Directory Command

Shell

Different types of shell

Compiling Program

Networking

Commands

Reference

Reference Commands

Online help:Manpages

Useful links/Books

Search Engine

 

 

BASIC Unix Directory commands


Commands to find out where you are

pwd

Prints current directory.Use to check directory in which you are working.

whoami

For people who use multiple IDs, tells you which ID you are using.

ls : Commands to get information about contents of current directory

Use options -l, -a, -t, -g in any combination or order as shown in examples.

ls : Lists files and directories in current directory.

ls -l : Lists files and directories and details about them.

ls -a : Lists files and directories and hidden files.

ls -t : Lists files and directories in order by last modified date.

ls -g : Lists files and directories and which group owns them.

ls -la : Lists files and directories, including hidden files, and gives information about them.

ls -latg :Lists files and directories showing all options.

ls p* :Lists any files in the current directory that begin with the letter p. The asterisk (*) is used as a wild card. It replaces one or more characters in a file name. For example, *p* looks for any file with the letter p anywhere in the name.


Commands to add or delete directories or files

mkdir directory1 : Makes a directory and names it directory1.

rmdir directory1 : Removes the directory named directory1. (Note: You cannot remove a directory unless it is empty.)

vi file1 Makes a file named file1 and places you in the "vi" editor. If you only want to make a file as a placeholder, type :wq (colon and letters w and q) and then press the Enter/Return key to leave the vi editor.

rm file1 : Removes the file named file1 from the current directory.

rm * : Removes all files from the current directory.


Commands to move from one directory to another

cd : Moves one directory above your current location.

cd . : Moves to the same directory.

cd .. : Moves to the parent directory.

For example we are in CS login cs1234 and have following directories public_html, windows and csc1000. Inside csc1000, there are two more directories homework1 and homework2.In homework1 directory there are two subdirectories abc and xyz.Now let us try to use above two commands.Type

%pwd

/home/users/cs1234

%cd public_html

%pwd

/home/users/cs1234/public_html

%cd homework1

%cd abc

%pwd

home/users/cs1234/public_html/abc

%cd .

home/users/cs1234/public_html/abc

%cd ..

home/users/cs1234/public_html

cd directory1 : Moves to a directory named directory1 in the current directory.

cd ../directory_name : Moves one directory above current directory and then to directory named.


Commands to move and copy files

mv file1 file2 : Moves file1 into file2. If file2 has not been created, it creates file2 and moves the contents of file1 into it. If file2 exists, its contents are replaced by the contents of file1. In all cases, file1 no longer exists. mv file1 directory_name Moves the file named file1 into the directory named.

cp file1 file2 : Copies the contents of file1 into file2. Leaves file1 as is.


Command to print files to your screen

more file1 : Prints the contents of file1 on your screen one screen at a time. Press the space bar to view the next screen.