Вы находитесь на странице: 1из 24

man

Description: man is the system's manual viewer; it can be used to display


manual pages, scroll up and down, search for occurrences of specific text,
and other useful functions.
Syntax: man command
Example : man cp
Output: It will give all details about cp command.
Options:
-h, --help

-- Print a help message and exit.

-V, --version

-- Display version information and exit.

who
Description:
The who command prints information about all users who are currently
logged in.
Syntax: who
Output: displays the information of users logged on to the system
Options:
q--- Displays all login names, and a count of all logged-on users.
Who am i--Displays the username, line, and time of currently user logged.

cat

cat stands for "catenate." It reads data fromfiles, and outputs their
contents. It is the simplest way to display the contents of a file at
the command line.

Overview
cat is one of the most commonly-used commands in Linux. It can be used
to:

Display text files


Copy text files into a new document
Append the contents of a text file to the end of another text file,
combining them

Syntax: cat filename


Example: cat a.txt
Displaying Text Files
The simplest way to use cat is to simply give it the name of a text file. It will
display the contents of the text file on the screen

Example: cat a.txt


Create A Text File
This simple creates the text file and we can insert data into the file and also
can see the contents of file on the screen.

Example: cat > a.txt


Enter data into a.txt and close file by pressing ctrl+d.
Cat a.txt ---to see the contents of file.
>>--- can be used to append two or more file with cat
Example: cat a.txt >>b.txt
will read the contents of a.txt and write them at the end of b.txt. If b.txt
does not already exist, it will be created and the contents of a.txt will be
written to the new file.

cd
The cd command, which stands for "change directory", changes
the shell's current working directory.

Description
The cd command is one of the commands you will use the most at
the command line in linux. It allows you to change your working directory.
You use it to move around within the hierarchy of your file system.

Syntax: cd dirname
Example: cd /home/14KN1A1213.
Will change from current directory to 14KN1A1213 directory.

Options:
cd /

will change to root directory

cd ~ will change to home directory.


Note: cd (enter) will also change to home directory.

Representing The Parent Directory


The parent directory of the current directory in other words, the directory
one level up from the current directory, which contains the directory we're in
now is represented by two dots ("..").
So, If we were in the directory /home/username/documents, and we
executed the command

Command:

cd ..

we would be placed in the directory /home/username.

So, If we were in the directory /home/username/documents, and we


executed the command
Command: cd ../../
we would be placed in the directory /home.

CP

Description
The cp command is used to make copies of files and directories.

Syntax: cp [OPTION]... SOURCE... DESTINTION.


