KEMBAR78
Editing Files | PDF | System Software | Software
0% found this document useful (0 votes)
19 views7 pages

Editing Files

The document provides an overview of editing files in Linux using text editors, focusing on Nano and Vim. It explains how to create and edit files with Nano, including commands for saving and searching text, and introduces Vim as a more powerful, modal editor with various modes for different tasks. Additionally, it highlights the importance of understanding file permissions for security assessments in penetration testing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

Editing Files

The document provides an overview of editing files in Linux using text editors, focusing on Nano and Vim. It explains how to create and edit files with Nano, including commands for saving and searching text, and introduces Vim as a more powerful, modal editor with various modes for different tasks. Additionally, it highlights the importance of understanding file permissions for security assessments in penetration testing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Editing Files

After learning how to create files and directories, let’s move on to working
with these files. There are several ways to edit a file in Linux, with some of
the most common text editors being Vi and Vim. However, we will start with
the Nano editor, which is less commonly used but easier to understand.

To create and edit a file using Nano, you can specify the file name directly
as the first parameter when launching the editor. For example, to create
and open a new file named notes.txt, you would use the following
command:

benscs@htb[/htb]$ nano notes.txt


This command will open the Nano editor, allowing you to start editing the
file notes.txt immediately. Nano’s straightforward interface (also called
"pager") makes it a great choice for quickly editing text files, especially when
you’re just getting started.

Nano Editor

GNU nano 2.9.3


notes.txt

Here we can type everything we want and make our


notes.▓

^G Get Help ^O Write Out ^W Where Is ^K Cut


Text ^J Justify ^C Cur Pos M-U Undo
^X Exit ^R Read File ^\ Replace ^U Uncut
Text ^T To Spell ^_ Go To Line M-E Redo
Below we see two lines with short descriptions. The caret (^) stands for our
"[CTRL]" key. For example, if we press [CTRL + W], a "Search:" line appears at
the bottom of the editor, where we can enter the word or words we are
looking for. If we now search for the word "we" and press [ENTER], the cursor
will move to the first word that matches.

GNU nano 2.9.3


notes.txt

Here ▓we can type everything we want and make our


notes.

Search: notes
^G Get Help M-C Case Sens M-B Backwards M-J
FullJstify ^W Beg of Par ^Y First Line ^P PrevHstory
^C Cancel M-R Regexp ^R Replace ^T Go To
Line ^O End of Par ^V Last Line ^N NextHstory
To jump to the next match with the cursor, we press [CTRL + W] again and
confirm with [ENTER] without any additional information.

GNU nano 2.9.3


notes.txt

Here we can type everything ▓we want and make our


notes.

Search [we]:
^G Get Help M-C Case Sens M-B Backwards M-J
FullJstify ^W Beg of Par ^Y First Line ^P PrevHstory
^C Cancel M-R Regexp ^R Replace ^T Go To
Line ^O End of Par ^V Last Line ^N NextHstory
Now we can save the file by pressing [CTRL + O] and confirm the file name
with [ENTER].

GNU nano 2.9.3


notes.txt

Here we can type everything we want and make our notes.

File Name to Write: notes.txt▓


^G Get Help M-C Case Sens M-B Backwards M-J
FullJstify ^W Beg of Par ^Y First Line ^P PrevHstory
^C Cancel M-R Regexp ^R Replace ^T Go To
Line ^O End of Par ^V Last Line ^N NextHstory
After we have saved the file, we can leave the editor with [CTRL + X].

Back on the Shell

To view the contents of the file, we can use the command cat.

benscs@htb[/htb]$ cat notes.txt

Here we can type everything we want and make our notes.


On Linux systems, there are several files that can be tremendously
beneficial for penetration testers, due to misconfigured permissions or
insufficient security settings by the administrators. One such important file
is the /etc/passwd file. This file contains essential information about the
users on the system, such as their usernames, user IDs (UIDs), group IDs
(GIDs), and home directories.

Historically, the /etc/passwd file also stored password hashes, but now
those hashes are typically stored in /etc/shadow, which has stricter
permissions. However, if the permissions on /etc/passwd or other critical
files are not set correctly, it may expose sensitive information or lead to
privilege escalation opportunities.

