Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (2024)

pjungwir on March 30, 2015 | parent | context | favorite | on: Stop using tail -f (mostly)


Another less-vs-vi question:

As a junior programmer I got chewed out by my IT department because I was examining a (production) log file in vi. The sysadmin told me I should use less (actually more---this was on Solaris in ~2001). To this day I only read log files with less, but I've never figured out his objection. Negatives to using vi I can imagine are:

- I might write to the log file. That seems like a real worry, although I could also say `vi -R` to prevent it.

- Starving the production system of memory. I'm pretty sure he expressed this concern. Any insight into whether it is legit? Is less actually any better?

Obviously you really should have a log shipping & aggregation service so you can read logs offline, etc, but not every project is large enough for that, nor every org organized enough. So for the sake of argument my premise is, "Assuming you want to read a log on production . . ."

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (1)

annnnd on March 31, 2015 | next [–]


From sysop standpoint there is a huge difference:

1) for user: less chance (pun intended) to actually change the file when all you wanted was to read it

2) for sysadmin: if sysadmin sees "less somefile.log" in bash history, he knows the user just read the log. If he sees "vi somefile.log" then he doesn't know if the user has also changed the log file (maybe not even knowing it).

The assumption is that you deal with non-malicious users who just make mistakes (which is often the case).

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (2)

notfoss on March 31, 2015 | parent | next [–]


 for sysadmin: if sysadmin sees "less somefile.log" in bash history, he knows the user just read the log. If he sees "vi somefile.log" then he doesn't know if the user has also changed the log file (maybe not even knowing it).

In case you didn't know, you can invoke an editor from within less by pressing 'v'. And that wouldn't get registered in the shell history ;)

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (3)

pjungwir on March 31, 2015 | root | parent | next [–]


Ha ha, this reminds me of the days I had sudo access to `vi` but not a lot of other commands, on a box that IT didn't really want to support. . . .

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (4)

annnnd on April 7, 2015 | root | parent | prev | next [–]


> The assumption is that you deal with non-malicious users...

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (5)

notfoss on April 7, 2015 | root | parent | next [–]


It was there previously? Sorry I missed it. In any case, I wouldn't call the action I mentioned malicious. There is no hack involved, no improvisation either. Simply using a built-in feature of `less`.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (6)

pjungwir on March 31, 2015 | parent | prev | next [–]


Thanks for your reply! Since I do a lot of devops I've tried over the years to formulate a mental model of how a sysadmin thinks and what they care about. I'd never have thought about this auditability concern, so it's something to add to my list! :-)

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (7)

vbezhenar on March 30, 2015 | prev | next [–]


On large files less fires up immediately and vim is quite slow. I think that vim is loading an entire file in the memory while less just loads visible chunk. May be other vi implementations are more efficient with large files.

Besides — vim really shouldn't be used on log files. It's editor, not viewer.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (8)

pjungwir on March 30, 2015 | parent | next [–]


> Besides — vim really shouldn't be used on log files. It's editor, not viewer.

I think the two concerns I stated are probably legit, but this one is boring to me. Vim is nicer than less for reading files. I have more navigation commands. I can yank part of the file and save it somewhere else. I can pipe a range of lines through awk/etc. I can switch between files. I can split my screen. Etc. Some of these are probably available in less too (more than more(1) supported in 2001), but I doubt all, and I already know the commands in vim. I'm interested in not clobbering my logs and not crashing the server, but if you tell me vim is an editor not a viewer, I'll ask Why?

Btw re-reading my words I don't mean to sound combative. But the point of my original question was to understand. I've been cargo-culting "use less for logs" for 14 years already.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (9)

kragen on March 30, 2015 | root | parent | next [–]


You can save a part of the file, pipe a range of lines, or switch between files in less, too, and the commands are mostly the same as in vi. It'd sure be nice to be able to split the screen, though!

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (10)

EdiX on March 30, 2015 | parent | prev | next [–]


> I think that vim is loading an entire file in the memory while less just loads visible chunk

No, vim also only keeps part of the file loaded, however it will try to count how many lines the file has.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (11)

robmil on March 30, 2015 | parent | prev | next [–]


Vim ships with a command called `view` that will start it in read-only mode, and makes it very much a viewer —not just an editor.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (12)

dredmorbius on March 31, 2015 | root | parent | next [–]


True, and I like using this for syntax-colored views of files. But it's got an annoying tendency to switch to edit mode with very little fuss.

Sometimes I want a viewer to just be a viewer.

Speaking of which: are there any Linux/Unix viewers that do have generalized syntax highlighting support?

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (13)

notfoss on March 31, 2015 | root | parent | next [–]


You can give vimpager a try. It even supports vimrc. But I have felt it to be considerably slower than less.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (14)

sukilot on March 31, 2015 | root | parent | prev | next [–]


