0% found this document useful (0 votes)
8 views44 pages

Class-2 Basic Linux Commands

This document provides an introduction to basic Linux commands and the command line interface (CLI), focusing on the Bourne Again Shell (bash). It covers command syntax, options, arguments, and various types of commands, including user, universal, system, and networking commands. Additionally, it explains specific commands like ls, mkdir, cd, cp, mv, and chmod, along with their syntax and usage examples.

Uploaded by

madhavdevpj2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views44 pages

Class-2 Basic Linux Commands

This document provides an introduction to basic Linux commands and the command line interface (CLI), focusing on the Bourne Again Shell (bash). It covers command syntax, options, arguments, and various types of commands, including user, universal, system, and networking commands. Additionally, it explains specific commands like ls, mkdir, cd, cp, mv, and chmod, along with their syntax and usage examples.

Uploaded by

madhavdevpj2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

System software Foundations of Computing

Module 3- Basic Linux – introcuction


• Linux, a Unix-like operating system, employs the Command
Basic Linux commands

Line Interface (CLI) through a program called the shell.


• The shell acts as an intermediary between the user and the
Linux kernel, executing commands and returning results.
• Among the various Linux shells available, the Bourne Again
Shell (bash) is the most popular.
• Developed under the GNU Project, bash is an enhanced
version of the original Bourne shell (sh), designed by Steve
Bourne at Bell Labs.
Module 3- Basic Linux – introcuction
• In Linux, the CLI appears as a login prompt where users
Basic Linux commands

must enter their username and password to access the


system.
• Upon successful login, a prompt appears, indicating the
system is ready for commands.
• This prompt format varies based on the user type:
– For regular users: $
– For root (administrator) users: #
Module 3- Basic Linux – introcuction
• For example:
Basic Linux commands

• [sanvik@Linuxhost /home/sanvik]$ or
• [sanvik@Linuxhost ~]$
• In this format:
– sanvik — the logged-in user's name
– Linuxhost — the system's hostname
– ~ — shorthand for the user's home directory
Module 3- Command Syntax, Options, and Arguments
• Understanding the correct syntax of Linux commands is
Basic Linux commands

crucial when working with the command line interface


(CLI).
• The basic syntax for a Linux command is as follows:
• $ <command_name> <-options> <list_of_arguments>
• This structure defines the sequence and separation of
options and arguments in relation to the command
name, which determines the command's execution
behavior.
Module 3- Command Syntax, Options, and Arguments
• Command Name:
Basic Linux commands

• This is a valid Linux command that can be a built-in


shell script, system call, or user-defined program stored
in a directory listed in the PATH environment variable.
• The command name is mandatory; other parts (options
and arguments) are optional depending on the
command's operation.
• Example:
• $ ls
Module 3- Command Syntax, Options, and Arguments
• Options:
Basic Linux commands

• Options are used to modify the behavior of a


command.
• They are specified after the command name and are
preceded by one (-) or two hyphens (--).
• Options can either be mentioned separately or
combined in a single hyphen
• $ ls -l
• Displays detailed information about files in long format.
Module 3- Command Syntax, Options, and Arguments
• $ ls -l -t
Basic Linux commands

– Displays detailed information sorted by modification time.


• $ ls -lt
– Combines -l and -t options in one command for the same
output.
• $ ls -lt -r
– Displays detailed information sorted by modification time in
reverse order.
Module 3- Command Syntax, Options, and Arguments
• Arguments:
Basic Linux commands

• Arguments are inputs provided to the command. They


may refer to directories, files, or patterns.
• Arguments are optional and depend on the command’s
functionality.
• Example:
• $ ls -l *.c
– Displays details of all .c files in the current working directory.
Module 3- Command Syntax, Options, and Arguments
• $ ls -l /etc
Basic Linux commands

– Displays detailed information about the contents of the /etc


directory.
• $ cat /home/abc
– Displays the contents of the file abc located in the /home
directory.
Module 3- Command Syntax, Options, and Arguments
• Linux provides a vast range of commands categorized
Basic Linux commands

into different types based on their functionality.


– 1. User Commands
– 2. Universal Commands
– 3. System Commands
– 4. Communication and Networking Commands
Module 3- Command Syntax, Options, and Arguments
• 1. User Commands
Basic Linux commands

• Commands commonly used by users for file management,


navigation, and general system interaction.
• Examples:
– ls → List directory contents
– cp → Copy files
– mv → Move or rename files
– cat → Display file contents
– grep → Search within files
Module 3- Command Syntax, Options, and Arguments
• 2. Universal Commands
Basic Linux commands

