0% found this document useful (0 votes)
9 views

Linux Notes

Class notes on linux

Uploaded by

praveenadass02
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Linux Notes

Class notes on linux

Uploaded by

praveenadass02
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Contents

I Linux Shell ................................................................................................................................................ 1


Command to find the shell ........................................................................................................................ 1
II Files and Directories ............................................................................................................................... 1
2.1 Files ..................................................................................................................................................... 1
2.2 Directories ........................................................................................................................................... 1
2.3 File Paths............................................................................................................................................. 2
Absolute Path ........................................................................................................................................ 2
Relative Path ......................................................................................................................................... 2
Special Symbols ..................................................................................................................................... 2
III Binary and Data files............................................................................................................................. 2
3.1 Binary Files and its Characteristics ..................................................................................................... 2
3.2 Data Files and its Characteristics ........................................................................................................ 3
3.3 Handling Binary and Data Files .......................................................................................................... 3
IV Command based text editor .................................................................................................................. 3
4.1 Nano ................................................................................................................................................... 3
Basic Navigation .................................................................................................................................... 4
Editing Text ........................................................................................................................................... 4
Saving Changes...................................................................................................................................... 4
Exiting Nano .......................................................................................................................................... 4
Additional Features ............................................................................................................................... 4
4.2 Vim editor .......................................................................................................................................... 5
V Basic Linux commands ........................................................................................................................... 5
5.1 cd command ....................................................................................................................................... 5
5.2 pwd command ..................................................................................................................................... 5
5.3 cat command ....................................................................................................................................... 6
5.4 ls command ......................................................................................................................................... 6
5.5 cp command ........................................................................................................................................ 6
5.6 mv command ....................................................................................................................................... 7
5.7 rm command ....................................................................................................................................... 7

0
I Linux Shell

A Linux shell is a command-line interface (CLI) program used for interacting with the operating
system (OS). It acts as a mediator between the user and the Linux kernel, allowing users to issue
commands to perform various tasks such as navigating the file system, managing files and
directories, running applications, and configuring system settings.

Popular shells for Linux include Bash (Bourne Again Shell), which is the default on many
distributions, as well as others like Zsh (Z Shell), Fish, and more. Each shell has its own features,
syntax, and capabilities, but they all serve the fundamental purpose of providing a command-line
interface to the Linux operating system.

Command to find the shell

$echo $0

II Files and Directories


Files and Directories form the backbone of the filesystem, allowing users to organize and
manage data efficiently.
2.1 Files

1. Regular Files: These are the most common type of files in Linux. They can contain text,
programs, scripts, images, etc.
2. Directories: Directories are special files that serve as containers for other files and
directories. They provide a hierarchical structure to organize data.
3. Symbolic Links (symlinks): These are files that act as pointers to another file or
directory. They are similar to shortcuts in Windows.
4. Device Files: Found in /dev, these files represent physical and virtual devices connected
to the system (e.g., hard drives, printers, terminals).
5. Named Pipes : Special files used for inter-process communication. They allow data to
be passed between processes.
6. Sockets: Used for communication between processes on the same or different systems.

2.2 Directories

1. Root Directory: The top-level directory in Linux filesystem, denoted by /(forward slash).
All other directories and files are subdirectories or files within this hierarchy.
2. Home Directory: Each user has a designated home directory, usually located at
/home/username. This is where personal files and configurations are stored.
3. Current Directory: Represents the directory you are currently working in. It's denoted
by . (dot).
4. Parent Directory: Denoted by .. (double dot), it refers to the directory immediately
above the current directory.

1
2.3 File Paths

Absolute Path

An absolute path specifies the exact location of a file or directory from the root directory (/).

 Format: /path/to/file_or_directory
 Example: /home/user/Documents/file.txt
 Explanation:
o / is the root directory.
o home is a directory within the root.
o user is a directory within home.
o Documents is a directory within user.
o file.txt is the file located within the Documents directory.

Relative Path

A relative path specifies the location of a file or directory relative to the current working
directory.

 Format: path/to/file_or_directory
 Example: Documents/file.txt
 Explanation:
o If the current working directory is /home/user, then Documents/file.txt refers to
/home/user/Documents/file.txt.

Special Symbols

 . (Dot): Represents the current directory.


o Example: ./file.txt (refers to file.txt in the current directory).
 .. (Double Dot): Represents the parent directory.
o Example: ../file.txt (refers to file.txt in the parent directory of the current
directory).

III Binary and Data files

Files can broadly be categorized into two main types: binary files and data files.

3.1 Binary Files and its Characteristics

Binary files are files that contain data in a format that's not intended to be human-readable.
Instead, they are encoded in binary format, which is a sequence of 0s and 1s, representing
machine code or compiled data. Binary files typically include executable programs, libraries, and
compiled code.

2
Characteristics:

Non-human-readable: You cannot interpret binary files directly using a text editor because they
are encoded in a format understood by computers.

Executable: Binary files include executable programs (e.g., .exe), which are applications that can
be run by the operating system.

Compiled Code: They often contain compiled code, which is the output of programming
languages after compilation with extension like .o

3.2 Data Files and its Characteristics

Data files contain information or data that is stored in a format that can be interpreted or
processed by applications or users. These files may store text, images, documents, databases, or
any other form of structured or unstructured data.

Characteristics
Human-readable: Data files are typically human-readable or can be interpreted by specific
applications.

Structured Data: They may store structured data in formats like text, XML, CSV, etc.

Content Variety: Data files can range from plain text documents to complex multimedia files like
images, audio, video, etc