Example: cp origfile newfile
Output: Creates a copy of the file in the working directory named newfile,
and will be located in the working directory.
Options:
-i interactive
cp -i oldfile newfile
you will be prompted:
cp: overwrite newfile?
If you type y (or yes, Y, YES, or any other combination of upper and
lowercase of these), then newfile will be overwritten with a copy
of origfile. Typing anything else will abort the operation.
-R recursive (coping all contents of a directory and sub-directories
cp -R /one/two /three/four

Copy the directory two (located in the directory /one), and


everything two contains, into the destination directory /three/four. The result will
be called /three/four/two. The directory /three must already exist for the
command to succeed. If the directoryfour does not already exist in the
directory /three, it will be created.

-f force

----

COPIES FILES FORCEFULLY.

-v, verbose ---Verbose mode; explain what is being done.

ps
Reports a snapshot of the status of currently running processes.

Description
On every UNIX-like operating system, the process status command (ps)
displays information about active processes. Every operating system's
version of ps is slightly different, so consult your own documentation for
specific options.
Syntax: ps options
Example: ps -e
Output: displays all the processes running on system. (e option also do the
same).

ls
Lists the contents of a directory.

Description

List information about the FILEs (the current directory by default). Sort
entries alphabetically .

Syntax: ls [OPTION]... [FILE]...


Suppose you are in directory /home/14KN1A1213
Example: ls
Output : lists all files in the directory 14KN1A1213.
Options:
-l long listing of files
t Time stamp--- listing along with time stamps( files will be sorted based
upon last time file has changed ).
r recursive listsing includes sub-directories files also .

mv
The mv command is used to move or rename files.

Description
mv renames file SOURCE to DEST, or moves theSOURCE file (or files)
to DIRECTORY.
Note: mv is like cut and paste. The source file will be deleted after
mv is performed.

Syntax: mv source destination.


Example: mv /home/a.txt /home/IT/b.txt.
Output: a.txt which is present in home is moved to IT directory as
b.txt and a.txt is deleted(a.txt is renamed as b.txt).

Options:
-f, force forcefully moves the existing files.
-i, interactive Prompt before overwriting each existing destination
file, regardless of the file's permissions. If the answer to the prompt is
negative, the file is skipped.
-v verbose Verbose mode; explain what is being done.

rm
The rm command removes (deletes) files .

Description
rm removes each specified FILE. The removal process unlinks a filename in
a filesystem from data on the storage device, and marks that space as
usable by future writes. In other words, removing files increases the amount
of available space on your disk .The data itself is not destroyed, but after
being unlinked, it becomes inaccessible. Remove your files wisely! The
effects of an rm operation cannot be undone.

Syntax: rm options filename.


Example: rm /home/14kN11213/a.txt

Output: it removes the file a.txt in directory 14KN1A1213.


Options:
-f force

----

-v, verbose

removes files forcefully .


---Verbose mode; explain what is being done.

-i, interactive --Prompt before removing(need to give y to remove) .


-r, recursive --removes files recusively(including sub-directories)

mkdir
Short for "make directory", mkdir is used to create directories on a file
system.

Description
If the specified DIRECTORY does not already exist,mkdir creates it.
More than one DIRECTORY may be specified when calling mkdir.

Syntax: mkdir options directory name


Example: mkdir abc
Output: will create a directory abc on working directory.
Options:

-p parent directory --- Create parent directories as necessary.


Example: mkdir p a/b/c ---- (it creates A and in A sub-directory B will be
created and in B sub-directory C will be created.) ABC.
mkdir -p /home/a/b/c--------Creates the directory /home/a/b/c. If the
parent directory/home/a/b does not already exist, mkdir will create that
directory first.
-v, verbose

---Verbose mode; explain what is being done.

rmdir
Removes a directory.

Description
The rmdir utility removes the directory entry specified by each directory
argument, provided the directory is empty.
Syntax: rmdir options directory name.
Example: rmdir /home/14KN1A1213/ddd
Output: the directory ddd will be removed if it is an empty directory.

Example: rmdir p /home/14KN1A1213/ddd

Output: the directory ddd will be removed if it is an empty directory.


Note: both commands will give same output
-v, verbose

---Verbose mode; explain what is being done.

chmod
chmod is used to change the permissions of files or directories.

Overview

On Linux and other Unix-like operating systems, there is a set of rules


for each file which defines who can access that file, and how they can
access it. These rules are called file permissions or file modes. The
command name chmod stands for "change mode", and it is used to
define the way a file can be accessed.
Before continuing, you should read the section What Are File
Permissions, And How Do They Work? in our documentation of the
umask command. It contains a comprehensive description of how to
define and express file permissions.
In general, chmod commands take the form:
Syntax: chmod options permissions filename
Example: chmod R 777 cd.txt
Output: the permissions of the file cd.txt has been changed .
If no options are specified, chmod modifies the permissions of the file
specified by filename to the permissions specified by permissions.
permissions defines the permissions for the owner of the file (the
"user"), members of the group who owns the file (the "group"), and
anyone else ("others"). There are two ways to represent these
permissions: with symbols (alphanumeric characters), or with octal
numbers (the digits 0 through 7).

Let's say you are the owner of a file named myfile, and you want to set
its permissions so that:
the user can read, write, and execute it;
members of your group can read and execute it; and
others may only read it.
This command will do the trick:
Example: chmod u=rwx,g=rx,o=r myfile (symbolic way)
This is an example of using symbolic permissions notation. The letters
u, g, and o stand for "user", "group", and "other". The equals sign
("=") means "set the permissions exactly like this," and the letters "r",
"w", and "x" stand for "read", "write", and "execute", respectively. The
commas separate the different classes of permissions, and there are
no spaces in between them.
Here is the equivalent command using octal permissions notation:
Example: chmod 754 myfile
Here the digits 7, 5, and 4 each individually represent the permissions
for the user, group, and others, in that order. Each digit is a
combination of the numbers 4, 2, 1, and 0:
4-- stands for "read",
2-- stands for "write",
1-- stands for "execute", and
0-- stands for "no permission."
So 7 is the combination of permissions 4+2+1 (read, write, and
execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0
(read, no write, and no execute).

more

Displays text, one screen at a time.

Description
more is a filter for paging through text one screen at a time. It does not
provide as many options or enhancements as less, but is nevertheless quite
useful and simple to use.
Syntax: more options filename
Example: more a.txt
Output: displays the contents of a.txt and asks user to press space to see
more content of file.
Options:
-d With this option, more will prompt the user with the message [Press
space to continue, 'q' to quit.].
-p Do not scroll. Instead, clear the whole screen and then display the text.

finger
finger looks up and displays information about system users.
Syntax: finger
Output: displays thee information about the user.
Example: finger

(here write the out put from observation).

pwd
Print the name of the working directory.

Description
pwd prints the full pathname of the current working directory.
Syntax: pwd
Example: pwd
Output: /home/14KN11213.

cal
Display a conveniently-formatted calendar from the command line.

Description
If no options are given, cal displays the current month at the command line. It's a
quick and convenient way to glance at the dates of the month.
Syntax: cal options
Example: cal -1
Output: displays calendar of present month
Options:

-1 Display a single month. This is the default.

-3 Display three months: last month, this month, and next month.
-s Display the calendar using Sunday as the first day of the week.
-m Display Monday as the first day of the week.
-y Display a calendar for the entire current year.

kill
kill is used to send a signal to a process.

Description
The default signal for kill is TERM (which will terminate or "kill" the process).
Syntax: kill -9 pid
Example: kill -9 123
Output: It kills the process with pid 123.
Note: It cannot kill a process with id -1.

Logout
logout command and example
If you are logged in as an user and just wanted to exit a login shell
type logout command
Syntax: $ logout.
Output: You will be logout of a login shell session or secure shell
session.

Shutdown
It can be used to shutdown the linux system

Syntax: shutdown.

History
It is possible to recall previous commands by using the cursor keys,
however it is also possible using the history command.
Issuing the history command will show the commands previously
entered, you may want to pipe this through tail to just see the most
recent.
Syntax: history
Example: history
Output: displays all the previous commands.

The vi Editor
Introduction:
vi is a powerful editor with many features. It can handle very large files
much easier than a program like Microsoft Word. Unlike Word, vi is only a
TEXT EDITOR and you cannot include graphics or fancy fonts in your file
the vi editor typically functions in three different modes:
1. Command mode
2. Insert mode
3. colon mode

1) vi command mode
When you first start editing a file with the vi editor you will be in vi
command mode. In this mode you can issue many vi commands, including
commands like insert, append, and delete, and other search and navigation
commands that let you move around your file.
Possibly the most important thing to know is that when you're in command
mode you can't insert text immediately. You first need to issue
an insert,append, or open command to insert text.

2) vi insert mode
Once you issue a vi insert, append, or open command, you will be in vi
insert mode. If you're working with a modern vi or vim implementation, your
vi editor is typically configured to show the current mode of operation, so
when you go into insert mode, you'll see a text string like this on the last
line of your vi editor window:
-- INSERT At this point you can (a) type text into your file and (b) use the arrow keys
to navigate around your file just as you would do with any other text editor.
A very important concept to know is that when you're in vi insert mode, but
you want to switch back to vi command mode, you easily move back to
command mode by pressing the [Esc] key.

