Upload
rishipath
View
215
Download
0
Embed Size (px)
Citation preview
7/27/2019 UNIX Cmd 1.1
1/8
UNIX Commands
Heading Objective Command Example
df df command displays
information about total spaceand available space on a filesystem
This displays the file systemstatistics in 1024-byte diskblocks.
df k df -k /test
This displays file systemstatistics in MB disk blocksrounded off to nearest 2nddecimal digit.
df m df -m /test
This displays file system
statistics in GB disk blocksrounded off to nearest 2nddecimal digit.
df g df -g /test
find Finds files with a matchingexpression.
This searches the entire filesystem and writes thecomplete path names of allfiles named .profile. The /(slash) tells the find commandto search the root directory and
all of its subdirectories.
find / find / -name .profile-print
This lists the names of the filesthat have only owner-read andowner-write permission. The .(dot) tells the find command tosearch the current directoryand its subdirectories.
find . find . -perm 0600 print
To list all files in the currentdirectory that have beenchanged during the current 24-hour period.
find . ctime find . -ctime 1 print
To lists the names of theordinary files (-type f) thathave more than one link (-links +1).
find . -type f find . -type f -links+1 print
To find all accessible fileswhose path name contains find
find . name find . -name '*find*'print
To search for all files that areexactly 414 bytes long
find . -size find . -size 414c print
7/27/2019 UNIX Cmd 1.1
2/8
Wait Waits until the termination ofa process ID.
Waits until the termination ofa process123456789.
wait [ ProcessID] wait 123456789
date Displays the date in the
desired format.Displays the date in the formatequivalent to %m/%d/%y.
date +"%D"
Displays the locale's fullmonth name.
date +"%B"
Displays the hour (24-hourclock) as a decimal number(00-23).
date +"%H"
Displays the locale'sequivalent of either AM orPM.
date +"%p"
Displays 12-hour clock time(01-12) using the AM-PMnotation; in the POSIXlocale, this is equivalent to %I:%M:%S %p.
date +"%r"
errpt Generates a report of loggederrors.
To display a completesummary report
errpt
To display a complete detailedreport
errpt -a
To display a detailed report ofall errors logged for the erroridentifier E19E094F
errpt -a errpt -a -jE19E094F
To display a detailed report ofall errors logged in the past 24hours.
errpt -a -s mmddhhmmyy
To list error-record templatesfor which logging is turned offfor any error-log entries.
errpt -t -F log=0
To view all entries from thealternate error-log file
/var/adm/ras/errlog.alternate
errpt -i/var/adm/ras/errlog.alternate
To display a detailed report ofall errors and group duplicateerrors
errpt aD
fmt Formats mail messages priorto sending.
To format a message you havecreated with the mail editor
~| fmt
7/27/2019 UNIX Cmd 1.1
3/8
The file file1 is formatted anddisplayed on your screen
fmt filename fmt file1
fuser Identifies processes using afile or file structure.
To list the process numbers of
local processes using the/etc/passwd file
fuser /etc/passwd
To list the process numbersand user login names ofprocesses using the/etc/filesystems file
fuser -u /etc/filesystems
To terminate all of theprocesses using a given filesystem
fuser -k -x -u -c/dev/hd1 orfuser -kxuc /home
To list all processes that areusing a file which has been
deleted from a given filesystem.
fuser -d /usr
ipcs Reports interprocesscommunication facility status.
Ipcs
jobs Displays status of jobs in thecurrent session.
To display the status of jobs inthe current environment
jobs l
To display the process ID forthe job whose name beginswith "m"
job -p %m
ls Displays the contents of adirectory.
To list all files in the currentdirectory
ls a
To display a long listing withdetailed information aboutchap1 and .profile.
ls -l chap1 .profile
To display a long listing forthe directories . and manual,and for the file manual/chap1.(Without the -d flag, this
would list the files in the . andmanual directories instead ofthe detailed information aboutthe directories themselves.)
ls -d -l . manualmanual/chap1
To display a long listing of thefiles that were modified mostrecently, followed by the olderfiles.
ls -l t
7/27/2019 UNIX Cmd 1.1
4/8
mail,
Mail, or
mailx
Sends and receives mail.
The mail command lists everymessages in your system
mailbox.
To send the message letter tothe recipient user1@host1 andcopies touser2@host2 and user3@host3
mail -c "user2@host2user3@host3"user1@host1
7/27/2019 UNIX Cmd 1.1
5/8
with field specifiers ruser,pid,ppid=parent,args
To display information aboutprocesses and kernel threadscontrolled by the currentterminal
ps lm
To display information aboutall processes and kernelthreads
ps -emo THREAD
rlogin Connects a local host with aremote host.
To log in to a remote host withyour local user name
rlogin host2
To log in to a remote host witha different user name
rlogin host2 -l dale
To log in to a remote host withyour local user name and
change the escape character
rlogin host2 -e\
shutdown Ends system operation.
To turn off the machine Shutdown
To give users more time tofinish what they are doing andbring the system tomaintenance mode
shutdown -m +2
su Changes the user IDassociated with a session.
To obtain root user authority Su
To obtain the privileges of thejim user
su jim
To set up the environment as ifyou had logged in as the jimuser
su jim
To run the backup commandwith root user authority andthen return to your originalshell
su root "-c/usr/sbin/backup -9-u"
uname Displays the name of thecurrent operating system.
To display the completesystem name and versionbanner
uname a
rsh or
remsh
Executes the specifiedcommand at the remote host orlogs into the remote host.
To check the amount of freedisk space on a remote host
rsh host2 df
7/27/2019 UNIX Cmd 1.1
6/8
To append a remote file toanother file on the remotehost, place the >>metacharacters in quotationmarks
rsh host2 cat test1">>" test2
To append a remote file at theremote host to a local file,omit the quotation marks
rsh host2 cat test2>> test3
To append a remote file to alocal file and use a remoteuser's permissions at theremote host (The remote filetest4 is appended to the localfile test5 at the remote host,with user jane's permissions.)
rsh host2 -l jane cattest4 >> test5
grep Searches a file for a pattern.
To use a pattern that containssome of the pattern-matchingcharacters *,
^, ?, [, ], \(, \), \{, and \}
grep "^[a-zA-Z]"pgm.s
To display all lines that do notmatch a pattern
grep v grep -v "^#" pgm.s
To display all lines in the file1file that match either the abcor xyz string
grep E grep -E "abc|xyz"file1
To search for a $ (dollar sign)in the file named test2
grep \\$ test2
This option causes a case-insensitive search.The -n option lists the matching
lines, together with line numbers.
grep -i
This option matches only wholewords.
grep -w
The -l option lists only the files
in which matches were found, butnot the matching lines.
grep -l
The -r (recursive) optionsearches files in the currentworking directory and allsubdirectories belowit.
grep -r
The -n option lists the matching
lines, together with line numbers.grep n
7/27/2019 UNIX Cmd 1.1
7/8
vi (visual) vi is a display-oriented texteditor based on an underlyingline editor. When using vi,changes we make to the fileare reflected in what we see on
our screen.
vioptions filename
By using this we come out oftext mode and enter intocommand mode.
ESC
1. Commands for Saving Work
/ Editing
write file under original name :w
write file under original name,exit vi
ZZ or :wq
exit vi, no changes are saved :q!
write the file underfilename :wfilename
write the file underfilename,overwrite existing file
:w!filename
write linesx throughy underfilename
:x,y wfilename
filename write linesx throughy underfilename , overwriteexisting filename
:x,y w!
2. Commands for Inserting
Text
insert before the currentcharacter
i
insert after the current
character
a
insert at end of current line A
insert at beginning of currentline
I
insert below current line(opens new line)
o
insert above current line(opens new line)
O
7/27/2019 UNIX Cmd 1.1
8/8
end text insertion ESC
3. Commands for Replacing
Text
replace the current character rreplace the current word s
replace the current line S
4. Commands for Deleting Text
delete the current character x
delete the current line dd
delete the previous character X
5. Commands for Copying
(yank) and Pasting Text
yank current character y
yank current word yw
yank current line yy
place most recently deleted oryanked character(s) or word(s)after the current character,place line(s) below current line
p
place most recently deleted oryanked character(s) or word(s)
before the current character,place line(s) above the currentline
P