[Day 4] 1. Few more Commands
Types of Commands in Linux
1. Internal Commands
- Definition: Commands implemented within the shell program itself.
- Executable File: Not available on the disk.
2. External Commands
- Definition: Commands implemented separately from the shell.
- Executable Locations: Found on the hard disk in directories such as ,
/bin,/sbin, and/usr/bin./usr/sbin
Command Types and Tools
-
Command: Checks if a command is internal or external.
type- Examples:
- →
type echoecho is a shell builtin - →
type mkdirmkdir is /usr/bin/mkdir - →
type cdcd is a shell builtin
- Examples:
-
Command: Provides the path of a given command (location on the hard disk).
which- Examples:
- →
which ls/usr/bin/ls - →
which cd/usr/bin/cd - →
which echo/usr/bin/echo - →
which pwd/usr/bin/pwd - →
which mkdir/usr/bin/mkdir
- Examples:
-
Command: Gives the path of the command and its manual page.
whereis- Examples:
- →
whereis lsls: /usr/bin/ls /usr/share/man/man1/ls.1.gz - →
whereis cdcd: - →
whereis aliasalias:
- Examples:
File Handling in Shell
-
Internal commands are executed inside the shell only.
-
The shell deals with text files and not special files like PDFs.
-
Command:
open- Use to open files based on their paths. It checks the file's magic number and opens the appropriate application.
- Example: Opening a PDF file will launch a PDF viewer.
Tools for Executable Files
- : Displays detailed information from ELF (Executable and Linkable Format) files, such as headers, sections, and symbols.
readelf - : Offers broader functionality, including disassembling code and showing headers, sections, and symbol tables for various binary formats.
objdump
Manual Pages
- Use to access manual entries for commands.
man- Example: returns "No manual entry for alias" because it's built-in.
man alias - Instead, use for bash-related commands.
man bash
- Example:
Command Execution
-
Synchronous Execution: Commands execute one after the other, with the shell waiting for the current command to finish before proceeding.
-
Asynchronous Execution: Commands execute in the background, allowing immediate execution of other commands. This is done using
at the end of the command.&- Example:
cat & - Check status with command.
ps - Use command to stop background processes.
kill- : Lists signals (64 in total, each with a predefined meaning).
kill -l - Examples of killing a process:
- (using PID)
kill -9 5480 kill -SIGKILL 5480- (can kill multiple processes)
pkill -9 cat
- Example:
Logical Operators
-
(AND Operator):
&&- Nest commands; the second command executes only if the first is successful.
- Example:
ls && pwd - If the first command fails (e.g., ), the second won't execute.
ls -W
-
(Separator):
;- Executes the second command regardless of the first command's success or failure.
-
(OR Operator):
||- The second command executes only if the first fails.
- Example:
ls || pwd - If generates an error, the error is displayed, and the second command executes.
ls -W
Read Next
[Day 4] 3. Types of Operating System
### **Resident Monitors** !3. Resident Monitors.png - **Input Method:** Code was written using a typewriter-like device on punch cards. - **Pro...
[Day 4] 4. Grep (GNU Regular Expression Parser)
#### **Regular Expression / Pattern** - **Definition:** A collection/set/combination of characters used for searching or matching purposes....