Bash Shell Stuff

File & Ditectory shortcuts

Current user’s home directory:
~/

Current directory:
./

Parent directory:
../

Two parent directories up:
../../

All files in target directory. (Be very careful.):
/*

Redirect Output

Redirect output of one command into the input of another with a pipe:
command_1 | command_2

Search through output of a command for phrase:
command | grep phrase

Redirect output to a file:
command > file

tee works like |, but it writes output to both target and terminal:
tee target

Redirect standard output and error to /dev/null, where it is deleted.
command > /dev/null 2>&1

Wait until command 1 is finished to execute command 2
command_1 ; command_2

&& acts like ; but only executes command_2 if command_1 indicates that it succeeded without error by returning 0.
command_1 && command_2

|| acts like && but only executes command_2 if command_1 indicates an error by returning 1.
command_1 || command_2

Wildcards:
Zero or more characters:
*

Matches “phrase” and any number of trailing characters:
phrase*

Matches any incidences of “phrase” with any trailing or leading chars:
*phrase*

Matches any one char:
?

Matches any of the characters listed inside brackets:
[chars]

Matches a range of chars between a-z:
[a-z]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: