TCM Security Academy Notes - by syselement
🏠 Home BlogGitHub📚 Buy Me a Book
  • TCM Security Academy Notes
  • Courses
    • TCM - Linux 101
      • 1. Introduction
        • Linux Distributions
        • Installing Linux
      • 2. Command Line
        • Intro to Command Line
        • Getting help on the Command Line
        • Command Line Arguments and Options
        • Reading Text Files
      • 3. File System
        • Filesystem Hierarchy Standard
        • Devices, Partitions and Mounting
        • Absolute and Relative Paths
        • Files and Directories
        • Paths, Filenames and Text Files
        • Filesystem Links
        • Archiving and Searching Files
      • 4. Users and Groups
        • Working with Users and Groups
        • File and Directory Permissions
        • Changing Users and Passwords
      • 5. Installing Software
        • Package Management
      • 6. Shells
        • Common Command Line Shells
        • Environment Variables & Startup Files
        • Input/Output Redirection
        • Command History & Substitution
      • 7. Utilities and File Editors
        • Searching and Processing Text
        • Networking at the Command Line
        • File Transfer
        • Text Editors and Converters
      • 8. Process Management
        • Process Information
        • Foreground and Background Processes
        • Managing Processes
        • Scheduling Processes
      • 9. Regular Expressions
        • Regular Expressions, Searching, Replacing, Building
      • 10. Bash Scripting
        • Bash Scripting Basics, Control Structures, Loops
      • 🌐Linux101 References
    • TCM - Mobile Application Penetration Testing
      • 1. Introduction & Mobile Pentesting
      • 2. Android Security
      • 3. Android Lab Setup
      • 4. Android Static Analysis
      • 5. Android Dynamic Analysis
      • 6. Android Bug Bounty
      • 7. iOS Security
      • 8. iOS Lab Setup
      • 9. iOS Static Analysis
      • 10. iOS Dynamic Analysis
      • 11. iOS Bug Bounty
      • 🌐MAPT References
    • TCM - Practical Ethical Hacking
      • 1. Introduction & Networking
      • 2. Lab Set Up, Linux & Python
        • Intro to Kali Linux
        • Intro to Python
      • 3. The Ethical Hacker Methodology
        • Information Gathering
        • Scanning & Enumeration
        • Vulnerability Scanning with Nessus
        • Exploitation Basics
        • Capstone Practical Labs
      • 4. Active Directory
        • Active Directory Lab
        • AD - Initial Attack Vectors
        • AD - Post-Compromise Enumeration
        • AD - Post-Compromise Attacks
        • AD - Additional Attacks
        • AD - Case Studies
      • 5. Post Exploitation
      • 6. Web Application
        • Web App Lab Setup
        • Web App - SQL Injection
        • Web App - XSS
        • Web App - Command Injection
        • Web App - Insecure File Upload
        • Web App - Authentication Attacks
        • Web App - XXE
        • Web App - IDOR
        • Web App - Capstone Practical Lab
      • 7. Wireless Attacks
      • 8. Legal Documentation & Report Writing
      • 🌐PEH References
  • 🏠syselement's Blog Home
Powered by GitBook
On this page
  • Command History
  • history
  • Command Substitution

Was this helpful?

Edit on GitHub
  1. Courses
  2. TCM - Linux 101
  3. 6. Shells

Command History & Substitution

Command History

  • To show previously executed commands use the history command

history

history
  865  find / -name 'file1.txt' 2> errors.txt
  866  cat errors.txt 
  867  ll
  868  ls errors.txt 
  869  ll errors.txt 
  870  source .bashrc 
  871  ll errors.txt 
  872  ls -lah errors.txt
# It includes the executed commands and the history number associated to them

history | less

# To execute one of the previous commands use !HISTORY_NUMBER
!868

# To execute the last command use these shortcuts
!-1
!!

# Up & Down arrow keys can be used to scroll through history

# To execute the last "command" command - cat for example
!cat
  • The configuration options of the history are located in the .bashrc file

cat ~/.bashrc
    # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
    HISTSIZE=1000
    HISTFILESIZE=2000

Command Substitution

  • Redirecting doesn't always work.

  • With command substitution a command can be replaced with its output before the entire command is executed by the shell.

  • Backticks `` or $() are used:

ls -l `cat file.txt`
ls -l $(cat file.txt)

# Example with a file list
cat file-list.txt 
    file1.txt
    file2.txt
    file3.txt
ls -l `cat file-list.txt`
    -rw-rw-r-- 1 root root 6 set  3 00:16 file1.txt
    -rw-rw-r-- 1 user user 7 set  3 00:16 file2.txt
    -rw-rw-r-- 1 user user 8 set  3 00:16 file3.txt

PreviousInput/Output RedirectionNext7. Utilities and File Editors

Last updated 2 years ago

Was this helpful?