Unix Commands

Unix commands

Misc commands
man,banner,cal, calendar,clear,nohup, tty .
Man ual command.
man man This is help command, and will explains you about online manual pages you can also use man in conjunction with any command to learn more about that command for example.
• man ls will explain about the ls command and how you can use it.
• man -k pattern command will search for the pattern in given command.

Banner command.
banner prints characters in a sort of ascii art poster, for example to print wait in big letters. I will type
banner wait at unix command line or in my script. This is how it will look.


Cal command
cal command will print the calander on current month by default. If you want to print calander of august of 1965. That's eightht month of 1965.
cal 8 1965 will print following results.
August 1965
S M Tu W Th F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31


Clear command
clear command clears the screen and puts cursor at beginning of first line.

Calendar command
calendar command reads your calendar file and displays only lines with current day.
For example in your calendar file if you have this
12/20 Test new software.
1/15 Test newly developed 3270 product.
1/20 Install memory on HP 9000 machine.
On dec 20th the first line will be displayed. you can use this command with your crontab file or in your login files.

Nohup command.
nohup command if added in front of any command will continue running the command or process even if you shut down your terminal or close your session to machine. For exmaple, if I want to run a job that takes lot of time and must be run from terminal and is called update_entries_tonight .
nohup update_entries_tonight will run the job even if terminal is shut down in middle of this job.

Tty command
Tty command will display your terminal. Syntax is
tty options
Options
• -l will print the synchronous line number.
• -s will return only the codes: 0 (a terminal), 1 (not a terminal), 2 (invalid options) (good for scripts)


File Management commands.
cat,cd, cp, file,head,tail, ln,ls,mkdir ,more,mv, pwd, rcp,rm, rmdir, wc.

Pwd command.
pwd command will print your home directory on screen, pwd means print working directory.
/u0/ssb/sandeep
is output for the command when I use pwd in /u0/ssb/sandeep directory.

Ls command
ls command is most widely used command and it displays the contents of directory.
options
• ls will list all the files in your home directory, this command has many options.
• ls -l will list all the file names, permissions, group, etc in long format.
• ls -a will list all the files including hidden files that start with . .
• ls -lt will list all files names based on the time of creation, newer files bring first.
• ls -Fxwill list files and directory names will be followed by slash.
• ls -Rwill lists all the files and files in the all the directories, recursively.
• ls -R | more will list all the files and files in all the directories, one page at a time.

Mkdir command.
mkdir sandeep will create new directory, i.e. here sandeep directory is created.

Cd command.
cd sandeep will change directory from current directory to sandeep directory.
Use pwd to check your current directory and ls to see if sandeep directory is there or not.
You can then use cd sandeep to change the directory to this new directory.

will restore all files whose name contain "save"
• find . -depth -print | cpio -padm /mydir will move a directory tree.

Dump command is useful to backup the file systems.
dump command copies all the files in filesystem that have been changed after a certain date. It is good for incremental backups. This information about date is derived from /var/adm/dumpdates and /etc/fstab .
syntax for HP-UX dump is
/usr/sbin/dump [option [argument ...] filesystem]
Options
• 0-9 This number is dump level. 0 option causes entire filesystem to be dumped.
• b blocking factor taken into argument.
• d density of tape default value is 1600.
• f place the dump on next argument file instead of tape.
• This example causes the entire file system (/mnt) to be dumped on /dev/rmt/c0t0d0BEST and specifies that the density of the tape is 6250 BPI.
o /usr/sbin/dump 0df 6250 /dev/rmt/c0t0d0BEST /mnt
• for more info type man dump at command line.

Pack command.
pack command compacts each file and combine them together into a filename.z file. The original file is replaced. Pcat and unpack will restore packed files to their original form.
Syntax is
Pack options files
Options
• - Print number of times each byte is used, relative frequency and byte code.
• -f Force the pack even when disk space isn't saved.
• To display Packed files in a file use pcat command
pcat filename.z
• To unpack a packed file use unpack command as unpack filename.z .

Tar command.
tar command creates an archive of files into a single file.
Tar copies and restore files to a tape or any storage media. Synopsis of tar is
tar [options] [file]

Examples:
tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the tape in /dev/rmt0.
tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it in file backup.tar.
Functions:
• c creates a new tape.
• r append files to a tape.
• t print the names of files if they are stored on the tape.
• x extract files from tape.
Options:
• b n use blocking factor of n.
• l print error messages about links not found.
• L follow symbolic links.
• v print function letter (x for extraction or a for archive) and name of files.
________________________________________

