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
  • Spaces in filenames
  • File and Path Expansion
  • Text Files Commands
  • head
  • tail
  • diff

Was this helpful?

Edit on GitHub
  1. Courses
  2. TCM - Linux 101
  3. 3. File System

Paths, Filenames and Text Files

Spaces in filenames

📌 Use TAB for auto-completion.

ls
	'file name.txt'
# Single quotes are displayed to make sure "file name.txt" is one entry

cat file name.txt
	cat: file: No such file or directory
	cat: name.txt: No such file or directory
# Bash shell uses spaces between commands arguments
  • Best pratice: do not use spaces in file names as word separators.

  • There are two ways to tell bash the space is part of the name:

    • Escape the name with a \ (treat the space as part of the argument).

    • Place the entire name in double quotes (do not interpret any special character inside the quotes).

cat file\ name.txt
	Hello Paths!
# TAB on keyboard can also be used for auto completion.

cat "file name.txt" 
	Hello Paths!

File and Path Expansion

  • Directories and files in a path are separated by a slash /.

  • Everything in between separators is called a segment.

  • The most used wildcard is the asterisk *.

ls file*.txt
# List the current directory text files that start with the string "file"

ls file?.txt
# List the text files that start with the string "file" and have another character after that.
# ? wildcard = any single character on the command line

ls **/*.txt
# Use ** to search accross multiple segments. ** matches zero or more characters accross multiple directories.
  • [ ] indicate very specific character to match.

ls file[123].txt
ls file[1-3].txt
ls file[a-zA-Z].txt

# Only match files that start with the string "file" and another specific character after.

Text Files Commands

head

  • head - by default print the first 10 lines of each file

    • Use -n option to specify the lines to display (or -NUMBER)

head words.txt 
	# One
	# Two
	# Three
	# Four
	# Five
	# Six
	# Seven
	# Eight
	# Nine
	# Ten
	
head -n 3 words.txt 
	# One
	# Two
	# Three
	
head -15 words.txt 
	# One
	# Two
	# Three
	# Four
	# Five
	# Six
	# Seven
	# Eight
	# Nine
	# Ten
	# 
	# Alfa
	# Bravo
	# Charlie
	# Delta

tail

  • tail - by default print the last 10 lines of each file

    • Use -n option to specify the lines to display (or +NUMBER)

tail words.txt 
	# Delta
	# Echo
	# Foxtrot
	# Golf
	# Hotel
	# India
	# Juliett
	# Kilo
	# Lima
	# Mike
	
tail -n 3 words.txt 
	# Kilo
	# Lima
	# Mike
	
tail -4 words.txt 
	# Juliett
	# Kilo
	# Lima
	# Mike
  • tail command can be used to monitor the end of a file (a log) for changes.

tail --help
	-f, --follow[={name|descriptor}]
                           output appended data as the file grows;
                             an absent option argument means 'descriptor'
                             
tail -f /var/log/auth.log

diff

  • diff - compare files line by line and displays any differences

diff words.txt words2.txt 
	
	2c2
	< Two
	---
	> 
	4c4
	< Four
	---
	> 
	6c6
	< Six
	---
	> 
	8c8
	< Eight
	---
	> 
	13c13
	< Bravo

PreviousFiles and DirectoriesNextFilesystem Links

Last updated 2 years ago

Was this helpful?