Executing Commands - Paiet/Tech-Journal-for-Everything GitHub Wiki
- Basic execution
- Command options
ls -l
ls -l -a
ls -la
ls --all
cat /etc/passwd
ls --hide=Desktop
tar -cvf backup.tar /home/dpezet
- Learning more about you
- Finding a command
echo $PATH
- Shell search order
- Aliases
- Shell reserved words
- Function
- Built-in command
-
cd
, exit
, type
, etc
type exit
- Filesystem command
- Command may not be in the path
locate chage
-
chage
sets a password expiration
- Shell history
~/.bash_history
- Arrow keys
-
Ctrl-P
and Ctrl-N
history
!521
!man
!?<string>?
!!
!! <additional args>
-
fc 521 523
- Edits a range of commands in the default editor
- Commands are executed on exit
- Tab autocomplete
- Piping commands
cat /etc/passwd
cat /etc/passwd | sort
-
cat /etc/passwd | sort | less
- Sequential commands
mkdir test ; cd ./test ; touch file.txt ; ls -la ; pwd
- Expanding commands
- One at a time
which dash
chsh -s /bin/dash
- All at once
- Can do arithmetic
echo "I am $[2015 - 1957] years old."
-
echo "There are $(ls | wc -w) files in this directory."
-
wc
is word count
- The math is done outside of the shell
- Shell Variables
echo $USER
set
set | grep USER
- Defining the PATH
- Update in
~/.bashrc
PATH=$PATH:/getstuff/bin ; export PATH
- Aliases
alias p='pwd ; ls --CF'
unalias p
- Configuring the bash shell
- Config files
-
/etc/profile
- Sets up environment for all users
- Run when you log in
-
/etc/bashrc
- Sets up environment for bash
- Runs each time bash launches
- Can be overridden in
~/.bashrc
-
~/.bash_profile
- Sets up environment for a single user
- Prompt
-
$
and #
- Regular users see
$
- Root users see
#
- The prompt is defined in the
$PS1
variable
- Define in
~/.bashrc
to make changes permanent
export PS1="[\t \w]\$ "
- Variables
-
\!
Command history number
-
\#
Command number
-
\$
User promt
-
\w
Full path
-
\W
Current working directory
-
\[
& \]
Non-printing characters
-
\\
Backslash
-
\d
Date
-
\h
Hostname
-
\n
Newline
-
\s
Shell name
-
\t
Time
-
\u
Username
⚠️ **GitHub.com Fallback** ⚠️