Command line basics every writer should know

Writers, it’s time to stop worrying and learn to love the command line. Your terminal is your friend. There’s nothing to fear here.

In this little article, I will go through some fun and easy commands that will be helpful to the power-user writer.

Getting comfortable on the command line will open up a whole new world of possibilities for you and make it easier to get more done in less time.

But remember, when you’re talking command line, a “folder” is a “directory.”

Cozy command line operation is different than clicking around a standard user interface. When using the terminal, it’s a whole different approach. Instead of clicking on what you want, you are giving written instructions to the computer. You are, in essence, telling your computer to do things for you:

  • “Change this directory to…”
  • “Tell me what’s in this directory”
  • “Search my files for this pattern…”
  • “Show me what is in this file…”

The commands that follow will work for Mac and Linux users. So go ahead and fire up your terminal and let’s get started.

Be sure to check out my Emacs For Writers handbook if you’re ready to take your writing to the next level or at least show off to your friends. And once you are comfortable on the command line, you can download my basics of shell fu PDF.

It’s easy to get lost when you’re going in and out of directories with nothing but a text prompt. So it can be helpful to get a reminder of what directory you are currently visiting. You can do that by running the pwd command:

 pwd 

This will show you something like this: /Users/yourname/Documents/my-novel.

2. ls (list files)

Listing files, as you can imagine, lists out the contents of a directory. “Hey, computer, what files are in this folder?”

 ls 

If you want to see the files listed vertically and including “hidden” files:

 ls -la 

Try both and see the difference.

3. cd (change directory)

Changing directories is essential for navigation around your file system. You can use the simple cd (change directory) command to get this done.

For example, if you have a directory called my-novel you can go there like this:

 cd my-novel 

This is presuming the my-novel directory is a subdirectory of your current location. If not, you can modify the command with the full (“absolute”) path to the directory:

 cd /home/joe/Documents/my-novel 

Sometimes you will need to go back a level. For that you can add some dots:

 cd .. 

4. mkdir (make directory)

Sometimes it is not enough to merely change directories, but to create whole new directories as well. You can do that with the mkdir command followed by the name of a directory you want to create:

 mkdir my-great-novel 

You can even create nested directories:

 mkdir my-great-novel/chapter1 

5. cat (concatenate/view file)

You can always open up a file in an actual text editor or other appropriate program. But if you want to see what’s in a file, or “concatenate” the contents and pipe them into another command, the cat command has got you covered.

 cat chapter1.txt 

For an example of piping, you can take the output of cat and send it to a program called wc that counts words with the -w flag, as in this example:

 cat chapter1.txt | wc -w 

Bonus commands for writers

wc -w filename.txt
count words in a file
touch newfile.txt
create empty file
mv oldname.txt newname.txt
rename a file
cp chapter1.txt chapter1-backup.txt
copy a file

Helpful grep searches to try out

The grep search command can be very handy when looking for certain patterns across your files. Here are you some helpful writerly patterns you can try out.

grep “Chris” *.txt
find every mention of character Chris
grep -i “chris” *.txt
case-insensitive: finds Chris, chris, CHRIS
grep -n “TODO” *.txt
show line numbers where TODO appears
grep -c “said” chapter*.txt
count how many times “said” appears in each chapter
grep -r “plot hole” .
recursively search all files in current directory
grep “Chapter [0-9]” *.txt
find “Chapter 1”, “Chapter 2”, etc.
grep -v “draft” *.txt
show lines that DON’T contain “draft”
grep -A 3 “cliffhanger” novel.txt
show line with “cliffhanger” plus 3 lines after
grep -B 2 “foreshadowing” novel.txt
show 2 lines before “foreshadowing”
grep -E “was|were” chapter1.txt
find passive voice helpers
grep “very\|really\|just” *.txt
find weak qualifiers to eliminate

That’s it for now. I would suggest doing some practice runs with these commands until they become second nature. You’ve taken your first step into a larger world. Knowing these commands will help you get accustomed to Linux if you are just switching over from the Mac world. Or, if you are in Mac world, you can get some good mileage out of these there as well. If you have any comments or questions be sure to leave them below and I will do my best to answer.

Be the first to comment

Leave a Reply

Your email address will not be published.


*