Understanding & Executing - Linux Command Line - Part 2

The second part of the walkthrough of the Linux (& macOS) command line

Part 1: https://medium.com/@AndreasSterneer/unixcommandline1-76e1d6721614

Introduction

Quick Recap

File & Directory Permissions

ls -l 
directory/user/group/other = -/---/---/---
- /rwx/rw-/r--
d /rw-/r--/--

chmod

chmod <class>[+-=]<mode(s)> <file(s)>chmod g-r image.jpg //revokes group permission to read the filechmod ug+rw note.txt //adds user & group permissions to read & writechmod o-rwx,u+rwx file.txt //revokes group other permissions to read, write, execute & also adds user permission to read, write & execute

Numerics

Binary to decimal (111 = 4 + 2 + 1 = 7)Permission Number | Permissions Text | Permission Mode| 7 | read, write and execute | rwx |
| 6 | read and write | rw- |
| 5 | read and execute | r-x |
| 4 | read only | r-- |
| 3 | write and execute | -wx |
| 2 | write only | -w- |
| 1 | execute only | --x |
| 0 | none | --- |
777 = rwxrwxrwx
707 = rwx---rwx
534 = r-x-wxr--

Redirection & Pipes

Standard Output

>
cat > fruits.txt
head -n1 <file>
head -n1 fruits.txt > fruits-2.txt
cat fruits-2.txt fruits-3.txt fruits-4.txt > fruits-5.txt

The Append Operator

>>
 cat >> fruits.txt
cat fruits-2 fruits-3 >> fruits-4

Standard Input

mail john.appleseed@email.com < KeynoteNotes.docx

Standard Error

2>          // Only redirects the error messages
&> // Redirects both output and error messages
find / -name "*.pid" 2> error.txt

The heredoc

<program/command> << <document name>
cat << EOF
my default shell is $SHELL
my default shell is /bin/zsh/ 
my account name is `whoami`
my account name is andreas

Pipes

<<MUSIC | sort
ls -l | grep fruit

DF Command

df -h

Tee Command

df -h | tee diskInfo.txt

Working with process

PID = Process ID
PPID = Parent Process ID
TTY = The controlling terminal of the process
STIME = Starting time of the process
TIME = CPU time
CMD = The command the process represents
S = Sleeping Process
S+ = In the foreground of the controlling terminal

The ps command

The top command

top -s 5 -o cpu

Foreground & Background Process

 find / -name “*.pid”
find / -name “*.pid” &

Jobs

The fg & bg commands

fg %job_ID // resumes the process the foreground with the job ID behind the % operatorbg %job_ID // resumes the process in the background with the job ID behind the % operator