If you would like to look at a book I suggest:
www.tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf
Sommaire
HOME
By default your HOME directory is the directory in which you "land" when you log in. The path of this directory is usually:
/home/username
It is also stored in the HOME environment variable (see further down):
echo $HOME
In general there is not much space in your HOME but therefore, at UQAM, a backup of everything you keep under your HOME is done every 3 hours. We also keep daily and weekly backups for up to 4 weeks. You if you ever remove something by accident or if the machine or disk unit crashes, there will still be a copy of everything you had in your HOME.
Therefore, it is strongly suggested that you keep everything which is small and important in your HOME! Like programs, scripts, configuration files.
...
emacs Reference Card (more intuitive)
vi Reference Card (available on all Linux systems)
Special characters
General
/ | Separates directories in a file path, represents the root directory when used at the start of a path |
# | Used to start a comment in Bash |
$ | Used to reference the value of a variable |
; | Allows the execution of multiple commands on the same line |
| Executes the preceding command in the background |
| | "Pipe", passes the output of one command as input to another |
! | Negates the exit status of the command that follows it, also used for history expansion |
\ | Escape character. Nullifies the special meaning of the next character, including the invisible "new line" character |
...
chmod [ who option permission ] file-/directory-name(s)
'who' can be any combination of:
u (user)
g (group)
o (other)
a (all) (i.e. ugo)
'option' adds or takes away permission, and can be:
+ (add permission),
- (remove permission), or
= (set to exactly this permission).
'permission' can be any combination of
r (read)
w (write)
x (execute)
Example: chmod a+x filename - makes filename executable by everyone.
Display a message
echo
echo "message" : displays/prints 'message'.
Examples:
echo Hello
Hello
echo "Hello there"
Hello there
Formatted print
printf : produces output according to a format.
Example:
printf '%3.3d\n' $(( 1 + 15 ))
016
'\n' gives a new line.
For more information check: man 3 printf
Quotes: single vs. double
...
You can evaluate a command and store the answer in a variable.
For example if you want to store the current date in a variable you can use:
current_date=`date`
or the newer method:
current_date=$(date)
echo $current_date
Evaluate a variable
If you have a variable which contains a command you can evaluate (execute) this command with 'eval':
Arithmetic
year=2013
next_year=$(( year + 1 ))
or
(( next_year = year + 1 ))
echo $next_year
2014
% : modulo / remainder
echo $(( 10 % 3 ))
1
Just be careful and never try arithmetic operations on numbers starting with a zero!!!
Formatted print
printf : produces output according to a format.
Example:
printf '%3.3d\n' $(( 1 + 15 ))
016
'\n' gives a new line.
For more information check: man 3 printf
History
history : lists the most recent commands
...