Man, CP, RM ... Command in Linux
Man, CP, RM ... Command in Linux
Man, CP, RM ... Command in Linux
-V, --version
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:
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 /
Command:
cd ..
CP
Description
The cp command is used to make copies of files and directories.
-f force
----
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 .
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.
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.
----
-v, verbose
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.
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.
chmod
chmod is used to change the permissions of files or directories.
Overview
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
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
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:
-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
dd
deletes a line
4dd
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.
\b
Backspace.
\c
\e
\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.
we
have
inserted
horizontal
tabs.
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