APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Vim: edit with vim

Long ago I wrote an article claiming that I write my e-mails in Vim and that led to a very interesting and sometimes annoying flame war in that site. There seems to be a lot of passion that goes behind arguments for deciding which editor is better: vi or emacs.

Title Last Comment
Running a command at a particular time  
- I have a cron job that runs every hour. Within that script I need to test for specific times. -

How can I find out when our anniversary falls on a Saturday?  
- How can I find out when our anniversary falls on a Saturday? I thought it would be easy, but it doesn't seem to be? -

I need to send a kill -1 to a process  
- I need to send a kill -1 to a process but I can not get the pid from a file as it's location is different on some systems -

Shell script cannot test for the existence of files  
- My shell script needs to move certain files to another location. How do I test that the files exist? -

Why does this variable become blank?  
- Why does this variable become blank? It's obviously set in the first part, but it goes away. -

Take Control of the Mac Command Line with Terminal  
- Old-timers like me couldn't avoid being exposed to command line interfaces - that's all we had when we started Younger people and people who simply started using computers a bit later weren't necessarily exposed to any command line. Any computer they ever used had a graphical user interface and while it still may have had a command line available, there was seldom any incentive to use it. That apparent lack of any compelling reason remains true, but in fact understanding the command line can give you much more control over your computer and allow you to accomplish some tasks much more quickly and easily. -

Restrict script to console use  
- How to restrict a shell script to prevent use by ssh or to only be used at the console. -

Removing empty directories  
- Follow along as we segue and digress, dive deep and reverse ourselves all while trying to avoid the pedantic spoilers who would surely ruin our fun emptying our directories. -

Perl directory listing  
- Learning Perl basics to produce 'pretty' directory listing with 'File::Find'.: A "pretty" or custom directory listing is a good place to start developing your scripting skills if you want to. -

Printing multiple files  
- I have 25 .txt files that I would like to print. They are named 1.txt, 2.txt and so on. How can I do this? -

Shebang - What's the point of #!/bin/bash?  
- Shebang, hashbang, pling - whatever you call it, what's the point? What does it do? Do you need it in shell scripts or not? -

Wall and write   2013/07/30 TonyLawrence
- The Unix/Linux "wall" command does that. Login as root, type "wall" <ENTER>, then whatever you want to say (multiple lines are OK), follwed by <ENTER> and then CTRL-D -

Determine Unix/Linux version and cpu's  
- Usually some variant of uname, often 'uname -a', but all sorts of other possibilies; it depends on the Unix and in some cases even the specific version. -

Passing shell environment variables  
- Is there anyway for a child process to set an environment variable visible to its parent? -

Deleting a lost file name - delete unremoveable files  
- It HAS a file name- it probably has control characters in it that are confusing the display. Try ls -b. If that doesn't work, do "ls -l > /tmp/t" and the "vi /tmp/t" -

View large files without more or less  
- I have a rescue disk that doesn't include "more" or "less" - how can I examine large files? -

Losing white space IFS   2013/07/22 TonyLawrence
- The shell doesn't really destroy anything; it's just doing what it should - ignoring repeated white space. -

Here files (shell scripting)   2012/10/09 TonyLawrence
- Once again, I've been bitten by not having read the manual recently. This bite really annoyed me. -

No clobber scp - scp without overwriting   2012/10/07 TonyLawrence
- Although you usually want scp to update files, there are times when you definitely do not. I wrote this script to avoid overwriting existing files. -

LOD Communications, Inc.
Capture and report (Bash Scripting)  
- You've been asked to copy some jpg files to a USB disk overnight. That's easy enough - a cron job and a simple 'cp -a' will do that. But there is so much that could go wrong, isn't there? There might not be any files to copy or there might not be room on the USB disk. Somebody might have changed permissions on files or directories alreasdy in place, preventing overwrite with updated images. -

Auto Edge archive removal script  
- The way I wanted Edge to work, was just like the days when we backed up to Tape. We would pull Master backups each night, label the tapes M-F, and take a SAT tape off-site for an extra layer of protection. When Monday rolled around, the new backup would replace the old Monday backup, rinse, lather, repeat. This changed when we upgraded to Edge 3.x, and started using the NAS. Once we had multiple servers with multiple jobs backing up to the same resource, and not having enough free space on the NAS because backups were piling up, I had to resort to manually deleting things (through edgemenu) on the NAS to free up space. This got old rather quickly, as I had to look down the long list of backup jobs, and determine which ones could be deleted. If I missed one day, the NAS would fill up, and backups would fail. -

Death of the command line revisited   2011/09/10 TonyLawrence
- Five years ago I wrote a little blurb called Death of the command line. As it happened, that article was misunderstood by many who read it - I don't know if it was my fault or theirs, but somehow many readers ended up thinking I was either predicting the demise of CLI's (Command Line Interfaces) or hoping for that demise or both. Nothing could have been farther from the truth. I remain a big fan of CLI's and use them daily. And yet, just five years later and still at risk of angering yet another batch of folk who won't read carefully, I'm going to suggest that predicting the death of the CLI may not be such a bad bet after all. -

Higher resolution timers in the shell  
- In the olden days, we'd pick up the current time from 'date' and store that. Then, after suspect part of the script, we'd run it again and calculate the elapsed time. Simple enough, but 'date' limited us to whole seconds. We had nothing in the shell that was tighter. -

Linux colors ls ––color command  
- Change default dircolors. Personally, I don't like colors in my shell. I think it would be fine as an option, but to have it as the default offends me and many other old Unix hands. -

Is sed dead?  
- If you learn how to use sed, you get a bonus: the same editing commands can be used in ed and vi. -