3) vi colon mode
The last vi mode is known as vi colon mode. You can only get to colon mode
from command mode, and you get into last line mode by pressing the colon
key, like this:
press {esc} and then press{ :}colon
After pressing this key, you'll see a colon character appear at the beginning
of the last line of your vi editor window, and your cursor will be moved to
that position. This indicates that vi is ready for you to type in a "last line
command".
From this vi command prompt you can do all sorts of really amazing things.
You can do simple things, like quitting your vi session, like this:

:q means quit
:q!--> means quit forcely
:wq means save and quit

Editing A File
The most common way to start a vi session is to tell it which file to edit. To
edit a file named filename, use the command:
Example: vi filename
The screen will clear and the text of your file will appear on the screen. If
filename doesn't exist yet, vi will start you in a new file, and when you tell it
to save your work, it will use the filename that you specified.
Arrow Keys
On most terminals, you can use the arrow keys to move the cursor around.
Left and right moves the cursor left or right one character, and up and down
move the cursor up or down one line. The other way to move the cursor is
with the h, j, k, and l keys
h

left

down

up

right

Searching
Another way to position yourself in the file is by giving the editor a string to
search for. If you type "/" followed by a string of characters and press Enter,
the editor will search for the next occurrence of this string in your file, and
place the cursor there. Pressing n will go to the next occurrence after that.
If instead of forward, you want to search backward for a string, use ?
instead of /. In a ? string search, pressing n will take you to successive
occurrences in the same (backward) direction.
Example: /abc
Output: searches and highlights occurrence of abc in text .
Other Options:

