πŸ‘¨β€πŸ’»
Jawad's Notes
  • πŸ‘¨β€πŸ«INFOSEC
    • πŸ•ΈοΈWeb
      • Burp Suite: Setting Foxyproxy
      • XSS
      • Wappalyzer
      • Directory Traversal
      • LFI
        • PHP Wrappers
        • RFI
      • Reverse Shell
        • Command Injection Quick Tips
      • File Upload
      • WPScan
      • SQL Injection
        • Schemas
        • SQLmap
        • MSSQL
        • MySQL
        • PostgreSQL
    • πŸ”§Tools
      • Whois
      • DNSRecon
      • DNSenum
      • nslookup
      • Netcat
        • Powercat
      • Nmap
        • Nmap Scripting Engine
        • Test-NetConnection
        • Grep
      • Server Message Block (SMB)
      • SNMP
      • SMTP
      • ExifTool
      • Search Engine Hacking
      • Source Control Hacking
      • Nessus
      • Canarytokens
      • Qualys SSL Server Test
      • Security Headers
      • theHarvester
      • Shodan
      • Gobuster
        • Dirb
      • Searchsploit
      • Password Cracking
        • Hashcat
        • John The Ripper
        • Hydra
        • hashID
        • CPU vs GPU
    • 🐧Linux
      • Symbols
      • cat
      • curl
      • openvpn
      • tcpdump
      • Remote Desktop
      • SmbShare
      • Tmux
      • Convert Windows-style line endings (CRLF) to Unix-style (LF)
      • SSH
    • πŸ–₯️Macros in Office
    • 🍎Enhancing Your MacOS Terminal Experience
    • 🚩CTF
      • SQL Injection
        • WHERE clause allowing retrieval of hidden data
        • Allowing login bypass
        • UNION attack, determining the number of columns returned by the query
        • UNION attack, finding a column containing text
        • UNION attack, retrieving data from other tables
        • UNION attack, retrieving multiple values in a single column
        • Querying the database type and version on Oracle
Powered by GitBook
On this page
  • The > symbol in Linux command line
  • The | symbol, known as a pipe
  • The & symbol
  • && (AND)
  1. INFOSEC
  2. Linux

Symbols

The > symbol in Linux command line

is used for redirection. Specifically, it is used to redirect the output of a command to a file, overwriting the existing contents of the file. This allows you to save the output of a command to a file instead of displaying it on the screen. For example, if you have a command that generates some output and you want to save this output to a file, you can use the > operator followed by the name of the file where you want to save the output.

Here's a simple example:

echo "Hello, world!" > myfile.txt

This command will redirect the output of the echo command (which is "Hello, world!") into a file named myfile.txt. If myfile.txt does not exist, it will be created; if it does exist, its existing contents will be overwritten without warning.

To append the output of a command to a file instead of overwriting it, you would use >> instead of >. This appends the output to the end of the file, preserving its existing contents.

Example:

echo "Another line." >> myfile.txt

This command adds "Another line." to the end of myfile.txt, preserving whatever content was already there.

The | symbol, known as a pipe

is used for a different kind of redirection compared to >. While > is used to redirect output to a file, | is used to pass the output of one command as input to another command. This enables the chaining of commands, allowing for more complex operations and data processing workflows.

Here's a basic example to illustrate the difference:

  • Using > to redirect output to a file:

    ls > list_of_files.txt

    This command lists the contents of the current directory and redirects the output to a file named list_of_files.txt, overwriting its contents if it exists.

  • Using | to pass output to another command:

    ls | grep "txt"

    This command lists the contents of the current directory and then passes the output to the grep command, which filters the output to only show files that contain "txt" in their names.

The pipe | is powerful because it lets you combine multiple commands in a way that the output of one command becomes the input of the next command. It's a fundamental part of the Unix philosophy of building small, modular tools that do one thing well and connecting them together to perform complex tasks.

So, while > is great for saving output to files, | is indispensable for creating efficient pipelines that process data in stages. Each serves a distinct purpose, and which one you use depends on the task you're trying to accomplish.

The & symbol

is used to run a command in the background. When you append & to a command, it tells the shell to execute the command asynchronously, allowing you to continue using the terminal for other tasks while the command runs. This is particularly useful for running processes that take a long time to complete or when you want to keep a process running without blocking your terminal session.

How it works

When you execute a command followed by &, the shell starts the command as a background job. The shell immediately returns the control to the user, displaying a job ID and a process ID associated with the background task. You can then proceed with other commands while the background job continues to run.

Example

sleep 30 &

This command will start the sleep command, which pauses for 30 seconds, in the background. Instead of your terminal being tied up for 30 seconds, you'll get a prompt back immediately, allowing you to continue working.

Managing Background Jobs

You can manage background jobs using various commands:

  • jobs lists all jobs running in the background of the current shell session, showing their job IDs.

  • fg %jobid brings a background job to the foreground, making it the current job. Replace jobid with the actual job ID.

  • bg %jobid continues running a job in the background if it was stopped. Replace jobid with the actual job ID.

  • kill %jobid sends a signal to a background job, typically to terminate it. Replace jobid with the actual job ID.

Using & for background execution is a fundamental aspect of multitasking in shell environments, allowing users to efficiently run multiple processes simultaneously.

&& (AND)

operator is used to execute commands conditionally. It runs the second command only if the first command succeeds (i.e., exits with a status of 0, indicating success). This allows you to chain commands together conditionally, ensuring that each command in the sequence is executed only if the preceding command was successful.

Example: cd /directory && ls changes the current directory to /directory and then lists its contents, but only if the cd command is successful (meaning the directory exists and you have permission to access it).

PreviousLinuxNextcat

Last updated 1 year ago

πŸ‘¨β€πŸ«
🐧