all posts (default)
Weblog (or Blog)
Thursday, May 16, 2019
More CLI Tutorials
If you went through Zed Shaw's Command Line Crash Course, you saw that it only covered a limited number of commands. If you are like me in this age of "free" information, you go through several tutorials to find that one that matches your idea of the right level of detail and the right presentation. Here are several more free CLI tutorials that I found useful:
- Lifehacker's A Command Line Primer for Beginners,
- Lifehacker's Become a Command Line Ninja With These Time-Saving Shortcuts, and
- Learn Enough Command Line to Be Dangerous.
Comments on Tutorials
If you liked the "learn the hard way" (i.e., memorize progressively more difficult concepts and practice, practice, practice) approach of Zed Shaw, you might be interested in some of his other tutorials on programming. Most of these have a fee.
Also, the third tutorial listed above, Learn Enough Command Line to Be Dangerous, is very complete and detailed. Recommended.
posted at: 11:34 | path: /bash | permanent link
Wednesday, May 15, 2019
Keyboard Shortcuts for Terminal
These shortcuts apply to macOS Terminal. They may work in other bash shells, but I don't know.
^ = control key
^A - move cursor to beginning of line
^E - move cursor to end of line
^U - delete from cursor to beginning of line
^K - delete from cursor to end of line
^R - search command history. Press again to find next.
cd - - toggle between paths
!! - paste last command
!<command name> - repeat last command using <command name>
!$ - paste arguments from last command
^<text>^<replacement> - replace <text> in last command
posted at: 11:27 | path: /bash | permanent link
Tuesday, May 14, 2019
Strange Terminal Behavior
I'm using Mojave 10.14.5 on a 2017 Macbook Pro. In Terminal, when I type the command
popd, as soon as I press Return or Space, the following is added to the end of my command:
The pop command works, but I also get this output:
-bash: 2D: command not found -bash: 2D: command not found -bash: 2D: command not found -bash: 2Ddopp: command not found
This also happens with the
dirs command. Is this normal behavior for Terminal? If not, how can I fix it? If you know, please send me an email by clicking Comment in the left sidebar.
UPDATE 2019-05-21: I traced the problem to the text expander TypeIt4Me. Their support responded to my inquiry and advised me to use Preferences|Special to tell TypeIt4Me to ignore (i.e., not expand) Terminal. That solved my problem.
They continued to work on the issue and found that if the box labeled "Correct typos with AppleSpell" under Preferences|AutoCorrect is checked, AppleSpell will correct things in Terminal.
posted at: 08:34 | path: /bash | permanent link
Monday, May 13, 2019
Climbing the Tree in bash
If you are going through Zed Shaw's Command Line Crash Course, you see that much of his content relates to changing from one directory to another and knowing where you are in the directory tree. Using the command line is so different from using a GUI such as Finder to navigate the directories. With Finder, you see the directory tree displayed and all you have to do to move from one to another is click.
Bash shells on other versions of Linux/Unix have a terminal command "tree" to show you all the directories "below" your working directory. MacOS does not come with tree installed. You can, however, install it yourself. A post on SuperUser tells you how to install the tree command on macOS.
posted at: 17:51 | path: /bash | permanent link
Friday, May 10, 2019
Shaw's Command Line Crash Course correctly says you must memorize bash/Terminal commands to effectively use them. He further suggests that you make up flash cards to help you do that. If you want an on-screen alternative, Quizlet already has cards to learn macOS Terminal commands.
posted at: 10:21 | path: /bash | permanent link
Thursday, May 09, 2019
Zed Shaw's CLI Tutorial
In an earlier post, I recommended that beginners go through Zed Shaw's Crash Course to hone their basic skills in using the command line. If you use macOS and are doing Exercise 7, you may get a message that the directory you are trying to remove using
rmdir is not empty.
rmdir can only delete (remove) an empty directory. The reason the directory is not empty is that you may have used Finder to display the directory, resulting in Finder creating a hidden file holding its settings.
At the bottom of the list of commands to practice for Linux/macOS, Shaw provides a warning about and instructions if you get the "not empty" message. He recommends that you use
rm -rf <dir_name> instead of
rmdir. That works. But Shaw does not explain that the
-rf switch requires care because you are telling macOS to remove (delete) without confirmation the directory and all of its subdirectories (i.e., the
-r switch means to recurse through all subdirectories). If you mistakenly type
rm -rf /, you will delete every directory on your hard drive. So be very careful with
rm -rf <dir_name>.
posted at: 09:57 | path: /bash | permanent link
Wednesday, May 08, 2019
bash on Windows
Several years ago, Microsoft added the Windows Subsystem for Linux to Windows 10. This allowed you to add what is in essence a Linux-type terminal app and be able to execute Linux commands and run Linux programs on a Windows computer. This is neat for my current effort to learn to use the bash shell and scripting. Now Microsoft has announced even wider support for Linux/Unix type programming with the Windows Terminal. So learning bash shell scripting will be useful on either a Windows, macOS, or Linux driven computer. Expected by the end of 2019.
posted at: 10:07 | path: /bash | permanent link
Tuesday, May 07, 2019
My first home computer was a Tandy Radio Shack TRS-80. It used a cassette tape (yep, just like the ones you played music from) to store its programs. When you turned it on, you were presented with a prompt and a blinking cursor, ready for you to type something. I could not find a screenshot of that, but I did find one for the opening screen of the Apple II, which came out the same year, 1977. The TRS-80's prompt was similar because they both used the programming language BASIC as the operating system.
Even when I "graduated" to the IBM PC in 1981, turning it on brought you to an empty screen with only A:\> (designating one of the two floppy disk drives, A and B) and a blinking cursor. This is the command line interface (CLI)--no icons or menus in sight. The computer expects you to type a command to get things started. A program is running in the background to interpret your commands to the operating system and start the computer to doing what you told it to do. Thus CLI is sometimes called command language interpreter. When you are not familiar with the commands, that blinking cursor fosters all sort of anxiety.
In my blog, I talked about my experience with the Windows command line and batch files (Windows version of scripts). I'm exploring how to write scripts to do repetitive tasks on my Macbook Pro. The scripts are a series of commands in a text file that can be run from the CLI prompt by typing the name of the file. The shell for macOS is a program called bash, an abbreviation of "Bourne again shell." So before I can write a script consisting of commands, I need to know what those commands are and how to use them. The best resource I have found on the Internet is Zed Shaw's Command Line Crash Course. So if you are interested in learning along with me, go through that tutorial and then we will proceed to scripting the commands.
posted at: 11:45 | path: /bash | permanent link
Wednesday, May 01, 2019
As I've said before in this blog, I used Windows almost exclusively for 30 years before buying a Macbook Pro, which I use almost exclusively now. I got pretty good writing Windows batch (aka cmd) scripts to do things on my computer that I did repetitively. For macOS, I need to learn to write bash scripts to do these things. I'll post what I learn as I go along, so come back to join me if you are interested in watching an absolute beginner in bash try to figure this out.
posted at: 10:14 | path: /bash | permanent link