title

Introduction to Linux

Linux is a good Operating System

 

Shell, basics

Objectives

General

What does RTFM mean?

What is a Shebang

What is Shell

What is the shell

What is the difference between a terminal and a shell

What is the shell prompt

How to use the history (the basics)

Navigation

What do the commands or built-ins cd, pwd, ls do

How to navigate the filesystem

What are the . and .. directories

What is the working directory, how to print it and how to change it

What is the root directory

What is the home directory, and how to go there

What is the difference between the root directory and the home directory of the user root

What are the characteristics of hidden files and how to list them

What does the command cd - do

Looking Around

What do the commands ls, less, file do

How do you use options and arguments with commands

Understand the ls long format and how to display it

A Guided Tour

What does the ln command do

What do you find in the most common/important directories

What is a symbolic link

What is a hard link

What is the difference between a hard link and a symbolic link

Manipulating files

What do the commands cp, mv, rm, mkdir do

What are wildcards and how do they work

How to use wildcards

Working with Commands

What do type, which, help, man commands do

What are the different kinds of commands

What is an alias

When do you use the command help instead of man

Reading Man Pages

How to read a man page

What are man page sections

What are the section numbers for User commands, System calls and Library functions

title

Shell, Navigation

Navigating a Unix system

Moving through directories

moving from one folder another

cd <directory_path>

Example: To move from the current working directory to the root directory

cd /root

Current working directory

To view the current working directory

pwd

File Manipulation

Creating files and directories

creating a new file

touch <filename>

creating a new directory

mkdir <directory_name>

Displaying the contents of a file

displaying the contents of a file

cat <filename>

Listing files and directories

To list the files:

ls

To list the files including the hidden ones:

ls -a

To list the files including the hidden ones in long format:

ls -la

Moving and copying files and directories

copying a file into the same directory

cp <filename> <directory_name>

Example: To copy the file todos.txt to /tasks directory

cp todos.txt /tasks

copying all files and folders including hidden ones to the current working directory (../hsms/. ensures that hidden files and folders are included.)

cp -r ../dir/. .

copy only the files without the folders to the current working directory:

  • ../dir/*: Matches all non-hidden files.
  • ../dir/.*: Matches all hidden files (excluding . and .. entries).
cp ../dir/* ../dir/.* .

renaming a file

mv <old_filename> <new_filename>

moving a file from one directory to another

mv <filename> <directory_path>

Example to move the file todos.txt to /tasks/today

mv todos.txt /tasks/today

Deleting files and directories

deleting a file

rm <filename>

deleting a directory

rm -r <directory_name>

we can also use the command

rmdir <directory_name>

 

title

Emacs

Emacs a command line editor for Linux and was created by Richard Stallman.

Opening a file from emacs

C-x C-f

Saving files

C-x C-s

Switching from one buffer to another

Using the mark and the point to set the region

Cut and paste lines and regions

cut an entire line

C-k

paste

C-y

Search forward and backward

search forward

C-s

Invoke commands by name

Undo

C-x u

Cancel half-entered commands

Quitting Emacs

C-x C-c

 

Vi

Vi is another command line text editor created by Bill Joy.

Start vi

to start editing a file using vi, we open or create a file using

vi <filename>

Difference between command and insert modes

command mode is used to type commands such as save or exit vi and insert mode is used to write into the file.

to enter insert mode

i

to enter command mode, just hit the escape key (esc) on the keyboard.

Cut and Paste lines

cut the current line

yy

delete the current line

dd

cut and delete the current line

yy dd

paste the lines in the buffer into the text after the current line

p

Search forward and backward

move the cursor to the beginning of the line

0

move the cursor to the end of the line

$

Undo

u

Quit

to quit vi, enter the command mode using escape key and use the command

:q!

to write (save changes) and quit

:wq!

Terminal Customization

Aliases

Aliases

Aliases can be created in the ~/.bashrc file.

Syntax:

alias alias_name="commands_to_run"

Example:

alias project_git_status="cd /home/projects/project; git status"

after creating the alias, run the source command to ensure the new alias works:

source ~/.bashrc

Functions

Apart from creating simple aliases, we can create a function which is a block of code that you can call by name. 

Functions can have parameters, and they can return values.

Basic syntax is:

function function_name() {
    # Commands
}

Example:

function greet() {
    echo "Hello, $1!"
}

To use this, we would call the function as: greet "Aaqil"

This would give the result: Hello, Aaqil!