Surfalytics
CLI course overview

Just Enough CLI · Step 7 Free

Permissions, sudo, archives, and shortcuts

The last set of essentials: who can touch a file, how to act as the administrator, and how files travel between servers.

File modes and permissions

ls -l shows each file’s permissions as a string like -rw-r--r--:

  • r — readable
  • w — writable
  • x — executable (can run as a program)
  • - — permission not granted

The string holds three sets: user (owner), group, other. So -rw-r--r-- means: the owner can read and write; everyone else can only read.

chmod — change permissions

chmod 644 file

The common numeric modes to memorize:

ModeMeaningUsed for
644user: read/write; others: readfiles
600user: read/write; others: nothingsecrets, SSH keys
755user: all; others: read/executedirectories, programs
700user: all; others: nothingprivate directories

You will meet this the first time SSH refuses your key with “permissions are too open” — the fix is chmod 600 ~/.ssh/your-key.pem.

sudo — run as the superuser

sudo runs one command as root. Installing system packages, editing system configs, restarting services — all need it:

sudo apt-get install htop
sudo systemctl restart my-service

Use it deliberately. sudo rm -r on the wrong path has no undo.

A symbolic link is a file that points to another file or directory — an alias, like a Windows shortcut. Quick access to long paths:

ln -s /very/long/path/to/data ~/data

Archiving: tar and gzip

gzip compresses a single file (file.gz; unpack with gunzip). It does not bundle directories — that is tar’s job:

tar cvf archive.tar file1 file2 ...   # create an archive
tar xvf archive.tar                   # extract it

In practice you will mostly meet the combined form .tar.gztar czf to create, tar xzf to extract. Every dataset download and every software release uses it.

Keyboard shortcuts

Editing commands with arrow keys is slow. These work in every shell:

ShortcutAction
CTRL-Ajump to the beginning of the line
CTRL-Ejump to the end of the line
CTRL-Werase the previous word
CTRL-Uerase to the beginning of the line
CTRL-Kerase to the end of the line
CTRL-Ypaste back what you erased
CTRL-P / CTRL-Nprevious / next command

For editing files in the terminal: nano is the simple choice; vim and emacs are the powerful ones. Learn nano now, vim later.

Practice in your terminal:

  1. Run ls -l ~ and read the permission strings on three files.
  2. Create a file and lock it down: touch secret.txt && chmod 600 secret.txt && ls -l secret.txt.
  3. Pack and unpack: tar czf test.tar.gz secret.txt, delete the original, then tar xzf test.tar.gz.
  4. Type a long command, then practice CTRL-A, CTRL-E, and CTRL-W. Clean up with rm secret.txt test.tar.gz.