The lowly ls command   2011/04/20 TonyLawrence
- ls might have more flags than any other Unix command and operating system variance is wide. The lowly ls command has a lot of flags, perhaps more than any other Unix command. -

Finding Yesterday's Date   2014/02/05 TonyLawrence
- How to find yesterday's date on Linux, Mac and any other Unix. -

Yesterday's Date   2010/04/01 TonyLawrence
- Recently I was asked how to write a script that would automate the task of copying a log file to another directory -

Murder and mayhem - killing users processes   2011/10/28 BigDumbDinosaur
- how to kill all of a specific user's user processes without "killall" - or select a subset to kill -

Slightly Scrambled - unsorting a file   2011/04/05 TonyLawrence
- Here is a typical way to approach the problem. It uses Perl's associative arrays and (somewhat ironically) uses -

Environment variables - maximum size of a variable?  
- An 18 MB or larger variable is much more than any shell script is likely to need, but it shows that you need not fear assigning large chunks of data -

What does a leading colon (:) mean in a script?  
- Bash and sh use colons as a separator ($PATH, for example), as a modifier (${n:="foo"}) and as a null operator ("while :"). -

Using color in shell scripts (Linux, Mac OS X)   2010/01/03 BigDumbDInosaur
- Color is tricky. Displays can be bad at it, people can be color blind... using colors can make text hard to read - I don't like using color in scripts. -

Sort -u vs. uniq  
- Don't tie yourself in pipeline knots with either of them; learn to use each of them appropriately and your scripts will be easier. -

Awk vs. Perl   2012/08/15 TonyLawrence
- Sure, I used to use awk. When I used it, you weren't likely to find Perl onmost Unix systems, so for a lot of text mangling, awk was at least easier than writing in C or anything else. It did the job, and you'd get used to its quirks. -

Freeing disk space with >  
- I wrote this up after a forum discussion in which several posters didn't really understand why '>' can free disk space when 'rm' cannot. -

Prevent deletion or moving of files  
- You need to let users create files in a common directory, but you don't want them to be able to delete other's files. Or you've put certain files, directories or symlinks into a user's home directory and don't want them to be able to mess with any of those. What can you do? -

Create syntax highlighted PDF and HTML files from C or perl  
- Create syntax highlighted PDF and HTML files from C or perl -

Plenty of space here  
- Like many people, my customer doesn't understand spaces in command lines. Unlike most, he's not one to leave spaces out - no, he's more likely to insert gratuitous spaces where none are wanted. -

Vim: edit with vim  
- For people who hate vi, vim does not offer much relief. -

Network Time Protocol - get atomic clock's precision from the Internet  
- It is ridiculous that a computer that we buy for several hundred dollars cannot be as accurate as a watch that be bought for less than 10$. That does not have to be the case once you read and understand this article. -

Print file listings from the command line  
- The OS X Finder suffers from a rather amazing limitation: you can'tprint the list of files you see in a Finder window. -

How do I capture program screens to a file or print them?   2012/09/17 TonyLawrence
- Various ways to capture text or screens on Unix/Linux and Mac OS X and Windows. -

Removing duplicate files   2013/06/28 Tony
- This Perl script considers a file to be a duplicate if it has the same name and the same number of bytes. THAT COULD BE A VERY BAD ASSUMPTION. -

Shell script used time  
- What that does is show you the last time a file was used which can be very helpful in tracing whether or not something happened when you expected it to -

Breaking out of a script  
- Sometimes you just want to bail out of a script when something happens. Let's say we're testing the output of some "chk" command and want to exit if it says "No". That's easy: we just add "chk | grep -q "No" && exit 0" to our script. If that "chk" spits out "No", our script is done right then and there - no more of it will be executed. -

Find with -execdir   2011/10/25 TonyLawrence
- This article discusses the "execdir" option to "find" and the use of "\;" or "+" to terminate the arguments supplied -

The Linux of our Understanding  
- How much do we really grok? I decided to read the complete Bash man page and see where I was left slack jawed. -

Bash Brace Expansion  
- Simple Bash Brace Expansion. The new tricks Bash has picked up in 3.0 are exciting and useful, but simple brace expansion has been available for some time now, and yet we seldom see it used. I suppose that's because the need doesn't come up too often. -

Empty the Trash   2010/06/05 TonyLawrence
- Should I empty the trash? I put the stuff there. Why would I put it there if I still wanted it? Just empty the damn thing. -

Analyzing web logs with grep  
- If you have a website, your logs are a great source of information. You can actually get a lot of quick and useful stats from the command line with just "grep". -

Writing a Twitter getter Widget  
- I did not like the Twitter Widget, so I wrote my own. I didn't like that either, but maybe you will. -

Power failure changes my habits  
- I need to be more careful in editing scripts - a power failure catches me at exactly the wrong time! -

Dual printing   2011/05/23 TonyLawrence
- Multiplexed printing is missing from all Unix/Linux printing systems that I know of. Here's how to add it. -

Using sh -c with find  
- Using sh -c imbedded in find script. I'm sure everyone reading here has used "-exec" with "find"; for example: -

Background tasks - Why?  
- Running shell scripts in background: I started to write what I thought would be a more complete response, but quickly realized that there is an awful lot to cover, and some of it is pretty complicated. The new Unix user actually has a lot to learn about this. -

Finding large files   2010/10/02 wilson
- Where has the space gone? Although it is getting harder and harder to run out of disk space, some of us still manage to do it. -

Wrapper scripts  
- When a command doesn't quite do what you want. wrpaaing it in a tiny shell script is often the most simple answer. -

Numbering Lines  
- Now and then you want to number the lines of a file. You can roll your own script to do that: -

More Shell articles