chmod :)

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (15)

dredmorbius on April 2, 2015 | root | parent | next [–]


It took me way too long to grok that.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (16)

oimaz on March 30, 2015 | parent | prev | next [–]


With vim, I usually use 'vim -u NONE <file-name>' which skips the startup file and makes loading zippy

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (17)

ryen on March 30, 2015 | parent | prev | next [–]


It may also try to do syntax highlighting and other formatting stuff, taking up even more resources and cpu time.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (18)

sliverstorm on March 30, 2015 | parent | prev | next [–]


And an editor should not be used on log files?

Frequently, frequently I am in the position that I need to manipulate an overly-verbose log file to condense out the information I want. I could spend a half hour concocting wizard-like shell invocations, OR I could do it interactively in five minutes with vi...

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (19)

blueblob on March 30, 2015 | prev | next [–]


I think your idea of `vi -R` or `vim -R` is a good idea. `less` uses less memory and may load faster but looking at logs for things like valgrind vim will give you syntax highlighting that I am not sure you can get with `less`.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (20)

dcohenp on March 30, 2015 | parent | next [–]


BTW, starting vim as "view" (through e.g. a symlink) is equivalent to "vim -R", precisely for this use case [0].

[0] http://vimdoc.sourceforge.net/htmldoc/starting.html#view

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (21)

blueblob on March 31, 2015 | root | parent | next [–]


I have used `view` but it didn't give me syntax highlighting. On my system (archlinux) view is actually a symlink to ex (which must change its behavior based on its name?).

 readlink /usr/bin/view ex
Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (22)

hrktb on March 30, 2015 | prev | next [–]


I think Edix's answer is the most pragmatic.Also, someone at work actually crashed a service by opening the log files in vim.

I think the problem was that the memory and processor were already getting stomped on (thus the need to look at the logs) and vim tried to do a lot of fancy stuffs to get more info on the file as a whole.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (23)

dexxtreme on March 30, 2015 | prev | next [–]


If I'm logging into a server later to resolve an issue, one thing I will probably check is the command history. If you open a file with "vi", how do I know that you only looked at it, and did not make any changes to it? When I see "less" in the command history, I know for certain that it was a read-only operation.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (24)

sukilot on March 31, 2015 | parent | next [–]


Why do you let revs login to production machines. That's your first problem.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (25)

cstoner on March 30, 2015 | prev | next [–]


It's a good practice for sure, but your sysadmin was probably a little over-hash.

I'm generally in the habit of using `view` to do read-only vim. `less` works as well.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (26)

dTal on March 31, 2015 | prev | next [–]


Funny - I always used to use less, until this popped up on HN:

http://seclists.org/fulldisclosure/2014/Nov/74

Now I mostly use vi.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (27)

_ondq on March 30, 2015 | prev | next [–]


I would never "yell" at anybody for using vi vs less, but I might curiously ask their reasoning behind it. I'm generally for less bikeshedding and cargo cultism when possible. Whatever works to get the job done.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (28)

nodata on March 30, 2015 | prev | next [–]


Yes, but cpu is normally the problem. vim is very inefficient with long lines, combine that with all of vim's features (syntax highlighting, etc.) and you have the potential to make a problem worse.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (29)

freehunter on March 30, 2015 | prev | next [–]


I don't know his exact reasoning, but the biggest thing I can think of you already touched upon: there's more of a danger that you can write to a file accidentally with vi vs with less.

Beyond that, I would probably correct a junior employee as well. Even if there's nothing wrong with it, it's not the right tool for the job. When I first started I got 'yelled' at for checking to see if a machine was on the network using tracert instead of ping. It works, but it's not the right tool for the job.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (30)

sukilot on March 31, 2015 | prev [–]


The sysadmin was low knowledge.

You should download the log file and view it locally. You should never run ad hoc commands on a live production sytem.

And there is no reason that you should have edit privileges on the log file anyway.

Another less-vs-vi question: As a junior programmer I got chewed out by my IT de... (2024)

FAQs

What is the difference between VI and less? ›

Less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi(1). Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals. There is even limited support for hardcopy terminals.

What is the difference between Vi and Vim? ›

Vim, short for “Vi IMproved,” is an enhanced, improved, and extended version of the Vi text editor. Developed by Bram Moolenaar in the early 1990s, Vim builds upon the foundation of Vi while adding numerous features and improvements. It is a more feature-rich and upgraded version of the Vi editor.

Which of the following commands would help you to delete a single character in the vi editor? ›

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.

How to find a string and replace in vi? ›

Search mode is activated by pressing ` /` , and replace mode is activated by using the substitute command ` :%s/old_pattern/new_string/g` .

What are the three types of VI? ›

While using vi, at any one time you are in one of three modes of operation. These modes are known as "command mode," "insert mode," and "last line mode."

What is the difference between VI and Sub VI? ›