SPACE

advance the cursor one position

repeats the last change command

opens and inputs a new line, above the current line

opens and inputs new lines, below the current line

undoes the changes you made to the current line

appends text after the cursor

appends text at the end od the line

deletes the object that you specify

dd

deletes a line

4dd

deletes 4 line from cursor line

inserts text before the cursor

inserts text at the start of line

deletes a char on which cursor is placed

undoes the last change.

echo
echo displays a line of text.

Overview
echo is a fundamental command found in mostoperating systems that offer
a command line. It is frequently used in scripts, batch files, and as part of
individual commands; anywhere you may need to insert text.

Syntax: echo [options] string.


Example: echo abc
Output: abc will be displayed on terminal.
Options:

\b

Backspace.

\c

Produce no further output after this.

\e

The escape character; equivalent to pressing the escape key.

\f

A form feed.

\n

A newline.

\r

A carriage return.

\t

A horizontal tab.

\v

A vertical tab.

Echo Examples
Example1: echo Hello, World!
Output: Hello, world!
example2: x=10
echo The value of x is $x.
Output: The value of x is 10.
Example3: echo -e 'Here \bthe \bspaces \bare \bbackspaced.'
Output: Herethespacesarebackspaced.
Example4: echo -e 'Here\nwe\nhave\ninserted\nnewlines.'
Output:

Here
we
have
inserted
newlines.

Example5: echo -e 'Here\twe\thave\tinserted\thorizontal\ttabs.'


Output: Here

we

have

inserted

horizontal

tabs.

Example6: echo -e 'This line is not completely \cprinted.'


Output: This line is not completely
Example7: echo 'This text is now in a text file.' > textfile.txt
Output: Writes the text This text is now in a text file. to the file textfile.txt.
If textfile.txt does not exist, it will be created; if textfile.txt already exists, it
will be overwritten.
Example8: echo 'This text is now in a text file.' >> textfile.txt
Output: Appends the text This text is now in a text file. to the file
textfile.txt. If textfile.txt does not exist, it will be created.
Example9: echo *
Output: Output a string comprising the name of each file in the working
directory, with each name separated by a space. For example, if you have
three files in your working directory, output may resemble the following:
flower.jpg document.doc readme.txt.

LINUX/UNIX FILE SYSTEM(TREE STRUCTURE)

Linux filesystem structures and understand the meaning of individual highlevel directories.
1. / Root
Every single file and directory starts from the root directory.
Only root user has write privilege under this directory.
Please note that /root is root users home directory, which is not same as /.
2. /bin User Binaries
Contains binary executables.Common linux commands you need to use in
single-user modes are located under this directory.Commands used by all
the users of the system are located here.
For example: ps, ls, ping, grep, cp.
3. /sbin System Binaries
Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used typically by
system aministrator, for system maintenance purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
4. /etc Configuration Files
Contains configuration files required by all programs.

This also contains startup and shutdown shell scripts used to start/stop
individual programs.
For example: /etc/resolv.conf, /etc/logrotate.conf
5. /dev Device Files
Contains device files.
These include terminal devices, usb, or any device attached to the system.
For example: /dev/tty1, /dev/usbmon0
6. /proc Process Information
Contains information about system process.
This is a pseudo filesystem contains information about running process. For
example: /proc/{pid} directory contains information about the process with
that particular pid.
This is a virtual filesystem with text information about system resources. For
example: /proc/uptime
7 /tmp Temporary Files
Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.
8. /home Home Directories
Home directories for all users to store their personal files.
For example: /home/14KN1A1213, /home/14KN11233
9. /boot Boot Loader Files
Contains boot loader related files.
Kernel initrd, vmlinux, grub files are located under /boot
For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic
10. /lib System Libraries
Contains library files that supports the binaries located under /bin and /sbin
Library filenames are either ld* or lib*.so.*
For example: ld-2.11.1.so, libncurses.so.5.7

Вам также может понравиться