Skip to content
A brief cheatsheet of useful commands when running scripts on linux
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md

README.md

Running Scripts: A Linux Cheatsheet

When running scripts on Linux, there are a few standard procedures you will likely want to use. I’ve outlined a quick cheat sheet here of some of the standard commands you may want to use.

Script output to files

Using the example command node myscript.js and the output file ~/myscript.log here are some handy commands.

Appending stdout to a file (not to the screen)

node myscript.js >> ~/myscript.log

Appending stdout & stderr to a file (not to the screen)

node myscript.js &>> ~/myscript.log

Appending stdout to a file and the screen

node myscript.js >&1 | tee -a ~/myscript.log

Appending stdout & stderr to a file and the screen

node myscript.js 2>&1 | tee -a ~/myscript.log

Writing stdout to a new file (not to the screen)

node myscript.js > ~/myscript.log

Writing stdout & stderr to a new file (not to the screen)

node myscript.js &> ~/myscript.log

Writing stdout to a new file and the screen

node myscript.js >&1 | tee ~/myscript.log

Writing stdout & stderr to a new file and the screen

node myscript.js 2>&1 | tee ~/myscript.log

Screen

If you’re expecting a script to run for a while, you will want to run it in screen in cases of session disconnections or terminal window closures.

Create a new screen session

screen

List all running screen sessions

screen -ls

Reattaching to your last screen

screen -r

Reattaching to a specific screen

screen -r <session-name>

Detaching from a screen

# from within a screen session

"Ctrl-a” + “d”

Killing a screen session

# from within a screen session

“Ctrl-a” + “k"

Also published at http://tlef.ca/a/scripts/

You can’t perform that action at this time.