Linux 4-6 - Linux Commands and Editors
Linux 4-6 - Linux Commands and Editors
Module-2
OSSD (21B12CS320)
B.Tech.(CSE-6th Sem)
JIIT, Noida
Where are these commands
located?
Directories:
/bin
/sbin
/usr/bin
/usr/sbin
Command Structure
command [-option(s)] [argument(s)]
the command;
any options required by the command
the command's arguments (if required).
OptionsMUST come after the command and before any command
arguments
Options SHOULD NOT appear after the main argument(s)
However, some options can have their own arguments!
More About Options
All options are preceded by a hyphen (-)
Options without arguments may be grouped after the
hyphen
The first option argument, following an option, must be
preceded by white space. For example -o sfile is valid but
-osfile is illegal.
Option arguments are not optional
More About Options
All options must precede other arguments on the command
line
A double hyphen -- may be used to indicate the end of the
option list
The order of the options are order independent
The order of arguments may be important
A single hyphen - is used to mean standard input
man
• Manual Pages
• Contains information about almost everything
- Other Commands
- System Calls
- C Library Functions
Syntax:
man <command name>
Example:
$ man ls
which
• Displays a path name of a command
• Searches a path environmental variable for the
command and displays the absolute path
Syntax:
which <command name/app>
Example:
$ which sh (shows which sh is actually in use)
whereis
• Display all locations of a command (or some other
binary, man page, or a source file).
• Searches all directories to find commands that
match the argument
Syntax:
whereis <command name>
Example:
$ whereis sh
passwd
• Change your login password.
Syntax:
passwd
passwd <username>
Example:
$ passwd user1
date
• Displays dates in various formats
Example :
Example:
$ alias dt='date'
$ dt
history
• Display a history of recently used commands
Syntax:
history <option>
Example:
$history 10
exit
• Exit from your login session.
• Example :
• $ exit
shutdown
• Causes system to shutdown or reboot
• May require super-user privileges
• Example:
$ shutdown -h now ( stop )
$ shutdown -r now ( reboot )
File Management Commands
ls
• Lists directory contents
Syntax:
ls <option>
Examples:
$ ls (lists all files except those starting with a “.”)
$ ls -a
$ ls -l
$ ls -al
cat
• Takes a copy of a file and sends it to the
standard output
Syntax:
cat <filename>
Example:
$ cat link.txt
more
• Display contents of large files page by page
or scroll line by line up and down.
• Syntax:
more <option> <filename>
Examples:
$ more a.txt (press enter to see next page content)
$ more -s a.txt (squeeze multiple space line into single)
cp
• Copies files/directories
Syntax:
$ cp <options><source> <destination>
Example:
$ cp a.txt b.txt
F1 = help
or :help
:help <command>
:q to exit help window
vi Editor Commands
Delete characters
x deletes character under the cursor
Insert characters
i converts to insert mode
then type characters
<esc> to exit insert mode
vi Editor Commands
Insert lines
o = open line below cursor
O = open line above cursor
<esc> to exit insert mode
Append characters
A converts to insert mode at end of a line
then type characters
<esc> to exit insert mode
vi Editor Commands
Deletion
d$ deletes to end of line
dw deletes to beginning of next word
de deletes to end of current word
d + motion
Using motions for movement
Use any of the motions above
Use count for repetition
2w = move cursor two words forward
0 = start of line
vi Editor Commands
Using repetition as part of deletion
2dw deletes next two words
Deleting a line
dd = delete line
2dd = delete two lines
Undo
u = undo one command
U = restore a line
cntl-R = redo a command
vi Editor Commands
p = put back the deleted text (in new place)
one of the delete command above + put = cut-and-paste
More general cut-and-paste
v = start visual mode (start block)
move cursor to end of block
y = yank (copy to buffer)
then p = put in new place
vi Editor Commands
Location
ctrl-g = show position in file
G = go to bottom of file
gg = go to top of file
<number>G = go to line <number>
vi Editor Commands
Search
/<phrase> = search
/<phrase>\c = ignore case
?<phrase> = search backwards
n = repeat search
N = repeat search in the other direction
cntl-o = move backward one instance
cntl-i = move forward one instance
Search for matching parentheses
Put cursor on (, [ or {
% = go to matching one
% = go to first one again
vi Editor Commands
Files
:w filename = write a file (save)
:!ls = list directory
:!xx = any command
Substitute (replace)
:s/thee/the = changes first one
:s/thee/the/g = changes all (global change)
:s/thee/the/gc = change all with query
:#,#/thee/the/g = only change within that line range
Emacs Editor
originally started as editor macros in 1976
Gosling Emacs available for Unix in 1981
GNU Emacs created by Richard Stallman in 1984
very popular editor on Unix until recently
history: editor war: emacs vs. vi
uses lisp-like macro language for powerful features and extensions:
programming language sensitive editing
email client
news reader
has built-in tutorial: ^h-t
THE PICO AND NANO EDITORS
part of the popular pine mail utility on UNIX
developed by the University of Washington
pico = pine email composer
nano is improved open source of pico available for GNU/Linux
very intuitive operation
on-screen guide and help
GUI Editors
use onscreen direct manipulation via mouse and menus
gedit
xedit
require to run X11 window server
What’s Next?
Shell, AWK, SED
Some Linux Utilities