As penetration testers, identifying files with improper rights or permissions


can provide key insights into potential vulnerabilities that might be
exploited, such as weak user accounts or misconfigured file access that
should otherwise be restricted. Understanding these files is vital when
assessing the security posture of a system.
VIM

Vim is an open-source editor for all kinds of ASCII text, just like Nano. It is
an improved clone of the previous Vi. It is an extremely powerful editor that
focuses on the essentials, namely editing text. For tasks that go beyond
that, Vim provides an interface to external programs, such as grep, awk, sed,
etc., which can handle their specific tasks much better than a
corresponding function directly implemented in an editor usually can. This
makes the editor small and compact, fast, powerful, flexible, and less error-
prone.

Vim follows the Unix principle here: many small specialized programs that
are well tested and proven, when combined and communicating with each
other, resulting in a flexible and powerful system.

Vim

benscs@htb[/htb]$ vim

1 $
~
~ VIM - Vi IMproved
~
~ version 8.0.1453
~ by Bram Moolenaar et al.
~ Modified by pkg-vim-
maintainers@lists.alioth.debian.org
~ Vim is open source and freely
distributable
~
~ Sponsor Vim development!
~ type :help sponsor<Enter> for
information
~
~ type :q<Enter> to exit
~ type :help<Enter> or <F1> for on-
line help
~ type :help version8<Enter> for
version info
~

0,0-1 All
In contrast to Nano, Vim is a modal editor that can distinguish between text
and command input. Vim offers a total of six fundamental modes that make
our work easier and make this editor so powerful:

Mode Description
Normal In normal mode, all inputs are considered as editor commands. So there is no insertion of the entered characters into the
case with most other editors. After starting the editor, we are usually in the normal mode.
Insert With a few exceptions, all entered characters are inserted into the buffer.
Visual The visual mode is used to mark a contiguous part of the text, which will be visually highlighted. By positioning the cur
selected area. The highlighted area can then be edited in various ways, such as deleting, copying, or replacing it.
Command It allows us to enter single-line commands at the bottom of the editor. This can be used for sorting, replacing text section
example.
Replace In replace mode, the newly entered text will overwrite existing text characters unless there are no more old characters at
position. Then the newly entered text will be added.
Ex Emulates the behavior of the text editor Ex, one of the predecessors of Vim. Provides a mode where we can execute mu
sequentially without returning to Normal mode after each command.

When we have the Vim editor open, we can go into command mode by
typing ":" and then typing "q" to close Vim.

1 $
~
~ VIM - Vi IMproved
~
~ version 8.0.1453
~ by Bram Moolenaar et al.
~ Modified by pkg-vim-
maintainers@lists.alioth.debian.org
~ Vim is open source and freely
distributable
~
~ Sponsor Vim development!
~ type :help sponsor<Enter> for
information
~
~ type :q<Enter> to exit
~ type :help<Enter> or <F1> for on-
line help
~ type :help version8<Enter> for
version info
~
:q▓
Vim offers an excellent opportunity called vimtutor to practice and get
familiar with the editor. It may seem very difficult and complicated at first,
but it will only feel that way for a short time. The efficiency we gain from
Vim once we get used to it is enormous. Entering the tutor mode
in vim editor can be done using the Command mode :Tutor or by using
the vimtutor command in the shell.

VimTutor

benscs@htb[/htb]$ vimtutor

=======================================================
========================
= W e l c o m e t o t h e V I M T u t o r
- Version 1.7 =
=======================================================
========================

Vim is a very powerful editor that has many


commands, too many to
explain in a tutor such as this. This tutor is
designed to describe
enough of the commands that you will be able to
easily use Vim as
an all-purpose editor.

The approximate time required to complete the


tutor is 25-30 minutes,
depending upon how much time is spent with
experimentation.

ATTENTION:
The commands in the lessons will modify the text.
Make a copy of this
file to practice on (if you started "vimtutor"
this is already a copy).

It is important to remember that this tutor is set


up to teach by
use. That means that you need to execute the
commands to learn them
properly. If you only read the text, you will
forget the commands!

Now, make sure that your Caps-Lock key is NOT


depressed and press
the j key enough times to move the cursor so
that lesson 1.1
completely fills the screen.

You might also like