Mt command
Mt command is used for tape and other device functions like rewinding, ejecting, etc. It give commands to tape device rather than tape itself. Mt command is BSD command and is seldom found in system V unix versions.
syntax is
mt [-t tapename] command [count]
mt for HP-UX accept following commands
• eof write count EOF marks.
• fsf Forward space count files.
• fsr Forward space count records.
• bsf Backward space count files.
• bsr Backward space count records.
• rew Rewind tape.
• offl Rewind tape and go offline.
• eod Seek to end of data (DDS and QIC drives only).
• smk Write count setmarks (DDS drives only).
• fss Forward space count setmarks (DDS drives only).
• bss Backward space count setmarks (DDS drives only).
• Examples
o mt -t /dev/rmt/0mnb rew will rewind the tape in this device.
o mt -t /dev/rmt/0mnb offl will eject the tape in this device.


System Status
at, chmod,chgrp, chown,crontab,date, df,du, env, finger, ps,ruptime, shutdwon,stty, who.

At command.
at command along with crontab command is used to schedule jobs.
at options time [ddate] [+increment] is syntax of at command.
for example if I have a script named usersloggedin which contains.
#!/bin/ksh
who | wc -l
echo "are total number of people logged in at this time."
and I want to run this script at 8:00 AM. So I will first type at 8:00 %lt;enter>
usersloggedin %lt;enter>
I will get following output at 8:00 AM
30
are total number of people logged in at this time.
Options:
• -f file will execute commands in a file.
• -m will send mail to user after job is completed.
• -l will report all jobs that are scheduled and their jobnumbers.
• -r jobnumber will remove specified jobs that were previously scheduled.

Chmod command.
chmod command is used to change permissions on a file.
for example if I have a text file with calender in it called cal.txt.
initially when this file will be created the permissions for this file depends upon umask set in your profile files. As you can see this file has 666 or -rw-rw-rw attributes.

ls -la cal.txt
-rw-rw-rw- 1 ssb dxidev 135 Dec 3 16:14 cal.txt
In this line above I have -rw-rw-rw- meaning respectively that owner can read and write file, member of the owner's group can read and write this file and anyone else connected to this system can read and write this file., next ssb is owner of this file dxidev is the group of this file, there are 135 bytes in this file, this file was created on December 3 at time16:14 and at the end there is name of this file. Learn to read these permissions in binary, like this for example Decimal 644 which is 110 100 100 in binary meand rw-r--r-- or user can read,write this file, group can read only, everyone else can read only. Similarly, if permissions are 755 or 111 101 101 that means rwxr-xr-x or user can read, write and execute, group can read and execute, everyone else can read and execute. All directories have d in front of permissions. So if you don't want anyone to see your files or to do anything with it use chmod command and make permissions so that only you can read and write to that file, i.e.
chmod 600 filename.

Chgrp command.
chgrp command is used to change the group of a file or directory.
You must own the file or be a superuser.
chgrp [options] newgroup files is syntax of chgrp.
Newgroup is either a group Id or a group name located in /etc/group .
Options:
• -h will change the group on symbolic links.
• -R recursively descend through directory changing group of all files and subdirectories.

Chown command.
chown command to change ownership of a file or directory to one or more users.
Syntax is
chown options newowner files
Options
• -h will change the owner on symbolic links.
• -R will recursively descend through the directory, including subdirectories and symbolic links.

Crontab command.
crontab command is used to schedule jobs. You must have permission to run this command by unix Administrator. Jobs are scheduled in five numbers, as follows.
Minutes 0-59
Hour 0-23
Day of month 1-31
month 1-12
Day of week 0-6 (0 is sunday)
so for example you want to schedule a job which runs from script named backup_jobs in /usr/local/bin directory on sunday (day 0) at 11.25 (22:25) on 15th of month. The entry in crontab file will be. * represents all values.
25 22 15 * 0 /usr/local/bin/backup_jobs
The * here tells system to run this each month.
Syntax is
crontab file So a create a file with the scheduled jobs as above and then type
crontab filename .This will scheduled the jobs.

Date command.
Date displays todays date, to use it type date at prompt.
Sun Dec 7 14:23:08 EST 1997
is similar to what you should see on screen.

