...
Syntax of a shell command
command-name [ -option(s) filename(s) or arguments ]
Everything in square brackets [] is optional.
Example: ls -l filename
...
ls -l -t -r
is the same as
ls -lrt
In case you have a file name or an argument starting with a '-' you can use '--'. The command will NOT interpret anything following a '--' as an option/key.
For example if you are using 'grep' to look for '-a' in a file you could type:
$ grep -iw -- -a filename
For more detailed explanations about Program Argument Syntax Conventions, please click on the here.
Documentation of specific commands - man & whatis
whatis command - displays a one-line summary about command
man command - displays on-line manual pages about command
'man' can be use on almost all of the shell commands listed below to get the complete description of the command.
To quit 'man' press 'q'.
Shell commands are case sensitive
Type commands exactly as shown; most shell commands are lower case. File and directory names can be lower, upper, or mixed case but must be typed exactly as listed.
Most important shell commands
...
> | Redirects the output of a command to a file, overwriting the file if it exists |
>> | Redirects the output of a command to a file, appending to the file if it exists |
< | Redirects input from a file to a command |
<< | Redirects a string into the standard input of a command |
Wild cards
Wildcards
Wildcards are "place holder" for one or many characters. A number of characters are interpreted by shell before any other action takes place. These characters are known as wildcard characters. Usually these characters are used in place of filenames or directory names.
* | An asterisk matches any number of characters in a filename, including none. |
? | The question mark matches any single character. |
[ ] | Brackets enclose a set of characters, any one of which may match a single character at that position. |
- | A hyphen used within [ ] denotes a range of characters. |
^ | Negates the sense of a match |
~ | A tilde at the beginning of a word expands to the name of your home directory. If you append another user's login name to the character, it refers to that user's home directory. |
Here are some examples for the usage of wild cardswildcards:
- cat c* : displays any file whose name begins with c including the file c, if it exists.
- ls *.c : lists all files that have a .c extension.
- cp ../rmt? . : copies every file in the parent directory that is four characters long and begins with rmt to the working directory. (The names will remain the same.)
- ls rmt[34567] : lists every file that begins with rmt and has a 3, 4, 5, 6, or 7 at the end.
- ls rmt[3-7] : does exactly the same thing as the previous example.
- ls ~ : lists your home directory.
- ls ~username : lists the home directory of the guy with the user name username.
...
Remove patterns from string
# | removes minimal matching prefixes |
## | removes maximal matching prefixes |
% | removes minimal matching suffixes |
%% | removes maximal matching suffixes |
:s:n | get 'n' characters starting from position 's' (first position is 0) |
Look at these examples and you will understand the meaning of the above:
string="ABC_abc_123"
echo ${string#*_}
abc_123 => removes everything before first occurance of '_'
echo ${string##*_}
123 => removes everything before last occurance of '_'
echo ${string%_*}
ABC_abc => removes everything after last occurance of '_'
echo ${string%%_*}
ABC => removes everything after first occurance of '_'
echo ${string:s:n}
abc => gets n characters, starting from position s
...
-e | select all processes |
-f | do full-format listing |
-u userlist | this selects the processes whose effective user name or ID is in userlist |
Try for example:
ps -fu $USER
Since the lines can get pretty long you can also pipe the output into less to see the full lines, for example:
ps -fu $USER | less
Also have a look at the 'STIME' to see how old the processes are.
If ever you need to kill one of these jobs you can use 'kill' followed by the process ID, 'PID' (second column).
If a normal 'kill' does not work try 'kill -9' followed by the 'PID'.:
kill -9 PID