0% found this document useful (0 votes)
45 views

Ual Command.: Man Man

The document provides summaries of various Linux commands including man, banner, cal, clear, tty, pwd, ls, mkdir, cd, cat, head, tail, more, wc, cp, mv, ln, rm, rmdir, cmp, grep, find, vi, chmod and their usage. It explains what each command is used for and provides examples of commonly used options and parameters for these commands.

Uploaded by

prasanna_erudite
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Ual Command.: Man Man

The document provides summaries of various Linux commands including man, banner, cal, clear, tty, pwd, ls, mkdir, cd, cat, head, tail, more, wc, cp, mv, ln, rm, rmdir, cmp, grep, find, vi, chmod and their usage. It explains what each command is used for and provides examples of commonly used options and parameters for these commands.

Uploaded by

prasanna_erudite
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

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.
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.

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.

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.
Cat command
cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).

Head command.
head filename by default will display the first 10 lines of a file.
If you want first 50 lines you can use head -50 filename or for 37 lines head -37 filename and so
forth.

Tail command.
tail filename by default will display the last 10 lines of a file.
If you want last 50 lines then you can use tail -50 filename.

More command. more command will display a page at a time and then wait for input which is
spacebar. For example if you have a file which is 500 lines and you want to read it all. So you
can use

more filename

Wc command
wc command counts the characters, words or lines in a file depending upon the option.

Options

 wc -l filename will print total number of lines in a file.


 wc -w filename will print total number of words in a file.
 wc -c filename will print total number of characters in a file.

Cp command.
cp command copies a file. If I want to copy a file named oldfile in a current directory to a file
named newfile in a current directory.
cp oldfile newfile
If I want to copy oldfile to other directory for example /tmp then
Mv command.
mv command is used to move a file from one directory to another directory or to rename a file.

Some examples:

 mv oldfile newfile will rename oldfile to newfile.


 mv -i oldfile newfile for confirmation prompt.
 mv -f oldfile newfile will force the rename even if target file exists.
 mv * /usr/bajwa/ will move all the files in current directory to /usr/bajwa directory.

Ln command.
Instead of copying you can also make links to existing files using ln command.
If you want to create a link to a file called coolfile in /usr/local/bin directory then you can enter
this command.
ln mycoolfile /usr/local/bin/coolfile

Some examples:

 ln -s fileone filetwo will create a symbolic link and can exist across machines.

Rm command.
To delete files use rm command.

Options:

 rm oldfile will delete file named oldfile.


 rm -r option will delete the entire directory as well as all the subdirectories, very
dangerous command.

Rmdir command.
rmdir command will remove directory or directories if a directory is empty.

Options:
 rm -r directory_name will remove all files even if directory is not empty.

Comparison and Searching

Cmp command.
cmp command compares the two files. For exmaple I have two different files fileone and filetwo.

cmp fileone filetwo will give me

fileone filetwo differ: char 80, line 4

if I run cmp command on similar files nothing is returned.


-s command can be used to return exit codes. i.e. return 0 if files are identical, 1 if files are
different, 2 if files are inaccessible.

Grep Command
grep command is the most useful search command. You can use it to find processes running on
system, to find a pattern in a file, etc. It can be used to search one or more files to match an
expression.
It can also be used in conjunction with other commands as in this following example, output of
ps command is passed to grep command, here it means search all processes in system and find
the pattern sleep.
ps -ef | grep sleep will display all the sleep processes running in the system as follows.

ops 12964 25853 0 16:12:24 ttyAE/AAES 0:00 sleep 60


dxi 12974 15640 0 16:12:25 ttyAH/AAHP 0:00 sleep 60
ops 12941 25688 0 16:12:21 ttyAE/AAEt 0:00 sleep 60
ops 12847 25812 0 16:11:59 ttyAH/AAH6 0:00 sleep 60
ops 12894 25834 0 16:12:12 ttyAE/AAEX 0:00 sleep 60
dxi 13067 27253 2 16:12:48 ttyAE/ABEY 0:00 sleep 1
ops 13046 25761 0 16:12:44 ttyAE/AAE0 0:00 sleep 60
dxi 12956 13078 0 16:12:23 ttyAG/AAG+ 0:00 sleep 60
ops 12965 25737 0 16:12:24 ttyAE/AAEp 0:00 sleep 60
ops 12989 25778 0 16:12:28 ttyAH/AAHv 0:00 sleep 60
ssb 13069 26758 2 16:12:49 ttyAH/AAHs 0:00 grep sleep
pjk 27049 3353 0 15:20:23 ? 0:00 sleep 3600
Find command.
Find command is a extremely useful command. you can search for any file anywhere using this
command provided that file and directory you are searching has read write attributes set to you
,your, group or all. Find descends directory tree beginning at each pathname and finds the files
that meet the specified conditions. Here are some examples.

Some Examples:
find /work -name chapter1 -print will list all files named chapter1 in /work directory.

Vi editor.
vi command launches a vi sual editor. To edit a file type
vi filename
vi editor is a default editor of all Unix systems. It has several modes. In order to write characters
you will need to hit i to be in insert mode and then start typing. Make sure that your terminal has
correct settings, vt100 emulation works good if you are logged in using pc.
Once you are done typing then to be in command mode where you can write/search/ you need to
hit :w filename to write
and in case you are done writing and want to exit
:w! will write and exit.

options:

 i for insert mode.


o I inserts text at the curson
o A appends text at the end of the line.
o a appends text after cursor.
o O open a new line of text above the curson.
o o open a new line of text below the curson.
 : for command mode.
o <escape> to invoke command mode from insert mode.
o :!sh to run unix commands.
o x to delete a single character.
o dd to delete an entire line
o ndd to delete n number of lines.
o d$ to delete from cursor to end of line.
o yy to copy a line to buffer.
o P to paste text from buffer.
o nyy copy n number of lines to buffer.
o G to go to last line in file.
o 1G to go to the first line in file.
o w to move forward to next word.
o b to move backwards to next word.
o $ to move to the end of line.
o J join a line with the one below it.
 /string to search string in file.
 n to search for next occurrence of string.

System Status

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.

You might also like