Merikanto

一簫一劍平生意,負盡狂名十五年

Linux Shell Commands - 01 Basic

This post is Part One of the summary of some common Linux Shell Commands. So let’s begin.


Seeking Help

It’s important to know where to seek help when we’re not familiar with certain commands, or just have doubts.

  • whatis: Quick explanation

  • man: Manuals, in 8 sections

  • info: Provides more description than manual does

  • whereis & which: find paths


Check Status

Commands to check CPU info, processes status:

  • top: Task manager

  • lscpu: Check CPU info

  • ps: Process status

  • ps aux: List all processes and their status and resource usage

  • tail -f: Monitoring log files, etc. in real time

  • stat: Check file status

  • df -h: Check disk space


Shortcuts

Important shortcuts to make things easier.

  • tab: Auto-complete the commands (especially with ls)

  • * & ?: fuzzy search

  • Ctrl + a and Ctrl + e

  • alias: Create command shortcuts. alias -p shows all.

    • e.g. alias ll="ls -alh"
    • Remove: unalias ll

Listings & Paths

Including commands regarding file paths, info, permissions, and more.

  • ls -dlh: Current directory’s info, human-readable

  • ls -alh: All files in detail, human-readable

  • ls -asSh | sort: File size, sorted

  • pwd: print absolute paths.

  • mkdir -p: Create multiple directories.

  • e.g. Note the use of { }

    1
    mkdir -p test/{lib/,bin/,doc/{info,product}}

Permissions

  • sudo usermod -G sudo <USER>: Get sudo privileges.

  • sudo chown <changed USER:changed GROUP> <FILE>: Change owner & group

  • chgrp: change group

  • umask

  • read (4), write (2), execute (1)

    • Octal Permission
      0
      1 –x
      2 -w-
      3 -wx
      4 r–
      5 r-x
      6 rw-
      7 rwx
    • chmod 600 & chmod go-rw: Only owner can read & write

    • chmod 755 & chmod +x: Permission to execute

    • chmod 777: All Privileges