After you build a VI, you can call it from the diagram of another VI within the same project. A VI called from the diagram of another VI is a subVI. SubVIs contain reusable code and simplify the diagrams of calling VIs. SubVIs are analogous to functions or subroutines in other programming languages.

How do you escape a character in vi search? ›

To escape a special character, precede it with a backslash ( \ ).

How do I quit vi without saving? ›

If you've made mistakes along the way while editing and want to back out (abandon) all non-saved changes, enter Command mode by pressing Esc and typing :q! This command quits without saving any changes and exits Vi.

How do I undo changes in the vi editor? ›

If you make a mistake in vi or if you just change your mind after an operation is completed, you can undo your last command by pressing u immediately after the command. You do not need to press Esc after you type u . By pressing u a second time you undo the undo.

How to replace globally in Vi editor? ›

Global replacement really uses two ex commands: :g (global) and :s (substitute). Since the syntax of global replacement commands can get fairly complex, let's look at it in stages. This changes the first occurrence of the pattern old to new on the current line.

How to remove m in Vi? ›

The "vi" editor can be used on Unix platform to globally remove CTRL-M (Control-M) characters:
  1. Use the vi editor to open the file that contains the Control-M characters.
  2. Enter the following. :1,$s/<ctl-v><enter>//g (where ctrl-v is the Ctrl Key and the letter v on the keyboard) ...
  3. Then enter :wq! to save the file.

How to search in Vi editor with example? ›

To find a character string, type / followed by the string you want to search for, and then press Return . vi positions the cursor at the next occurrence of the string. For example, to find the string "meta", type /meta followed by Return .

What is the degree of less? ›

comparative degree of less is less itself. superlative degree of less is least.

What is the difference between less and least? ›

Less is the comparative form of little and refers to “a smaller amount of.” Least is the superlative form of little and refers to “the smallest amount of.”

What is the difference between VI and IV in Roman numerals? ›

For example, the numeral VI, or 6, would be read as "five plus one" (5 + 1), and XI, or 11, is "ten plus one" (10 + 1). But the methods for representing 4 and 9 are special. The Roman numeral IV, or 4, would be read as "one less than 5" (5 - 1). Also, the numeral IX, or 9, would be read as "one less than 10" (10 - 1).

What is difference between less and more? ›

The difference between more and less is one of quantity. More and less can both be used as adjectives or adverbs. As a descriptive word, more signifies "indeed," while less signifies "less significantly." As a verb modifier, more signifies "to a more significant level", while less signifies "to a lower degree."

Top Articles
What to Know About Credit Card Daily & Monthly Periodic Rates
How Does Annual Vs Monthly Vs Daily Interest Affect My Loan? | Stag Protect
Goodbye Horses: The Many Lives of Q Lazzarus
How Many Cc's Is A 96 Cubic Inch Engine
Erskine Plus Portal
Bloxburg Image Ids
Paula Deen Italian Cream Cake
Katie Boyle Dancer Biography
Locate Td Bank Near Me
Pollen Count Central Islip
The Blind Showtimes Near Showcase Cinemas Springdale
Readyset Ochsner.org
Mills and Main Street Tour
Christina Khalil Forum
Inside the life of 17-year-old Charli D'Amelio, the most popular TikTok star in the world who now has her own TV show and clothing line
Elemental Showtimes Near Cinemark Flint West 14
Divina Rapsing
Hyvee Workday
All Breed Database
Exl8000 Generator Battery
PCM.daily - Discussion Forum: Classique du Grand Duché
Www.paystubportal.com/7-11 Login
Scheuren maar: Ford Sierra Cosworth naar de veiling
The best brunch spots in Berlin
Обзор Joxi: Что это такое? Отзывы, аналоги, сайт и инструкции | APS
Account Now Login In
Helpers Needed At Once Bug Fables
Bi State Schedule
Devotion Showtimes Near The Grand 16 - Pier Park
Home Auctions - Real Estate Auctions
Fridley Tsa Precheck
What Is Xfinity and How Is It Different from Comcast?
Lucky Larry's Latina's
Craigslist Com Humboldt
Heavenly Delusion Gif
Manatee County Recorder Of Deeds
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
1v1.LOL Game [Unblocked] | Play Online
Craigslist Ludington Michigan
Tricia Vacanti Obituary
Expendables 4 Showtimes Near Malco Tupelo Commons Cinema Grill
All Weapon Perks and Status Effects - Conan Exiles | Game...
White County
Turok: Dinosaur Hunter
Espn Top 300 Non Ppr
2000 Ford F-150 for sale - Scottsdale, AZ - craigslist
Laura Houston Wbap
Lira Galore Age, Wikipedia, Height, Husband, Boyfriend, Family, Biography, Net Worth
Glowforge Forum
Varsity Competition Results 2022
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 6170

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.