Linux Command Usage
• Linux is traditionally used as a command line
operated OS. Even today when lot many GUIs are
available, the Linux pro’s prefer to use the
command line.
• The Linux commands are typed on a terminal
window.
Finder=>Application=>Utilities=>Terminal
• The command prompt will be displayed as
[someone]$
Linux Command Structure
• A Linux command consists of 3 parts –
Command name, Options, Arguments
E.g. [someone~]$command-name -optA -optB
arg1 arg2
• Command name – case sensitive, special commands
start with a dot ( .)
• Each option is prefixed with a dash (-), the
option, most of the times, is a single letter,
but sometimes two or more letters.
• Arguments depend on the command, usually
file/directory names or sometimes strings or
numbers also.
Command line Options and Arguments
• No spaces within the command name or option or
argument. No space between the dash(-) and the
option name
• There must be at least one space between each
individual component of the command viz.
command, options and arguments
• Some special arguments :
• . (a dot): specifies current directory
• .. (two dots without space) : parent of current
directory
• stdin : standard input i.e. keyboard treated as file
• stdout : standard output i.e. the display screen of
the computer treated as file
• stderr : standard error output device usually screen
Relative and Absolute path
• Path is the position of the file (or directory)
in the file system
• The path can be either absolute or relatie.
• Absolute path starts from root directory (/)
all the way up to the file that you want to
access.
• Relative path starts from your current
directory. So relative path changes depending
on what is your present current directory.
• Dot (.) and dot dot (..) are used to specify
current and parent directory respectively in
the path.
File Name
• File name is Linux must ve less than 256
characters.
• Combination of letter, number or some special
symbols (a hyphen, underscore, dot etc)
allowed. Metacharacters (the symbols which have
special meaning) like $,*,? Etc are not
allowed.
• File can be prefixed with full path name.
Command Structure (Continued)
• The commands can be optionally suffixed by any
of the following modifiers –
• & (the Ampersand symbol): this will run the command
in background and the control will immediately
return to the terinal window without waiting for the
command to be over.
• > (the greater than symbol): this will re-direct the
output of the command to a specified file
• < (the less than symbol): this will take input to
the command from a specified file (instead of
keyboard)
• | (the vertical bar): this will redirect output of
the command to another command specified after |
Some Command Examples
• A few example commands given below –
(details we will cover in next session)
• ls : lists files in a directory
• cat : prints file on display screen
• cd : change current directory
• pwd : print current working directory
• rm file : delete specified file
• rmdir dir : remove (delete) directory
• cp file1 file2 : copy file1 to file2
• mv file1 file2 : rename file1 to file2
Most commonly used Linux commands
• File handling
• ls : lists files in a directory
• cat / head / tail : prints file on display screen.
Head and tail will print first 10 and last 10 lines
respectively
• more filename : same as cat but user controlled
scroll.
• cd : change current directory
• pwd : print current working directory
• rm file : delete specified file
• rmdir dir : remove (delete) directory
• cp file1 file2 : copy file1 to file2
• mv file1 file2 : rename file1 to file2
• touch file : change time stamp of a file or create a
new empty file (if it is not existing)
4
Most commonly used Linux commands
• Process handling
• ps : process status
• kill -9 : kill a process
• Locating resources
• whereis <command or file>: find location of acommand
(or any other resource) in the directory structure
• whatis <command> : brief information about command
• man <command> : detailed manual entry of command.
• User management
• who : identify who is currently logged in on the
system
• whoami : identify user id of self
• passwd : change password
5
Most commonly used Linux commands
• Tools/Utilities
• bc : basic calculator
• grep string filename : search a string in file(s)
• sed : stream editor (modifies a string in files)
• date : print / set date and time of the system
• cal : calendar
• Disk related
• du : report disk usage in the system
• df : report file usage