mirror of
https://github.com/The-Art-of-Hacking/h4cker.git
synced 2024-10-01 01:25:43 -04:00
2.7 KiB
2.7 KiB
Linux metacharacters
-
;
: Separates commands.command1 ; command2 # Run command1, then run command2 regardless of whether command1 succeeded.
-
&
: Background execution.command & # Runs "command" in the background.
-
&&
: AND operator.command1 && command2 # Run command1, then run command2 only if command1 succeeded.
-
||
: OR operator.command1 || command2 # Run command1, then run command2 only if command1 failed.
-
|
: Pipe operator.command1 | command2 # Output of command1 is passed as input to command2.
-
()
: Command group.(command1; command2) # Group commands into a subshell.
-
{}
: Command block.{ command1; command2; } # Group commands in the current shell.
-
$()
: Command substitution.echo $(command) # Runs "command" and substitutes its output in place.
-
``
(Backticks): Another way of command substitution.echo `command` # Same as above, but this syntax can be harder to spot.
-
>
: Output redirection.command > file # Redirect the output of command to a file, overwriting the file.
-
>>
: Append output.command >> file # Append the output of command to a file.
-
<
: Input redirection.command < file # Use "file" as input for command.
-
2>
: Error redirection.command 2> file # Redirect the error output of command to a file, overwriting the file.
-
2>>
: Append error output.command 2>> file # Append the error output of command to a file.
-
&>
: Redirect all output (stdout and stderr).command &> file # Redirect all output of command to a file, overwriting the file.
-
*
: Wildcard.ls *.txt # List all .txt files.
-
?
: Single character wildcard.ls ?.txt # List all .txt files with a single character name.
-
[]
: Character class.ls [ab]*.txt # List all .txt files starting with 'a' or 'b'.
-
!
: Negation.command1; ! command1 # Execute command1, then execute command1 again only if the first execution failed.
-
#
: Comment.# This is a comment in Bash.
-
\$
: Escape character.echo \$HOME # prints $HOME, not the value of the variable.
-
\"
: Escape character for quotes.echo "This is a \"quote\"" # prints This is a "quote".
Be careful, especially when using redirections, as they can overwrite your files without warning if you're not careful.