• Commands that are available across all major Linux


distributions like Ubuntu, Fedora, CentOS, etc.
• These commands ensure consistent functionality
irrespective of the Linux variant.
• Examples:
– pwd → Display the current directory
– mkdir → Create a new directory
– rmdir → Remove empty directories
– man → Display manual pages for commands
Module 3- Command Syntax, Options, and Arguments
• 3. System Commands
Basic Linux commands

• Commands that manage system processes, resources, and


kernel-related functions.
• These commands are often used by system administrators
to control system operations.
• Examples:
– ps → Display active processes
– top → Monitor system performance in real-time
– kill → Terminate a process
– shutdown → Power off or restart the system
Module 3- Command Syntax, Options, and Arguments
• 4. Communication and Networking Commands
Basic Linux commands

• Commands used for network management, monitoring,


and file transfers across networks.
• Examples:
– ping → Check network connectivity
– scp → Securely copy files over a network
– ftp → Transfer files between systems using FTP
– wget → Download files from the internet
Module 3- Command Syntax, Options, and Arguments
• Depends on how the commands are executed by the
Basic Linux commands

system, they are classified in to two


– Internal commands and
– External commands
Module 3- Command Syntax, Options, and Arguments
• Internal Commands
Basic Linux commands

• Internal commands are built directly into the shell itself.


They are loaded when the shell starts and do not exist
as separate files.
• Since these commands are part of the shell, they do
not require a separate process for execution.
Consequently, internal commands do not have a
process ID (PID) during execution.
Module 3- Command Syntax, Options, and Arguments
• Examples:
Basic Linux commands

• cd — Change the current directory


• pwd — Display the current working directory
• echo — Print text to the terminal
Module 3- Command Syntax, Options, and Arguments
• External Commands
Basic Linux commands

• External commands are not built into the shell; instead,


they are standalone programs stored as binary files in
specific system directories.
• The shell initiates a separate sub-process to execute these
commands.
• External commands are typically stored in:
– /bin — Common user commands (e.g., ls, mv, cat)
– /sbin and /usr/sbin — Commands requiring root privileges,
generally for system administration.
Module 3- Linux commands
• 1. ls Command (List Directory Contents)
Basic Linux commands

• The ls command is used to list files and directories in


the current or specified location.
• ls [options] [path_names]
• $ ls

• $ ls -l
Module 3- Linux commands
• total 0
Basic Linux commands

• This indicates the total number of blocks used by the


files in this directory. Since no significant data is stored
(small files or empty directories), it shows 0 blocks.
• -rw-r--r-- (File Permission)
• The first character represents the type of file:
• - → Regular file
• d → Directory
• l → Symbolic link
Module 3- Linux commands
• The remaining 9 characters are file permissions, divided
Basic Linux commands

into 3 groups:
• rw- → Owner's permissions (Read + Write)
• r-- → Group's permissions (Read only)
• r-- → Others' permissions (Read only)
• 1 (Link Count)
• This shows the number of hard links pointing to this file.
• For regular files, it's typically 1.
• For directories, it reflects the number of subdirectories
(including . and ..).
Module 3- Linux commands
• 2. mkdir Command (Create Directory)
Basic Linux commands

• The mkdir command is used to create new directories.


• Syntax:
• mkdir [directory_name]
• Example
• mkdir dir1 — Create a directory named dir1.
• mkdir dir1 dir2 — Create multiple directorie
• mkdir -p parent/child — Create parent and child directories
togethers.
Module 3- Linux commands
• 3. cd Command (Change Directory)
Basic Linux commands

• The cd command is used to navigate between directories.


• Syntax:
• cd [directory_path]
• Examples:
• cd dir1 — Change to dir1 directory
• cd .. — Move one directory back (parent directory)
• cd /home/user — Move to the specified absolute path.
Module 3- Linux commands
• 4. pwd Command (Print Working Directory)
Basic Linux commands

• The pwd command displays the current working


directory.
• Syntax:
• Pwd
• Example:
• $ pwd
• /home/sudheer
Module 3- Linux commands
• 5. cp Command (Copy Files and Directories)
Basic Linux commands

• The cp command is used to copy files and directories


from one location to another.
• Syntax:
• cp [options] <source> <destination>
• Examples:
• cp [Link] [Link]
– Copy [Link] to [Link]
Module 3- Linux commands
• cp [Link] dir1/
Basic Linux commands

– Copy [Link] to dir1 folder


