Now in this post I’m going to discuss about the linux basic command which is shown using vi/vim editor of Linux.
Linux basic command–Discussion about text editor
Generally, windows has the editor named notepad or notepad++
In Linux the editor is marked as vi or vim.
Vi is old editor, it is also the black and white version and it remains default.
On the other hand, vim is nice, user friendly and it is also the advanced editor. But one thing that, the package need to be installed.
At first we’ve changed our directory to home.=>
[root@localhost ~]# cd /home
After that we’ve created a directory named “lnx” using mkdir command, as you know, mkdir command is used for making directories.
[root@localhost home]# mkdir lnxAfter that we’ve changed our directories from “home” to “lnx”.
[root@localhost home]# cd lnxNow we want to copy some content from one folder to our current directory. Here in this example, I “passwd” folder to the current directory, and my current directory is “lnx” folder. The passwd folder is located in “/etc/passwd” . To copy content, i just have written a dot (.) at the end of the line. So the whole line indicates that copy the contents of passwd to the current directory.
[root@localhost lnx]# cp /etc/passwd .
Now lets see the folder passwd is copied or not.
[root@localhost lnx]# lspasswd
Yes !! It is copied.
[root@localhost lnx]# vim file1A writing space will open; write anything you want. For staring writing, just press “i”. To exit, from the writing, press “Shift+q” and then write exit.
Now we want to read the contents of a file. So we’ll use “cat” command.
[root@localhost lnx]# cat file1
See the output !! The contents are displayed.
Welcome to==>> whilenetworking.com
==>> myitzn.blogspot.com
Some important point you can remember:
[root@localhost lnx]# vim file1
This command helps us open our previous writing work.
Now you need to edit our work, so you can apply this:
>> dd which is for delete line by line.
>> ndd which is for delete n line(s)
>> dw — delete word.
>> d1 — delete letter.
>> Shift + d — cut lines from recent cursor position.
>> yy —copy one line.
>> nyy — copy n lines.
>> yw — copy word.
>> y1 — copy letter
>> 2y1 — copy 2 letter
>> p — paste
>> Shift + g — cursor move to last line
>> Ctrl + r — redo
>> u — undo
>> o — writing
Now lets have small discussion about touch command.
Logged in as super user
[ece@localhost Desktop]$ su –Password:
Last login: Sat May 7 04:26:55 EDT 2016 on pts/2
Changed directory to home=>
[root@localhost ~]# cd /homeCreate a new directory named “nayan”
[root@localhost home]# mkdir nayanEntered the directory=>
[root@localhost home]# cd nayan [root@localhost nayan]# ls [root@localhost nayan]# ls -ltotal 0
Create a txt file by using “touch”command=>
[root@localhost nayan]# touch c.txtSee the list and its permission system in detail=>
[root@localhost nayan]# ls -ltotal 0
-rw-r–r– 1 root root 0 May 7 11:59 c.txt
Now going back to home directory=>
[root@localhost nayan]# cd .. [root@localhost home]# cat nayancat: nayan: Is a directory
[root@localhost home]# echo hello
Hello
[root@localhost home]# echo hello>nayan
-bash: nayan: Is a directory
[root@localhost home]# cd nayan
Copy contents of ” /etc/passwd” to current directory=>
[root@localhost nayan]# cp /etc/passwd .[root@localhost nayan]# ls -l
total 4
-rw-r–r– 1 root root 0 May 7 11:59 c.txt
-rw-r–r– 1 root root 3004 May 7 12:02 passwd
[root@localhost nayan]# cat passwd ; Cat command
Now if you want to see the last 10 contents then can use the tail command=>
[root@localhost nayan]# tail passwd ;ece1:x:1004:1005::/home/ece1:/bin/bash
amin:x:1005:1006::/home/amin:/bin/bash
magun:x:1006:1007::/home/magun:/bin/bash
dep:x:1007:1009::/home/dep:/bin/bash
pri:x:1008:1010::/home/pri:/bin/bash
irin:x:1009:1011::/home/irin:/bin/bash
a1:x:1010:1013::/home/a1:/bin/bash
a2:x:1011:1014::/home/a2:/bin/bash
u1:x:1012:1016::/home/u1:/bin/bash
u2:x:1013:1017::/home/u2:/bin/bash
If you want to see the first 10 line of the contents, then can write the command =>
[root@localhost nayan]# head passwd
Last 5 line =>
[root@localhost nayan]# tail -n 5 passwdirin:x:1009:1011::/home/irin:/bin/bash
a1:x:1010:1013::/home/a1:/bin/bash
a2:x:1011:1014::/home/a2:/bin/bash
u1:x:1012:1016::/home/u1:/bin/bash
u2:x:1013:1017::/home/u2:/bin/bash
Location of hosts=>
[root@localhost nayan]# locate hosts/etc/ghostscript
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/X11/fontpath.d/default-ghostscript
/etc/avahi/hosts
.
.
.
.
.
.
Want to see the jpeg files?? just use the command=>
[root@localhost nayan]# locate -i .jpg
Find SElinux=>
[root@localhost nayan]# find /etc -type d -name selinux/etc/selinux
Find the files which is more than 10mb in size using this command =>
[root@localhost ~]# find / -size +10M/boot/initramfs-0-rescue-72f2d99ea211413bbc082429b977c36b.img
/boot/initramfs-3.10.0-229.el7.x86_64kdump.img
/boot/initramfs-3.10.0-229.el7.x86_64.img
/boot/initramfs-3.10.0-327.10.1.el7.x86_64.img
/boot/initramfs-3.10.0-327.10.1.el7.x86_64kdump.img
/dev/shm/pulse-shm-1796088854
.
.
.
.
.
Find files which is less than 10mb in size using this command =>
[root@localhost ~]# find / -size -10M ; Size less than 10M/proc/1421/task/2581/root
/proc/1421/task/2581/exe
/proc/1421/task/2581/mounts
/proc/1421/task/2581/mountinfo
/proc/1421/task/2581/clear_refs
/proc/1421/task/2581/smaps
/proc/1421/task/2581/pagemap
/proc/1421/task/2581/attr
.
.
.
.
.
Hope that you’ve enjoyed.
Leave a Reply