0% found this document useful (0 votes)
9 views51 pages

02 Shell

The document discusses the basics of the bash shell and its role as a command-line interface for interacting with the operating system. It covers the execution of commands, the structure of ELF files, and the dynamic linking process, along with various Linux commands for file management and system operations. Additionally, it provides a brief overview of command documentation and file viewing/editing utilities.
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)
9 views51 pages

02 Shell

The document discusses the basics of the bash shell and its role as a command-line interface for interacting with the operating system. It covers the execution of commands, the structure of ELF files, and the dynamic linking process, along with various Linux commands for file management and system operations. Additionally, it provides a brief overview of command documentation and file viewing/editing utilities.
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

02_Shell

Moatasem Elsayed
How the bash is Started on CLI
Systems ?
kthreadd

They are typically used to manage hardware that's why they are directly handled by the kernel and
have high priority.

kthreadd so that a clean environment is obtained even if this were to be


invoked by user space by way of modprobe, hotplug device, etc.

For more detail, the interface for the creation of kernel threads is declared in
<linux/kthread. h>.
[Link]

Init Process
Qemu alt+ctrl+1/2
What is the main purpose of shell ?
What is the main purpose of shell ?
- A shell provides a command-line interface, allowing users to interact with the operating
system and execute commands

- The shell serves as an interpreter for running programs and scripts. It can execute both
system-level commands and user-created scripts.

What is the meaning by commands ?


It is just program compiled and be as ELF file
What is the Elf file ?
Execve
Header
Elf may be dynamic or static
What is the dynamic Loader ?
sections

Elf needs ld-linux as dynamic Linker to load libraries

Explicitly
Elf file has info about what is the shared is needed ?

I need the dynamic linker to load


Libc.S0.6 to let my application able to run

Linux-vdso:
Virtual Dynamic Shared Object," and it's a mechanism to
optimize certain system calls and reduce the overhead of
switching between user space and kernel space during
system call execution.
trace system calls (ELF)

Run

Execve

loader

libraries

the dynamic linker (/lib64/[Link].2) is responsible for the actual runtime dynamic
Main linking process, while the cache (/etc/[Link]) contains information about shared libraries to
speed up their lookup. The linker configuration files and cache work together to ensure efficient
loading and resolution of shared libraries.
How the calling happen to shared library ?
Plt and GOT
Position-Independent Code
Global Offset Table
1- first time() before Lazy binding
call
Code call
printf@got.
2- printf@plt section
printf@plt 3- jmp to got
plt

1- call printf@plt
Second time
So Let's create our Bash ?
Fork
execve
Simple shell without argument
Shell with argument
So now we are ready to run Elf and
access files !

So what is meant by file ?


Inode
Task : use lstat and show info about file
Linux commands can be categorized into various groups based on
their functionality

1-File and Directory Management


-Help and Documentation
10-Process Management

2-File Viewing and Editing 11-Networking:

3-Controls: Redirection,Piping,Wildcard 12-User Management:

4-File Permissions: 13-Package Management:

5-File Compression and Archiving: 14-System Maintenance:

6-Text Processing 15-Links

7-System Information: 16- FS

8-System Monitoring and Logging

9-search
Anatomy of Linux Command

1
2
Command [options] ..Input
3
4
5
6
Built-In
7 Command User Command
8
9
10
11
12
13
14
Basics && File and Directory Management
● ls: List files and directories.
● pwd: Print working directory.
● cd: Change directory.
● echo /printf : print
● mkdir: Create directories.
● rm/rmdir: Remove directories.
● touch: Create empty files.
● cp: Copy files and directories.
● mv: Move or rename files and directories.
● rm: Remove files and directories.
● Alias
● history
1- pwd

1
2 Print Working directory. This command would print absolute path of working
3 Directory. It prints the current directory of the terminal window.
4
5
6
7
8
9
10
11
12
13
14
2-LS

1
Most common used
2
3
4
5
6
7
8
9
10
11
12
13
14
3-cd
1
2
Cd like cd ~ Cd dire1/dire2
3 Cd ..
4
5
6
7
Cd ../../ Cd / Cd ../dire3
8
9
10
Cd ~
11
12
13 Cd -
14
4-echo
1 Echo “hello”
2
3
4
Echo –e “text”
5
6
7
8
9 Echo –n “text”
10
11
12
13
14
5-printf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
6-mkdir

1
2
3
4
5
6
7
8
9
10
11
12
13
14
7-rm/rmdir

1
2
3
4
5
6
7
8
9
10
11
12
13
14
8-cp/mv
1
2
3
cp mv
4
5
6
7
8
9
10
11
12
13
14
9-alias

1
2
3
4
5
6
7
8
9
10
11
12
13
14
10-history

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Help and Documentation:
● man: Display manual pages for commands.
● --help or -h: Display command-specific help
● Tldr
● Cheat
● Info.
● Whereis
● Which
● whatis
Utils to understand Command

1
2
3
4
man/info
5 where tldr cheat
6
7
Command
8 --help Whereis command
9 Whereis –b command
10
Man command
11 Which command
12
whatis
13
command Apropos “requirement”
–f command
man14 man –k “requirement”

info command
File Viewing and Editing:
● cat: Concatenate and display file content.
● more / less: View file content one screen at a time.
● head / tail: Display the beginning or end of a file.
● nano / vim : Text editors for file editing.
1 Display
2
3
4 head
cat
5
less more tail
6
7
8
9
10
11
12
13
14
Tasks

1 [Link]
2
3
4
5
6
7
8
9
10
11
12
Write c++ code with cmake to generate
shared13library and write application
link 14
with the library

You might also like