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) bashis the default shell in most Linux systems
- Based on the Unix Bourne shell (
cshor the C Shell utilizes a syntax that is liken to the C programming languagetcshbased 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/shpoints to the default system shell- Usually
/bin/bashin Linux - Points to
/bin/dashin 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 -areturns 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
cdChange Directorycd ~/sallyis the same ascd /home/sally
pwdPrint Working Directoryechoprints a string of textecho Hello- Useful when writing scripts and checking the content of environmental variables
exitterminates any shelllogoutterminates only login shells
- You can find out whether a command is internal or external by using the
typecommandtype pwdtype cdtype bash
type -awill display different programs that use the same nametype -a cdtype -a pwd
- Shell tricks and tips
- Auto-complete commands with Tab
historyshows list of previously used commands, usually the last 500!!lists and executes the last command!210lists and executes command #210 in the listhistory -cclears 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
~/.bashrcand/etc/profile- Make necessary changes to these files
$PATHadd 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
envlists all environmental variablesunsetremoves the data from the variable
-
Getting Help
manfor the manual of a programman manto learn to usemanman -kwill perform a lookupman -k "system information"
manis divided into 9 sections- Some commands can reside in multiple sections
passwdresides in both sections 1 and 5mandefaults to the lowest numbered sectionman 5 passwdwill return the manual for section 5's entry for thepasswdcommand
- Some commands can reside in multiple sections
infois likemanbut uses hypertext and has some internal options for navigating the manualhelpusually gives a succinct synopsis of use for built-in commands