Linux Command Line Tools - Paiet/Tech-Journal-for-Everything GitHub Wiki
- Command-Line Basics
- Exploring Your Linux Shell
- Bourne Again Shell (
bash
)- Based on the Unix Bourne shell (
sh
) bash
is the default shell in most Linux systems
- Based on the Unix Bourne shell (
csh
or the C Shell utilizes a syntax that is liken to the C programming languagetcsh
based off ofcsh
- More
bash
-like but still different - The T stands for TENEX. An OS that inspired the author of
tcsh
- More
- There are 2 types of default shells
- Default Interactive Shell
- The shell that the user works with to enter commands
- Default System Shell
- The shell that they system uses to run startup scripts
- Typically the file
/bin/sh
points to the default system shell- Usually
/bin/bash
in Linux - Points to
/bin/dash
in Ubuntu
- Usually
- Default Interactive Shell
- Bourne Again Shell (
- Using a Shell
- Starting a shell
- Linux can drop you straight to a shell after startup
- In a GUI environment you can start a terminal emulator
- XTERM, Konsole, Terminal, gnome-terminal
uname -a
returns all the system information
- Internal vs. External Commands
- Internal commands are built-in to the shell
- External commands are programs that run in the shell but aren't native to the shell
- Internal command examples
cd
Change Directorycd ~/sally
is the same ascd /home/sally
pwd
Print Working Directoryecho
prints a string of textecho Hello
- Useful when writing scripts and checking the content of environmental variables
exit
terminates any shelllogout
terminates only login shells
- You can find out whether a command is internal or external by using the
type
commandtype pwd
type cd
type bash
type -a
will display different programs that use the same nametype -a cd
type -a pwd
- Shell tricks and tips
- Auto-complete commands with Tab
history
shows list of previously used commands, usually the last 500!!
lists and executes the last command!210
lists and executes command #210 in the listhistory -c
clears the history- The history is stored in
~/.bash_history
- Ctrl+P/Up arrow Ctrl+N/Down arrow scrolls through recently used commands
- Ctrl+R performs a reverse search of commands
- Ctrl+S performs a forward search of commands
- Ctrl+G quits the search
- Ctrl+A moves the cursor to the start of the line
- Ctrl+E moves the cursor to the end of the line
- Ctrl+Left or Right arrow keys move the cursor backward or forward a word at a time
- Esc+B/F performs the same action
- Ctrl+K deletes from the cursor to the end of the line
- Ctrl+X+Backspace deletes text from cursor to the beginning of the line
- Ctrl+T transpose the character before the cursor with the character under the cursor
- Esc+T transposes the word
- Ctrl+X+Ctrl+E quick launches the default text editor
- Starting a shell
- Exploring Shell Configuration
- Shell configuration files are just plain text shell scripts
~/.bashrc
and/etc/profile
- Make necessary changes to these files
$PATH
add directories to search for executables
- Shell configuration files are just plain text shell scripts
- Using Environment Variables
- Variables are containers for data
- System Variables and User-Created Variables
$TERM
- Exploring Your Linux Shell
Begin
$> PS1="My New Prompt$>"
My New Prompt$> export PS1
My New Prompt$> export PS1="Prompt$>"
Prompt$> echo $PS1
-
Using Environment Variables
env
lists all environmental variablesunset
removes the data from the variable
-
Getting Help
man
for the manual of a programman man
to learn to useman
man -k
will perform a lookupman -k "system information"
man
is divided into 9 sections- Some commands can reside in multiple sections
passwd
resides in both sections 1 and 5man
defaults to the lowest numbered sectionman 5 passwd
will return the manual for section 5's entry for thepasswd
command
- Some commands can reside in multiple sections
info
is likeman
but uses hypertext and has some internal options for navigating the manualhelp
usually gives a succinct synopsis of use for built-in commands