Day 3 Notes on “Learn Linux in 5 Days and Level Up Your Career” by Jason Cannon on Udemy

Day 3

1. File and directory permissions:

When ls -l typed in the console, something like this will show up on your screen: -rw-r--r-- 1 Philipp users 10400 Sep 27 08:52

The first character or symbol could be one of the following (Symbol – Type):
- – Regular file.
d – Directory.
l – Symbolic link.

Other characters in the permission string can be (Symbol – Permission):
r – Read
w – Write
x – Execute

Permission is different for files and directories. Read permission for example for a directory, enables you to see files in that directory.

Permission Categories:

Symbol – Category
u – User
g – Group
o – Other
a – All

Every user belongs to at least one group but can belong to many groups.
groups – Displays a user’s groups.
id -Gn – (As previous)

Secret Decoder Ring:

To go back to the example above: -rw-r--r-- 1 Philipp users 10400 Sep 27 08:52
- – Type
rw- – User
r-- – Group
r-- – Other
If specific permission is not granted, a hyphen - will take its place.

Changing Permissions (symbolic mode):

Item – Meaning
chmod – Change mode command.
ugoa – User category: user, group, other all.
+-= – Add, subtract, or set permissions.
rwx – Read, Write, Execute.

So for example: chmod g+w
This should change:
-rw-r--r-- 1 Philipp users 10400 Sep 27 08:52
Into this:
-rw-rw-r-- 1 Philipp users 10400 Sep 27 08:52
To add and subtract from multiple groups:
chmod u+rwx,g-x
-rwxrw-r-- 1 Philipp users 10400 Sep 27 08:52
Change all:
chmod a=r
Will result in:
-r--r--r-- 1 Philipp users 10400 Sep 27 08:52

Octal mode permission change examples:

chmod 700 – “-rwx——”
chmod 755 – “-rwxr-xr-x”
chmod 664 – “-rw-rw-r–”
chmod 660 – “-rw-rw—-”
chmod 644 – “-rw-r–r–”

Change group of file:

chgrp sales

File Creation Mask:

If no mask was used permissions would be:
777 for directories
666 for files

The umask Command:

umask [-S] [mode]
umask – Shows the mask used, i.e.: 0022
umask – Shows the mask used in symbolic, i.e.: u=rwx,g=rx,o=rx

2. View Files and the Nano Editor:

The cat Command:

cat file – Display the contents of file.
more file – Browse through a text file.
less file – More features than more.
head file – Output the beginning (or top) portion of file (10 lines by default).
tail file – Output the ending (or bottom) portion of file (10 lines by default).

Navigating a file:

space bar – Advance to the next page.
enter key – Advance one line.
q key – Quit viewing the file.

-n – Number of lines.
tail -15 file.txt – Output the last 15 lines at the ending (or bottom) portion of file.
tail -f file – Display data as it is being written to the file.
To exit the real-time display hit ctrl+c

The Nano Editor:

nano – Open Nano Editor.
pico – Some Destributions use pico for the Nano Editor.
nano file.txt – Open file.txt with the Nano Editor.
Use ctrl+x to exit the file.
Use ctrl+o to save the file.
Use ctrl+g to get help.

The Vi Editor:

vi file.txt – Open file with Vi Editor.
vim file.txt – m stands for improved, more features.
view file.txt Open file with Vi Editor in read only mode.

There are three modes in the Vi Editor, you are always in one of three modes, by default when opening Vi Editor you are in command-mode.

All three modes:
Mode – Key-Binding
Command-Mode – Esc
Insert-Mode – i or a A
Line-Mode – By beginning command with a :.

Command-Mode Key-Bindings:

k – Up one line.
j – Down one line.
h – Left one character.
l – Right one character.
w – Right one word.
b – Left one word.
^ – Go to the beginning of the line.
$ – Go to the end of the line.

x – Delete character.
dw – Delete a word.
dd – Delete a line.
D – Delete from the current position.
r – Replace the current character.
cw – Change the current word.
cc – Change the current line.
c$ – Change the text from the current position.
c – Same as c$.
~ – Reverse the case of a character.
yy – Yank (copy) the current line.
y<position> – Yank the <position>.
p – Paste the most recent deleted or yanked text.
u – Undo.
Ctrl-R – Redo.
/<pattern> – Start a forward search.
?<pattern> – Start a reverse search.
When searching use lower case n to go to the next result, and upper case N to the previous result.

Insert-Mode Key-Bindings:

i – Insert at the cursor position.
I – Insert at the beginning of the line.
a – Append after the cursor position.
A – Append at the end of the line.

Line-Mode Key-Bindings:

:w – Writes (saves) the file.
:w! – Forces the file to be saved.
:q – Quit.
:q! – Quit without saving changes.
:wq! – Write and quit.
😡 – Same as :wq.
:n – Positions the cursor at line n.
:$ – Positions the cursor on the last line.
:set nu – Turn on line numbering.
:set nonu – Turn off line numbering.
:help [subcommand] – Get help.

Repeating Commands:</h4

k5 – Move up a line five times.
80i – Insert 80 times.
80i_ – Insert 80 “_” characters.

vimtutor – Tutorial for Vi Editor.

A Vim Cheat Sheet can be found here:

The Emacs Editor:

emacs file.txt – Edit file.txt.
C-<char> – Ctrl while pressing <char>.
M-<char> – “Meta” key (alt key) while pressing <char>. Esc key can also be used as the “Meta” key.

For example:
C-h – Help.
C-x, C-c – Exit.
C-x, C-s – Save the file.
C-h t – Built-in tutorial.
C-h k <key> – Describe key.

Emacs File Navigation:

C-p – Previous line.
C-n – Next line.
C-b – Backward one character.
C-f – Forward one character.
M-f – Forward one word.
M-b – Backward one word.

C-a – Go to the beginning of the line.
C-e – Go to the end of the line.
M-< – Go to the beginning of the file.
M->- Go to the end of the file.
C-d – Delete a character.
M-d – Delete a word.
C-k – Kill (cut).
C-y – Yank (paste).
C-x u – Undo.
C-s – Start a forward search.
C-r – Start a reverse search.

Emacs Repeat Commands:

C-u N <command> – Repeat <command> N times.
For example:
C-u 10 C-d

Find Files and Directories

find [path] [expression]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.