Sunteți pe pagina 1din 26

BASIC UNIX COMMANDS

DAY-2
DIRECTORY STRUCTURE OF UNIX
cdrom
devices
floppy
login: root
Password:*****
#
SYSTEM LOGIN PROMT
login: zoom
Password:*****
$
System Administrator or Super User Login.
Normal User Login.
GENERAL UNIX COMMANDS
To Know the current directory
login: root
Password:*****
# pwd
/
#
Command: pwd
login: zoom
Password:*****
$pwd
/export/home/zoom
$
Examples:-
Printing Banner
Command: banner
Example:
# banner zoom
Calendar
Command: cal
Syntax: # cal <month> <year>
Example:
$ cal
$ cal 1985
$ cal 03 1985
Date and Time:
Command: date
Syntax: $ date

Example:
$ date
Tue Jun 24 04:48:52 GMT 2003
$
Clear The Screen
Command: clear
Example:
$ clear
FILES AND DIRECTORIES
Case sensitive
Any character can be used.
(a-z, A-Z,0-9,-,_,etc)
Avoid /, >, , !,
they are legal but hard to use with shells
File and Directory Names
Listing Files and Directories
Command: ls
Syntax: $ ls <options> <arguments>
To view hidden files
$ ls a
.profile test.c cisco
$
Example:
$ ls
test.c cisco
$
bash$ ls -l
total 306
-rwxr-xr-x 1 zoom sales 30 Aug 26 2003 test.c
-rwx------ 1 zoom sales 50 Aug 26 2003 sa1
-rwx------ 1 zoom sales 22 Aug 26 2003 sa2
-rwxr-x--- 1 zoom sales 73728 Aug 26 2003 syam
-rwx------ 1 zoom sales 42 Aug 26 2003 raj
bash$
Long Listing Files
type
access permission
# of links
owner
group
size
(bytes)
modification
date and time
name
Creation Of files:
Examples:
Command: cat
Syntax: # cat <options> <argurments>
$ cat file1
This is a test file
$
1) To create a file
$ cat > file1
This is a test file
(ctrl+d)
$
2) To view contents of a file
Examples:
$ cat file1
This is a test file
Test for appending
$
3) To append a file
$ cat >> file1
Test for appending
(ctrl+d)
$
4) To view contents of a file
$ cat file1 > file2
5) To add contents of file1 to file2
6) To append contents of file1 to file2
$ cat file1 >> file2
Example:
$ touch test.c
Touching files:
Touch command creates a file with zero bytes.
Command: touch
Removing/Deleting files
Command: rm
Syntax: $ rm <options> <filename>
Example:
$ rm test.c
WORKING WITH
DIRECTORIES
Creating Directories
Command: mkdir
Syntax: $ mkdir <options> <DirectoryName>
Example2:
$ mkdir p /dir2/dir3
WORKING WITH DIRECTORIES
Example1:
$ mkdir dir1
Navigation of Directories
Changing Directory:
Command: cd
Syntax: $ cd <arguments>
Example1:
To change to other directory
login: zoom
Password:*****
$pwd
/export/home/zoom
$ls
cisco sun mcse
$ cd cisco
login: zoom
Password:*****
$pwd
/export/home/zoom/cisco
Example2:
To change to one directory back
Example2: To
change to two directories back
login: zoom
Password:*****
$pwd
/export/home/zoom/cisco/ccna
$ cd ..
$ cd ../..
System Administrator
login: root
Password:*****
#pwd
/opt/sun
Normal User Login.
login: zoom
Password:*****
$pwd
/opt/sun
$cd
$pwd
/export/home/zoom
$
#cd
#pwd
/
#
Changing the directory using cd command
Removing/Deleting a Directory
Command: rmdir and rm
Syntax: $ rmdir (if directory is empty)
$ rm rf (if the directory is NOT empty)
Example:
# rmdir dir1
Example:
# rm rf dir1
Recursively
and forcibly
Recursively
and forcibly
Copying of Files / Directories
Command: cp
Syntax: # cp <options> <source> <destination>
Example1:
(copying a file to same location)
$ cp file1 file2
Example2:
(copying a file to different location)
$pwd
/export/home/zoom
$ cp file1 /opt/
Example3: (Directories)
$pwd
/export/home/zoom
$ cp r dir1 /opt/
Moving of Files
Command: mv
Syntax: $ mv <source > <destination >
Example1:
Moving file to a directory
$pwd
/export/home/zoom
$ mv file1 /opt/
Example2:
moving and renaming a dir
$pwd
/export/home/zoom
$ mv f dir1 /opt/dir2
Renaming of Files / Directories
Command: mv
Syntax: $ mv <options> <old file > <new file >
Example1: (file)
$ mv file1 newfile1
Example2: (Directories)
$pwd
/export/home/zoom
$ mv f dir1 /opt/

S-ar putea să vă placă și