3.3 Handling Binary and Data Files

Binary Files: View and edit binary files using specialized tools or hex editors capable of
interpreting binary data.

Data Files: Use text editors or dedicated applications suited for the specific data format to view
and edit.

IV Command based text editor

In Linux, there are several command-line based text editors that are popular among users who
prefer working within a terminal environment. These editors are efficient, lightweight, and can
be used over SSH sessions or on systems without a graphical interface. Here are some commonly
used command-based text editors in Linux:

4.1 Nano

Nano is a simple and beginner-friendly text editor that comes pre-installed on many Linux
distributions. It's known for its straightforward interface and ease of use.

3
Open a file or create a new one: $nano filename

4.1.1 Working with nano

Basic Navigation

 Use arrow keys to move the cursor.


 Page Up (Ctrl + Y) and Page Down (Ctrl + V) to navigate through the file.
 Ctrl + B to move back one character, Ctrl + F to move forward one character.
 Ctrl + G for help and to display current line number and file status.

Editing Text

Nano allows you to edit text directly within the terminal:

 Inserting Text: Simply start typing to insert text at the current cursor position.
 Deleting Text: Use the Backspace or Delete keys to remove characters.
 Cut, Copy, Paste: Nano doesn't have native cut, copy, and paste shortcuts like graphical
editors. Instead:
o Ctrl + K: Cut (kill) the current line.
o Ctrl + U: Uncut (paste) the last killed text.

Saving Changes

To save changes made to a file in Nano:

1. Press Ctrl + O (Write Out). Nano will prompt you to confirm the filename if you haven't
specified one.
2. Press Enter to confirm the filename or modify it if needed.
3. After saving, you can continue editing the file.

Exiting Nano

To exit Nano and return to the command prompt:

 Press Ctrl + X. If you have unsaved changes, Nano will prompt you to save them (Y for
yes, N for no).
 If you choose to save changes, follow the steps mentioned above (Ctrl + O to save, Enter
to confirm filename).

Additional Features

Nano provides additional functionalities accessible through keyboard shortcuts:

 Search: Use Ctrl + W to search for a specific string within the file.

4
 Replace: Use Alt + R to activate the replace function, allowing you to find and replace
text within the file.

4.2 Vim editor

Vim (Vi IMproved) is a powerful and highly configurable text editor inspired by the classic Unix
editor Vi. It is known for its modal editing capabilities and extensive customization options.

Open or create a file with: $vim filename

Key Features: Multiple modes (normal, insert, visual), syntax highlighting, macros, plugins,
extensive customization.

Learning Curve: Steeper learning curve compared to Nano, but very efficient once mastered.

V Basic Linux commands


5.1 cd command

cd stands for "change directory." It is a command-line utility used to change the current working
directory in the command line interface (CLI).

To change the current directory, use the cd command followed by the directory path you want to
switch to.

cd [directory_path]

Examples:

cd /home/user/Documents Changes the current directory to /home/user/Documents

cd .. Moves to the parent directory of the current directory

cd ~ or cd $HOME Changes to the home directory of the current user

Special Directories:

cd . Does nothing (remains in the current directory).

- (Dash): Represents the previous working directory (used as an argument to cd).

cd - Changes to the directory you were in before the current one

5.2 pwd command

pwd stands for "print working directory." It is a command-line utility that outputs the absolute
pathname of the current working directory.

5
pwd

Example:

pwd /home/user

5.3 cat command

cat command is used to concatenate and display the contents of files. Despite its name, cat is
versatile and has several other uses beyond just concatenating files

cat filename To display the contents of a file on the terminal

You can concatenate multiple files and display them sequentially using cat

cat file1 file2 This will output the contents of file1 followed by file2

cat file1 file2 > combined_file To concatenate files and redirect the output to another file

This will combine file1 and file2 and save the output to combined_file.

5.4 ls command

ls command is used to list directory contents. It shows you the files and directories within the
specified directory, or if no directory is specified, it lists the contents of the current working
directory.

ls To list the files and directories in the current directory


ls /path/to/directory To list specific directory
ls –a -a option shows all files including hidden files
ls –l long listing format
ls –lh human readable file sizes
ls –t sort by modification time
ls –R list subdirectories recursively

5.5 cp command

cp command is used to copy files and directories from one location to another.

cp source_file destination To copy a file from one location to another

6
For example, to copy a file named file1.txt from the current directory to /tmp directory
cp file1.txt /tmp
cp file1.txt file2.txt directory_name To copy multiple files into a directory
cp -r source_directory destination To copy a directory and its contents
recursively, use the -r (or -R) option
cp -i source_file destination To prompt before overwriting existing files
cp -v source_file destination To see detailed information about the files
being copied, use the -v (verbose) option:
5.6 mv command

mv command is used to move files and directories from one location to another. It can also be
used to rename files and directories within the same location.

mv source_file_or_directory destination To move a file from one location to another or


rename a file
mv -r source_directory destination To move a directory and its contents recursively,
use the -r (or -R) option:
mv old_file.txt new_file.txt
5.7 rm command

rm command is used to remove (delete) files and directories from the file system. It's a powerful
command-line utility, but it's important to use it with caution because deleted files are typically
not recoverable without specialized tools.

rm file_name To remove a file


rm file1.txt file2.txt file3.txt Removing Multiple Files
You can remove multiple files at once by specifying their names separated by spaces
rm -d directory_name To remove an empty directory
rm -r directory_name To remove a directory and its contents recursively

You might also like