• $ cp [Link] dir1/
• cp -r dir1 dir2
– Copy all contents of dir1 into dir2
Module 3- Linux commands
• 6. mv Command (Move/Rename Files)
Basic Linux commands

• The mv command is used to rename or move files and


directories.
• Syntax:
• mv [options] <source> <destination>
• Examples:
• mv [Link] [Link] — Rename [Link] to [Link]
Module 3- Linux commands
• mv [Link] dir1
Basic Linux commands

– Move [Link] to dir1 directory


• mv dir1 dir2
– Move the entire dir1 into dir2.
Module 3- Linux commands
• 7. cat Command (Concatenate and Display Files)
Basic Linux commands

• The cat command is used to display the contents of a file or


combine multiple files.
• Syntax:
– cat [options] [file_name]
• Examples:
• cat [Link]
– Display the contents of [Link]
• cat [Link] [Link] > [Link]
– Combine two files into one.
Module 3- Linux commands
• Redirection in Linux (> and >> Operator)
Basic Linux commands

• The > operator in Linux is used for output redirection,


allowing the output of a command to be saved into a
file instead of being displayed on the terminal.
• The operator
• > Overwrites the file and
• >> Appends data to the file.
Module 3- Linux commands
• Syntax:
Basic Linux commands

• <command> > <filename>


• Example:
• $ ls > [Link]
– The ls command lists the contents of the current directory.
– The > operator redirects this output to the file named
[Link].
– If [Link] already exists, its contents will be overwritten.
Module 3- Linux commands
• Input Redirection in Linux
• Input Redirection is a method of providing input to a
Shell scripting

command directly from a file instead of typing the


input manually.
• This is useful for processing the content of files using
commands that normally expect input from the
keyboard.
• The < symbol is used for input redirection.
Module 3- Linux commands
• Syntax:
Basic Linux commands

• $ command < inputfile


• Example:
• Wc < [Link]
Module 3- Linux commands
• 8. grep Command (Search for Patterns)
Basic Linux commands

• The grep command searches for specific text patterns


within files.
• Syntax:
• grep [options] "pattern" [file_name]
• Example:
– grep "error" [Link]
– grep -i "warning" [Link] — Case-insensitive search for
"warning".
Module 3- Linux commands
• 9. man Command (Manual Pages)
Basic Linux commands

• The man command displays the manual page for a


given command.
• Syntax:
• man [command_name]
• Example:
• man ls — Display the manual for the ls command
Module 3- Linux commands
• 10. chmod Command (Change File Permissions)
Basic Linux commands

• The chmod command is used to change file


permissions.
• Syntax:
• chmod [permissions] [file_name]
• Examples:
• chmod 755 [Link]
• Assign read (r), write (w), and execute (x) permissions.
Module 3- Linux commands
• Understanding the Numbers in chmod
Basic Linux commands

• The numeric code (like 755) is called the octal


representation of file permissions.
• The three digits represent the permissions for three
different user categories:
– 1st digit → Owner permissions
– 2nd digit → Group permissions
– 3rd digit → Others (everyone else) permissions
Module 3- Linux commands
• Permission Values in Octal:
Basic Linux commands

• Each permission type is assigned a numeric value:


– Read (r) → 4
– Write (w) → 2
– Execute (x) → 1
• To set multiple permissions
– Read + Write + Execute → 4 + 2 + 1 = 7
– Read + Execute → 4 + 1 = 5
– Read + Write → 4 + 2 = 6
Module 3- Linux commands
• chmod 755 [Link] →
Basic Linux commands

– 7 → Owner permissions (rwx) → Read + Write + Execute


– 5 → Group permissions (r-x) → Read + Execute
– 5 → Others permissions (r-x) → Read + Execute
• Result:
– Owner can read, write, and execute the file.
– Group can read and execute the file.
– Others can read and execute the file.
Module 3- Linux commands
• Alternative: Symbolic Mode (Human-readable form)
Basic Linux commands

• Instead of numeric values, symbolic notations can be


used
• Syntax:
• chmod u=rwx,g=rx,o=rx [Link]
• chmod g+w [Link]
Module 3- Linux commands
• 11. rmdir Command (Remove Directory)
Basic Linux commands

• The rmdir command is used to delete empty


directories.
• Syntax:
• rmdir [directory_name]
• Example:
• $ rmdir S2
Module 3- Linux commands
• For non-empty directories
Basic Linux commands

• rm -r dir1
• Example:
• rm -r S2
Basic Linux commands Module 3- Linux commands

You might also like