Df command.
df command displays information about mounted filesystems. It reports the number of free disk blocks. Typically a Disk block is 512 bytes (or 1/2 Kilobyte).
syntax is
df options name
Options
• -b will print only the number of free blocks.
• -e will print only the number of free files.
• -f will report free blocks but not free inodes.
• -F type will report on an umounted file system specified by type.
• -k will print allocation in kilobytes.
• -l will report only on local file systems.
• -n will print only the file system name type, with no arguments it lists type of all filesystems

Du command.
du command displays disk usage.

Env command.
env command displays all the variables.

Finger command.
finger command.

PS command
ps command is probably the most useful command for systems administrators. It reports information on active processes.
ps options
options.
• -a Lists all processes in system except processes not attached to terminals.
• -e Lists all processes in system.
• -f Lists a full listing.
• -j print process group ID and session ID.

Ruptime command.
ruptime command tells the status of local networked machines.
ruptime options
options.
• -a include user even if they've been idle for more than one hour.
• -l sort by load average.
• -r reverse the sort order.
• -t sort by uptime.
• -i sort by number of users.

Shutdown command.
Shutdown command can only be executed by root. To gracefully bring down a system, shutdown command is used.
options.
• -gn use a grace-period of n seconds (default is 60).
• -ik tell the init command to place system in a state k.
o s single-user state (default)
o 0 shutdown for power-off.
o 1 like s, but mount multi-user file systems.
o 5 stop system, go to firmware mode.
o 6 stop system then reboot.
• -y suppress the default prompt for confirmation.

Stty command
stty command sets terminal input output options for the current terminal. without options stty reports terminal settings.
stty options modes < device options • -a report all options. • -g report current settings. Modes • 0 hang up phone. • n set terminal baud. • erase keyname, will change your keyname to be backspace key. Who command who command displays information about the current status of system. who options file Who as default prints login names of users currently logged in. Options • -a use all options. • -b Report information about last reboot. • -d report expired processes. • -H print headings. • -p report previously spawned processes. • -u report terminal usage. Advance unix command concepts Put advance commands utilities, redirection, etc here. cal > cal.txt To create a new file called cal.txt that has calendar for current month. > sign redirects output from stdout (screen) to a file.

Tuesday 7 June 2011

Unix Commands

Unix commands

Misc commands
man,banner,cal, calendar,clear,nohup, tty .
Man ual command.
man man This is help command, and will explains you about online manual pages you can also use man in conjunction with any command to learn more about that command for example.
• man ls will explain about the ls command and how you can use it.
• man -k pattern command will search for the pattern in given command.

Banner command.
banner prints characters in a sort of ascii art poster, for example to print wait in big letters. I will type
banner wait at unix command line or in my script. This is how it will look.


Cal command
cal command will print the calander on current month by default. If you want to print calander of august of 1965. That's eightht month of 1965.
cal 8 1965 will print following results.
August 1965
S M Tu W Th F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31


Clear command
clear command clears the screen and puts cursor at beginning of first line.

Calendar command
calendar command reads your calendar file and displays only lines with current day.
For example in your calendar file if you have this
12/20 Test new software.
1/15 Test newly developed 3270 product.
1/20 Install memory on HP 9000 machine.
On dec 20th the first line will be displayed. you can use this command with your crontab file or in your login files.

Nohup command.
nohup command if added in front of any command will continue running the command or process even if you shut down your terminal or close your session to machine. For exmaple, if I want to run a job that takes lot of time and must be run from terminal and is called update_entries_tonight .
nohup update_entries_tonight will run the job even if terminal is shut down in middle of this job.

Tty command
Tty command will display your terminal. Syntax is
tty options
Options
• -l will print the synchronous line number.
• -s will return only the codes: 0 (a terminal), 1 (not a terminal), 2 (invalid options) (good for scripts)


File Management commands.
cat,cd, cp, file,head,tail, ln,ls,mkdir ,more,mv, pwd, rcp,rm, rmdir, wc.

Pwd command.
pwd command will print your home directory on screen, pwd means print working directory.
/u0/ssb/sandeep
is output for the command when I use pwd in /u0/ssb/sandeep directory.

Ls command
ls command is most widely used command and it displays the contents of directory.
options
• ls will list all the files in your home directory, this command has many options.
• ls -l will list all the file names, permissions, group, etc in long format.
• ls -a will list all the files including hidden files that start with . .
• ls -lt will list all files names based on the time of creation, newer files bring first.
• ls -Fxwill list files and directory names will be followed by slash.
• ls -Rwill lists all the files and files in the all the directories, recursively.
• ls -R | more will list all the files and files in all the directories, one page at a time.

