Practical uses of Linux Command
1.
cp
a.
It is a command which is used to copy the files or directories from
one place to another place.
Example:
~$
cp Topics.odt /home/anil/Downloads/
~$
Real
Time Problem: Suppose you are working in a company and
your manager ask you to copy the file in one more location. At this
point of time above example help you.
b.
We can preserve the permission of the files or directories while
copying from source to destination.
Example:
~$
cp -dR --preserve=all Text.txt /home/anil/Downloads
Real
Time Problem:
Suppose you are working in a company and your manager ask you to copy
the file in to another location by preserving the ownership and
permission of the file. At this point of time above example help you.
2.
scp
a.
It is a command which is used to copy files over the network between
the host.
Example:
~#
scp /home/anil/Text.txt anil@127.0.0.1:/home/anil
anil@127.0.0.1's
password:
Text.txt
100% 38 0.0KB/s 00:00
Real
Time Problem:
Suppose you are working in a company and your manager ask you to copy
the file in to another remote machine . At this point of time above
example help you.
b.
We can use v option to debug messages about their progress ,
authentication and configuration
problems.
Example:
~#
scp -v /home/anil/Text.txt anil@127.0.0.1:/home/anil
Executing:
program /usr/bin/ssh host 127.0.0.1, user anil, command scp -v -t
/home/anil
OpenSSH_6.6.1,
OpenSSL 1.0.1f 6 Jan 2014
debug1:
Reading configuration data /etc/ssh/ssh_config
debug1:
/etc/ssh/ssh_config line 19: Applying options for *
debug1:
Connecting to 127.0.0.1 [127.0.0.1] port 22.
debug1:
Connection established.
debug1:
permanently_set_uid: 0/0
debug1:
identity file /root/.ssh/id_rsa type -1
debug1:
identity file /root/.ssh/id_rsa-cert type -1
debug1:
identity file /root/.ssh/id_dsa type -1
debug1:
identity file /root/.ssh/id_dsa-cert type -1
debug1:
identity file /root/.ssh/id_ecdsa type -1
debug1:
identity file /root/.ssh/id_ecdsa-cert type -1
debug1:
identity file /root/.ssh/id_ed25519 type -1
debug1:
identity file /root/.ssh/id_ed25519-cert type -1
debug1:
Enabling compatibility mode for protocol 2.0
debug1:
Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1:
Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1
Ubuntu-2ubuntu2.8
debug1:
match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat
0x04000000
debug1:
SSH2_MSG_KEXINIT sent
debug1:
SSH2_MSG_KEXINIT received
debug1:
kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1:
kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1:
sending SSH2_MSG_KEX_ECDH_INIT
debug1:
expecting SSH2_MSG_KEX_ECDH_REPLY
debug1:
Server host key: ECDSA
a2:a9:cf:6f:4a:39:51:bd:64:31:a6:70:6b:dc:4d:01
debug1:
Host '127.0.0.1' is known and matches the ECDSA host key.
debug1:
Found key in /root/.ssh/known_hosts:13
debug1:
ssh_ecdsa_verify: signature correct
debug1:
SSH2_MSG_NEWKEYS sent
debug1:
expecting SSH2_MSG_NEWKEYS
debug1:
SSH2_MSG_NEWKEYS received
debug1:
SSH2_MSG_SERVICE_REQUEST sent
debug1:
SSH2_MSG_SERVICE_ACCEPT received
debug1:
Authentications that can continue: publickey,password
debug1:
Next authentication method: publickey
debug1:
Trying private key: /root/.ssh/id_rsa
debug1:
Trying private key: /root/.ssh/id_dsa
debug1:
Trying private key: /root/.ssh/id_ecdsa
debug1:
Trying private key: /root/.ssh/id_ed25519
Real
Time Problem:
Suppose you are working in a company and your manager ask you to copy
the file in to another remote machine but while copying you are
getting some error . At this point of time above example help you.
3.
rsync
a.
It is a fast and extraordinarily versatile file copying tool.
Example:
~#
rsync /home/anil/Text.txt anil@127.0.0.1:/home/anil
anil@127.0.0.1's
password:
b.
-avz option is used to sync the file by preserving the ownership and
permission.
Real
Time Problem:
Suppose you are working in a company and your manager ask you to sync
the source and destination folder. At this point of time above
example help you.
Example:
~#
rsync -avz /home/anil/T* /home/anil/Downloads/
sending
incremental file list
sent
205,086 bytes received 287 bytes 136,915.33 bytes/sec
total
size is 242,625 speedup is 1.18
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
preserve the ownership and permission of the files while copying the
files. At this point of time above example help you.
4.
mv
a.
It is a linux command which is used to rename the files.
Example:
~$
mv Text.txt New.txt
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
rename the file. At this point of time above example help you.
5.
SSH
a.
It is a program for logging into a remote machine and for executing
commands on a remote
machine.
Example:
~$
ssh anil@localhost
anil@localhost's
password:
Welcome
to Ubuntu 14.04.4 LTS (GNU/Linux 4.2.0-27-generic x86_64)
*
Documentation: https://help.ubuntu.com/
655
packages can be updated.
0
updates are security updates.
New
release '16.04.5 LTS' available.
Run
'do-release-upgrade' to upgrade to it.
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
login to the specific remote machine. At this point of time above
example help you.
b.
With the help of ssh we can execute the commands on a remote machine.
Example:
~#
ssh anil@localhost ls
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
login to the remote system and run the ls command. At this point of
time above example help you.
6.
dmesg
a.
It is a linux command which is used to read all messages from kernel
ring buffer.
Example:
~$
dmesg
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
login to the remote system and check the kernel messages. At this
point of time above example help you.
b.
We can read all the kernel messages with timestamp by using option -T
along with dmesg command.
Example:
~$
dmesg -T
[Tue
Oct 30 11:24:05 2018] traps: chrome[5119] trap invalid opcode
ip:55ea9a282f7b sp:7ffc8ad4aa30 error:0 in
chrome[55ea96009000+5df9000]
[Tue
Oct 30 11:24:29 2018] traps: chrome[5255] trap invalid opcode
ip:55ea9a282f7b sp:7ffc8ad4aad0 error:0 in
chrome[55ea96009000+5df9000]
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
login to the remote system and check the kernel messages with
timestamp. At this point of time above example help you.
7.
lsof
a.
It lists all the open files related belonging to all active
processes.
Example:
~$
lsof
BrowserBl
2488 2803 anil mem REG 8,1 34624
12591322 /usr/lib/x86_64-linux-gnu/libogg.so.0.8.1
BrowserBl
2488 2803 anil mem REG 8,1 182584
12591594 /usr/lib/x86_64-linux-gnu/libvorbis.so.0.4.5
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
login to the remote system and check all the open file related to the
active processes. At this point of time above example help you.
b.
We can use -N option to list all the NFS files.
Example:
~$
lsof -N
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
login to the remote system and check all the NFS files related to the
active processes. At this point of time above example help you.
8.
Chattr
a.
It is a linux file utility which is used to secure linux files or
directories from accidential deletion.
Example:
~#
chattr +i New.txt
root@anil-Vostro-3446:~#
rm -rf New.txt
rm:
cannot remove ‘New.txt’: Operation not permitted
Real
Time Problem:
Suppose you are working in a company and your manager ask you secure
the New.txt file. At this point of time above example help you.
b.
With the help of -R option we can secure entire directory.
Example:
~#
chattr -R +i Training/
root@anil-Vostro-3446:~#
rm -rf Training/
rm:
cannot remove ‘Training/data1.zip’: Permission denied
rm:
cannot remove ‘Training/data.zip’: Permission denied
rm:
cannot remove ‘Training/sd.txt’: Permission denied
rm:
cannot remove ‘Training/Untitled Document~’: Permission denied
rm:
cannot remove ‘Training/Untitled Document’: Permission denied
rm:
cannot remove ‘Training/dat.tar’: Permission denied
rm:
cannot remove ‘Training/text.txt’: Permission denied
Real
Time Problem:
Suppose you are working in a company and your manager ask you secure
the entire directory. At this point of time above example help you.
9.
Finger
a.
It is a user information lookup program.
Example:
~$
finger anil
Login:
anil Name: This is local user
Directory:
/home/anil Shell: /bin/bash
On
since Thu Nov 1 09:45 (IST) on :0 from :0 (messages off)
On
since Thu Nov 1 11:14 (IST) on pts/1 from :0
1 day 21 hours idle
On
since Thu Nov 1 11:16 (IST) on pts/11 from :0
1
day 20 hours idle
On
since Fri Nov 2 17:00 (IST) on pts/14 from :0
2
seconds idle
On
since Fri Nov 2 17:03 (IST) on pts/27 from :0
15 hours 12 minutes idle
No
mail.
No
Plan.
Real
Time Problem:
Suppose you are working in a company and your manager ask you to send
the user information. At this point of time above example help you.
10.
fsck
a.
It is used to check and repair the filesystem.
Example:
~#
fsck /dev/sdb
fsck
from util-linux 2.20.1
fsck.fat
3.0.26 (2014-03-07)
0x41:
Dirty bit is set. Fs was not properly unmounted and some data may be
corrupt.
1)
Remove dirty bit
2)
No action
?
1
Leaving
filesystem unchanged.
/dev/sdb:
2 files, 61/1992903 clusters
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
verify the /dev/sdb. At this point of time above example help you.
b.
We can use -y option to automatically fix all the problems.
Example:
~#
fsck -y /dev/sdb
fsck
from util-linux 2.20.1
fsck.fat
3.0.26 (2014-03-07)
0x41:
Dirty bit is set. Fs was not properly unmounted and some data may be
corrupt.
Automatically removing dirty bit.
Performing
changes.
/dev/sdb:
2 files, 61/1992903 clusters
Real
Time Problem:
Suppose you are working in a company and your manager ask you to
verify and correct all the issue of the /dev/sdb automatically. At
this point of time above example help you.

Great Blog and very useful and informative.
ReplyDeletealso, visit Linux course in Pune