Linux Tips
Shell Tips
- End a text program
that is hanging (i.e. in an infinite loop)
Press ctrl-c (with the correct terminal in the foreground). This can
often, but not always be used to escape from interactive programs as
well.
- End a misbehaving
graphical program
Use ps
to find its process id (also printed in
terminal when programs started), then kill [
PROCESS ID
]
. Despite the name,
this asks the program nicely to end. If it doesn't work, try kill
-9 [PROCESS ID]
which forces it to end.
- Run a graphical
programs from the command line
Add an ampersand (&) at the end of the command to fork
the process (run the program in a new process).
$ PROGRAM [OPTIONS] [I/O REDIRECTION] &
I you do this, you can
press enter to get a prompt and continue using the terminal. If you
don't, the prompt won't return until you close the program or enter
ctrl-c, and closing the terminal also kills the graphical program.
- Take advantage of the
command history
Press the up key to recover the most recent command. Use up and down
to scroll through the entire history.
- Take advantage of
auto-completion
When entering a command name or filepath, type just the first few
characters and press tab to have the shell attempt to complete it. If
there are multiple possibilities, the shell will display them. Type a
few more characters and press tab again, repeating as necessary. Once
you get the hang of it, this makes dealing with long path names much
easier.
Useful Text Programs
- mail -- send text via email
- Text body only, from a file:
$ mail ADDRESS -s "
SUBJECT
" <
TEXT_FILE
- Short text body only:
$ echo "EMAIL BODY" | mail ADDRESS -s "SUBJECT"
- mutt -- send attachments via email
- Short body plus attachment:
$ echo "
EMAIL BODY
" | mutt ADDRESS
-s "
SUBJECT
" -a ATTACHMENT
Shell Configuration
- Create aliases for common commands.
Edit the ".aliases" file in your home directory. Follow the format used
for the existing aliases.
- Enable file/folder coloring with "ls"
Edit the ".aliases" file and add the following entry to the top (before
any commands that use "ls"):
$ alias ls 'ls --color=auto'
This makes navigation somewhat easier.
See Also
Last updated 12/22/12