Mkdir command.
mkdir sandeep will create new directory, i.e. here sandeep directory is created.

Cd command.
cd sandeep will change directory from current directory to sandeep directory.
Use pwd to check your current directory and ls to see if sandeep directory is there or not.
You can then use cd sandeep to change the directory to this new directory.

will restore all files whose name contain "save"
• find . -depth -print | cpio -padm /mydir will move a directory tree.

Dump command is useful to backup the file systems.
dump command copies all the files in filesystem that have been changed after a certain date. It is good for incremental backups. This information about date is derived from /var/adm/dumpdates and /etc/fstab .
syntax for HP-UX dump is
/usr/sbin/dump [option [argument ...] filesystem]
Options
• 0-9 This number is dump level. 0 option causes entire filesystem to be dumped.
• b blocking factor taken into argument.
• d density of tape default value is 1600.
• f place the dump on next argument file instead of tape.
• This example causes the entire file system (/mnt) to be dumped on /dev/rmt/c0t0d0BEST and specifies that the density of the tape is 6250 BPI.
o /usr/sbin/dump 0df 6250 /dev/rmt/c0t0d0BEST /mnt
• for more info type man dump at command line.

Pack command.
pack command compacts each file and combine them together into a filename.z file. The original file is replaced. Pcat and unpack will restore packed files to their original form.
Syntax is
Pack options files
Options
• - Print number of times each byte is used, relative frequency and byte code.
• -f Force the pack even when disk space isn't saved.
• To display Packed files in a file use pcat command
pcat filename.z
• To unpack a packed file use unpack command as unpack filename.z .

Tar command.
tar command creates an archive of files into a single file.
Tar copies and restore files to a tape or any storage media. Synopsis of tar is
tar [options] [file]

Examples:
tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the tape in /dev/rmt0.
tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it in file backup.tar.
Functions:
• c creates a new tape.
• r append files to a tape.
• t print the names of files if they are stored on the tape.
• x extract files from tape.
Options:
• b n use blocking factor of n.
• l print error messages about links not found.
• L follow symbolic links.
• v print function letter (x for extraction or a for archive) and name of files.
________________________________________

Mt command
Mt command is used for tape and other device functions like rewinding, ejecting, etc. It give commands to tape device rather than tape itself. Mt command is BSD command and is seldom found in system V unix versions.
syntax is
mt [-t tapename] command [count]
mt for HP-UX accept following commands
• eof write count EOF marks.
• fsf Forward space count files.
• fsr Forward space count records.
• bsf Backward space count files.
• bsr Backward space count records.
• rew Rewind tape.
• offl Rewind tape and go offline.
• eod Seek to end of data (DDS and QIC drives only).
• smk Write count setmarks (DDS drives only).
• fss Forward space count setmarks (DDS drives only).
• bss Backward space count setmarks (DDS drives only).
• Examples
o mt -t /dev/rmt/0mnb rew will rewind the tape in this device.
o mt -t /dev/rmt/0mnb offl will eject the tape in this device.


System Status
at, chmod,chgrp, chown,crontab,date, df,du, env, finger, ps,ruptime, shutdwon,stty, who.

At command.
at command along with crontab command is used to schedule jobs.
at options time [ddate] [+increment] is syntax of at command.
for example if I have a script named usersloggedin which contains.
#!/bin/ksh
who | wc -l
echo "are total number of people logged in at this time."
and I want to run this script at 8:00 AM. So I will first type at 8:00 %lt;enter>
usersloggedin %lt;enter>
I will get following output at 8:00 AM
30
are total number of people logged in at this time.
Options:
• -f file will execute commands in a file.
• -m will send mail to user after job is completed.
• -l will report all jobs that are scheduled and their jobnumbers.
• -r jobnumber will remove specified jobs that were previously scheduled.

Chmod command.
chmod command is used to change permissions on a file.
for example if I have a text file with calender in it called cal.txt.
initially when this file will be created the permissions for this file depends upon umask set in your profile files. As you can see this file has 666 or -rw-rw-rw attributes.

