Tech by Blaze Media

© 2024 Blaze Media LLC. All rights reserved.
How to escape the surveillance state: Using unix to run a server
treety/Getty Images

How to escape the surveillance state: Using unix to run a server

We recently discussed the Unix operating system and its various offshoots, like Linux, and why it’s an invaluable skill to learn to assert your digital independence. If you know UNIX, you can use alternative operating systems like Linux, run your own servers, and do other powerful things that make you less dependent on software companies spoon-feeding user-friendly interfaces. We even offered some ways to try Unix or Linux on your computer without major modifications.

But once you get to a command prompt, it can be daunting. There you are with a window or screen of mysterious characters and an ominous blinking cursor. What now?

It helps to know how to get around. Here are two fundamental commands for navigation:

  • Type pwd and press enter or return to see the directory you’re currently in
  • Try ls to list the contents of the directory

Think of pwd and ls as a compass and map for a Unix file system. They tell you where you are and what you’re looking at.

Arguments and options

Almost every Unix command accepts arguments. No, not the kind you have with your relatives on Thanksgiving. An argument in the context of Unix means something additional you pass on to a command — often the file or directory you want the command to operate on.

Going back to the above example, if the ls command lists a familiar subdirectory — like Documents — you can enter that directory by typing cd followed by the directory name, like so: cd Documents. In this example, Documents is the argument passed to the cd command.

Here’s a tip: most Unix-type command lines let you press tab to autocomplete a file or directory name, so you can type cd Doc and then press tab to reduce errors and not have to type so much.

Get lost? Use cd ~ to return to your home directory, which is the directory you start in by default when you open a command-line window. You can also use cd .. to move up a directory. Here’s an example:

  1. Let’s say you start in /Users/yourname/ (again, verify your home directory with the pwd command)
  2. You move into your Documents folder with cd Documents/ (pwd would show /Users/yourname/Documents)
  3. You enter cd .. and you’re back in /Users/yourname/

Let’s talk about options, which are additional parameters passed to a command, usually denoted by a hyphen.

Let’s revisit the ls command. When you try it, it will probably show your files and folders in a set of columns. But if you instead type ls -l, it presents those files and folders as a vertical list. The -l is an example of an option.

By default, ls presents everything in alphabetical order. But if you give it the option -t, it displays files and folders in the order they were last modified, with the most recent files at the top.

You can combine options. Try ls -lt, which presents files and folders in a list in the order they were modified.

If you’re brand new to the concept, that should keep you busy for a while. But I want to introduce you to a powerful Unix command that will help you become self-sufficient in the digital realm: man.

That’s a man man

The man command is Unix’s built-in documentation system. You can pass any other command as an argument to man, like man pwd or man ls, which present extensive manual pages for those commands. But how do you use the man command? It is easy; just invoke man man to see a manual for man.

What’s cool about man is that it’s entirely self-documenting. Need help getting around? Press h while in the man application to see a help screen with all the keyboard shortcuts, like how to exit a man page (press q).

Man pages are usually laid out with:

  • A brief description of the command
  • A quick summary of arguments and options for the command
  • A detailed description of the command, followed by descriptions of the options

Usually, near the bottom, a man page gives examples and a list of related commands you can explore.

But how do you navigate inside a man page or the help screen? You could use regular arrow keys along with pgup and pgdown. Space will also advance by one screen. But if you want to learn Unix, I recommend becoming familiar with VIM keys.

Navigate like a VIM

VIM is a lightweight text editor for Unix and is a subject for another time, but its keyboard shortcuts are used in many Unix apps, like man, so they’re worth learning.

(And if you got curious and tried the VIM command and don’t know how to get out: press :q!)

VIM’s ancestors were developed when many keyboards did not have arrow keys, so developers had to get creative. For instance, they decided on:

  • j to move down
  • k to move up

These keyboard shortcuts work in man to move up and down single lines. Here’s a neat trick: Press a number before j or k to move down or up that many lines. So 5j moves down five lines.

Here are some others:

  • z to move down one page
  • w to move up one page
  • g to navigate to the beginning of a man page
  • G to navigate to the end of a man page

To search inside a man page, press forward slash (/) followed by your search term. Note that it’s case-sensitive. For instance, in man man, typing /System brings up results, /system does not.

  • Press n to “find next”
  • Press N to “find previous”

These shortcuts may seem like dumb or nerdy things to learn, but they can supercharge your Unix powers. Here’s a video of Luke Smith quickly renaming files using VIM shortcuts:

How vim Makes my Daily Life Easier youtu.be

That’s enough to get around a man page. If you want to master VIM keys, try the VIMtutor command, which presents an interactive tutorial. I also recommend the online game VIM Adventures if you prefer that approach.

There you have it: the basics of navigating a Unix file system, using the man command to get help, and navigating a man page. With those building blocks, you’re set to learn much, much more.

Want to leave a tip?

We answer to you. Help keep our content free of advertisers and big tech censorship by leaving a tip today.
Want to join the conversation?
Already a subscriber?