`~$ cp access.log log2 &` - "&" allows you to run commands in the background of the terminal. Copy large file and do other stuff in terminal as it goes. `~$ command1 && command2` - "&&" allows you to combine multiple commands together in one line of your terminal - command 2 will only run if command 1 is successful `~$ echo password:1234 > logins.txt` - ">" redirects the output of a command to another file, it overwrites ==WHOLE== file - in this case the output of echo is being sent to logins.txt <!--SR:!2023-04-08,4,270--> `~$ echo password:1234 >> logins.txt` - ">>" same usage as above however the output will not over write the file instead it will add it to the bottom - useful for logging information # Chain Commands `|` (pipe) - the output of the first command becomes the input of the second command `;` (semicolon) - placed between commands, they are run in sequence whether the previous command completed successfully or not `&&` (logical AND) - following command only runs if previous command was successful `||` (logcal OR) - following command only runs if previous command fails `!` (bang) - negates an expression # Redirection std**in** - standard input method, usually keyboard - file handler 0> std**out** - standard output method, usually the display - file handler 1> std**err** - standard output method for errors, usually the display - file handler 2> you can prove by: `curl -I http://google.com 2>/dev/null | grep HTTP` - the status (stderr) will be sent to null and grep will output only the http version ### Redirection Operators `>` Redirects stand output to a file - will overwrite existing information in the file `>>` Redirects standard output to a file - appends (adds) to existing file `<` Redirects input from a file to a command # xargs Commands Reads the input and executes a given command for each argument provided. This is useful for running commands on a series of files For example: - `find /foo -type f -name "*.pdf" | xargs rm"` - finds PDF files in the /foo directory and executes the rm command on each one. - only time you use, is when the command output is multiline and you want to for example wordcount each file links: [[_LinuxTerminalCMDIndex]] tags: #linux #terminal #CMD