ls -la cal.txt
-rw-rw-rw- 1 ssb dxidev 135 Dec 3 16:14 cal.txt
In this line above I have -rw-rw-rw- meaning respectively that owner can read and write file, member of the owner's group can read and write this file and anyone else connected to this system can read and write this file., next ssb is owner of this file dxidev is the group of this file, there are 135 bytes in this file, this file was created on December 3 at time16:14 and at the end there is name of this file. Learn to read these permissions in binary, like this for example Decimal 644 which is 110 100 100 in binary meand rw-r--r-- or user can read,write this file, group can read only, everyone else can read only. Similarly, if permissions are 755 or 111 101 101 that means rwxr-xr-x or user can read, write and execute, group can read and execute, everyone else can read and execute. All directories have d in front of permissions. So if you don't want anyone to see your files or to do anything with it use chmod command and make permissions so that only you can read and write to that file, i.e.
chmod 600 filename.

Chgrp command.
chgrp command is used to change the group of a file or directory.
You must own the file or be a superuser.
chgrp [options] newgroup files is syntax of chgrp.
Newgroup is either a group Id or a group name located in /etc/group .
Options:
• -h will change the group on symbolic links.
• -R recursively descend through directory changing group of all files and subdirectories.

Chown command.
chown command to change ownership of a file or directory to one or more users.
Syntax is
chown options newowner files
Options
• -h will change the owner on symbolic links.
• -R will recursively descend through the directory, including subdirectories and symbolic links.

Crontab command.
crontab command is used to schedule jobs. You must have permission to run this command by unix Administrator. Jobs are scheduled in five numbers, as follows.
Minutes 0-59
Hour 0-23
Day of month 1-31
month 1-12
Day of week 0-6 (0 is sunday)
so for example you want to schedule a job which runs from script named backup_jobs in /usr/local/bin directory on sunday (day 0) at 11.25 (22:25) on 15th of month. The entry in crontab file will be. * represents all values.
25 22 15 * 0 /usr/local/bin/backup_jobs
The * here tells system to run this each month.
Syntax is
crontab file So a create a file with the scheduled jobs as above and then type
crontab filename .This will scheduled the jobs.

Date command.
Date displays todays date, to use it type date at prompt.
Sun Dec 7 14:23:08 EST 1997
is similar to what you should see on screen.

Df command.
df command displays information about mounted filesystems. It reports the number of free disk blocks. Typically a Disk block is 512 bytes (or 1/2 Kilobyte).
syntax is
df options name
Options
• -b will print only the number of free blocks.
• -e will print only the number of free files.
• -f will report free blocks but not free inodes.
• -F type will report on an umounted file system specified by type.
• -k will print allocation in kilobytes.
• -l will report only on local file systems.
• -n will print only the file system name type, with no arguments it lists type of all filesystems

Du command.
du command displays disk usage.

Env command.
env command displays all the variables.

Finger command.
finger command.

PS command
ps command is probably the most useful command for systems administrators. It reports information on active processes.
ps options
options.
• -a Lists all processes in system except processes not attached to terminals.
• -e Lists all processes in system.
• -f Lists a full listing.
• -j print process group ID and session ID.

Ruptime command.
ruptime command tells the status of local networked machines.
ruptime options
options.
• -a include user even if they've been idle for more than one hour.
• -l sort by load average.
• -r reverse the sort order.
• -t sort by uptime.
• -i sort by number of users.

Shutdown command.
Shutdown command can only be executed by root. To gracefully bring down a system, shutdown command is used.
options.
• -gn use a grace-period of n seconds (default is 60).
• -ik tell the init command to place system in a state k.
o s single-user state (default)
o 0 shutdown for power-off.
o 1 like s, but mount multi-user file systems.
o 5 stop system, go to firmware mode.
o 6 stop system then reboot.
• -y suppress the default prompt for confirmation.

Stty command
stty command sets terminal input output options for the current terminal. without options stty reports terminal settings.
stty options modes < device options • -a report all options. • -g report current settings. Modes • 0 hang up phone. • n set terminal baud. • erase keyname, will change your keyname to be backspace key. Who command who command displays information about the current status of system. who options file Who as default prints login names of users currently logged in. Options • -a use all options. • -b Report information about last reboot. • -d report expired processes. • -H print headings. • -p report previously spawned processes. • -u report terminal usage. Advance unix command concepts Put advance commands utilities, redirection, etc here. cal > cal.txt To create a new file called cal.txt that has calendar for current month. > sign redirects output from stdout (screen) to a file.