fc
to Edit and Run an Old CommandI have posted Homework 9 here.
As usual, it will be due next Sunday at 11:59 PM.
I have posted the answers to Quiz 7 here.
Are there any questions before I begin?
ps
only shows you the processes running in your current shellps -u
ps -u root
ps -aux
will show all running processes$ cat print_positionals.sh #!/bin/bash # # Prints the value of the first four positional arguments echo echo 0: $0 echo 1: $1 echo 2: $2 echo 3: $3 $ ./print_positionals.sh foo bar bletch 0: ./print_positionals.sh 1: foo 2: bar 3: bletch
$ cat print_arg_numbers.sh #!/bin/bash # # Prints the number of arguments sent to this script echo echo This script received $# arguments $ ./print_arg_numbers.sh foo bar bletch This script received 3 arguments
$ name=Glenn Hoffman
Hoffman: command not found
$ team="Red Sox" echo $team Red Sox $ cheer='Go $team' $ echo $cheer Go $team
$ cheer="Go $team" $ echo $cheer Go Red Sox
init
or systemd
init
or systemd
has PID (Process ID) of 1 ...ps -f
displays a full listing of information about each
process ...
$ ps -f UID PID PPID C STIME TTY TIME CMD it244gh 26374 26373 0 13:41 pts/5 00:00:00 -bash it244gh 27891 26374 0 13:57 pts/5 00:00:00 ps -f
history
command
$ history 2 exit 3 cd 4 cd it244/work 5 pwd 6 rm -rf * 7 cd ~/it244/work 8 pwd 9 cp ~ghoffman/examples_it244/bother.sh . 10 ls /home/ghoffman/examples_it244 11 cp ~ghoffman/examples_it244/bother.sh . 12 ./bother.sh 13 ./bother.sh & 14 jobs ....
history
without an argument shows the entire listhistory
followed by a number
$ history 10 498 ps 499 exit 500 exit 501 history 502 cd 503 cd it244 504 cd work 505 ls 506 history 507 history 10
head
or tail
File | Contents |
---|---|
HISTFILE | The location of the file that records the command history. The default is ~/.bash_history |
HISTSIZE | The maximum number of command lines saved in the RAM list during a given session |
HISTFILESIZE | The maximum number of command lines saved in the file specified by HISTFILE, after you quit |
$ echo HISTFILE: $HISTFILE; echo HISTSIZE: $HISTSIZE; echo HISTFILESIZE: $HISTFILESIZE
HISTFILE: /home/it244gh/.bash_history
HISTSIZE: 500
HISTFILESIZE: 500
List | Location | Value |
---|---|---|
File list | ~/.bash_history | $HISTFILESIZE |
Memory list | RAM | $HISTSIZE |
history
$ history 5
515 cd ~ghoffman/examples_it244/
516 pwd
517 echo $PATH
518 cd
519 history 5
$ !517
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
$ ! 517
517: command not found
$ !e
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
fc
to Edit and Run an Old Commandfc
(fix command) allows you
to edit a previous command line ...
fc
is a built-in so it executes quicklyfc
will open up an editor window ... fc
fc
with an event number ...fc
can also be used to view the history listfc
will list the last 16 command lines
$ fc -l
511 ls
512 cd
513 ls
514 history 5
515 cd ~ghoffman/examples_it244/
516 pwd
517 echo $PATH
518 cd
519 history 5
520 echo $PATH
521 ! 517
522 echo $PATH
523 traceroute -a standford.edu
524 echo $PATH
525 echo $PATH
526 echo $PATH
fc
to list all events ...fc -l
...
$ fc -l 522
522 echo $PATH
523 traceroute -a standford.edu
524 echo $PATH
525 echo $PATH
526 echo $PATH
527 fc -l
fc -l
list a range of events ...fc -l
with two numbers
$ fc -l 522 525
522 echo $PATH
523 traceroute -a standford.edu
524 echo $PATH
525 echo $PATH
fc -l
with two strings ...$ history 10 521 ! 517 522 echo $PATH 523 traceroute -a standford.edu 524 echo $PATH 525 echo $PATH 526 echo $PATH 527 fc -l 528 fc -l 521 529 fc -l 522 525 530 history 10 $ fc -l t f 523 traceroute -a standford.edu 524 echo $PATH 525 echo $PATH 526 echo $PATH 527 fc -l 528 fc -l 521 529 fc -l 522 525
fc
?history
to get the event
number ...
fc
and that numberemacs
modevi
modeCommand | Meaning |
---|---|
Control A | Move to the beginning of the line |
Control E | Move to the end of the line |
Control U | Remove everything from the text entry point to the beginning of the line |
Control K | Remove everything from the text entry point to the end of the line |
← | Move the text entry point one character to the left |
→ | Move the text entry point one character to the right |
↑ | Recall the previous command line entry in the history list |
↓ | Recall the following command line entry in the history list |
set -o vi
$ ls hw1 hw10 hw11 hw2 hw3 hw4 hw5 hw6 hw7 hw8 hw9 $ ls hw[Tab][Tab] hw1/ hw10/ hw11/ hw2/ hw3/ hw4/ hw5/ hw6/ hw7/ hw8/ hw9/
$ e[Tab][Tab]
e2freefrag elfedit esac
e2fsck elif etags
e2image else etags.emacs23
e2label emacs ethtool
e2undo emacs23 eval
e4defrag emacs23-x ex
ebrowse emacsclient exec
ebrowse.emacs23 emacsclient.emacs23 exit
echo enable expand
ed enc2xs expiry
edit env export
editor envsubst expr
editres eqn extcheck
egrep erb
eject erb1.8
$ ass[Tab]
$ bar=BLETCH
$ echo $b[Tab]
BLETCH
ls -l
is quite a few characters to typealias ll='ls -l'
ls -l
$ ll total 45 -rwxr-xr-x 1 ghoffman grad 38 Oct 11 20:05 border.sh -rwxr-xr-x 1 ghoffman grad 135 Oct 16 08:35 bother.sh -rwxr-xr-x 1 ghoffman grad 13 Oct 29 14:23 cheer.sh -rwxr-xr-x 1 ghoffman grad 103 Oct 9 08:53 command_name.sh -rwxr-xr-x 1 ghoffman grad 99 Oct 29 16:15 comment_test.sh ...
alias
command ...
alias ALIAS_NAME=COMMAND
alias la='ls -a'
alias
with no arguments ...$ alias alias bin="pu $bin' alias binl="ls $bin' alias ck755="ls -l *.sh | tr '\''-'\'' '\'' '\'' | grep '\''rwxr xr x'\''' alias ckhb="head -1 *.sh | grep /bin/bash' alias cl="pu $cl' alias clhws="pu $clhws' alias clhwsl="ls $clhws' alias cll="ls $cl' alias clr="clear' ...
alias
with the alias name
$ alias ll alias ll='ls -l'
ll /home/ghoffman
ls -l /home/ghoffman
ls -l DIRECTORY_NAME | head
alias llh="ls -l $1 | grep txt"
$alias ll='ls -l'
$ bash
$ ll
ll: command not found
alias
command is a built-in
$ type alias alias is a shell builtin
$ name="Glenn Hoffman' $ echo $name Glenn Hoffman
$ echo 'My name is $name' My name is $name
$ echo "My name is $name" My name is Glenn Hoffman
$ alias la="ls -a' $ la . .addressbook .bash_profile .cshrc .login .pinerc .. .bash_history .cache it244 .msgsrc .ssh
$ alias ltr alias ltr="ls -ltr' $ ltr ~/bin/shell total 4 -rwxr-xr-x 1 ghoffman grad 107 Oct 13 09:42 border.sh -rwxr-xr-x 1 ghoffman grad 339 Oct 13 09:42 homework_setup.sh -rwxr-xr-x 1 ghoffman grad 306 Oct 14 00:18 homework_copy.sh -rwxr-xr-x 1 ghoffman grad 156 Nov 5 17:09 step.sh
export lncd=/courses/it244/s19/ghoffman export lntst=/home/ghoffman/code/it244_code/testing_scripts_it244 export lnwb=/home/ghoffman/public_html/it244_html
alias lncd='pu $lncd' alias lntst='pu $lntst' alias lnwb='pu $lnwb'
ls
on the directory
alias lncdl='ls $lncd' alias lntstl='ls $lntst' alias lnwbl='ls $lnwb'
pu
is a function which I will describe belowssh ghoffman@pe15.cs.umb.edu
pe15
$ alias pe15 alias pe15='ssh ghoffman@pe15.cs.umb.edu'
FUNCTION_NAME ()
{
COMMAND
COMMAND
...
}
$ whoson () > { > date > finger | grep 'pts/'$1 > } $ whoson 14 Sun Nov 10 20:18:33 EST 2013 thamerfa Thamer AlTuwaiyan pts/14 2 Nov 10 18:44 (c-174-63-86-44.hsd1.ma.comcast.net)
$ echo3 () { echo $1; echo $1; echo $1;} $ echo3 foo foo foo foo
function
$ function cheer ()
> {
> echo Go $1'!'
> }
$ cheer 'Red Sox'
Go Red Sox!
function
is not a command
$ type function function is a shell keyword
$ print_args () > { > echo "arg1: $1" > echo "arg2: $2" > } $ print_args foo bar arg1: foo arg2: bar
type
commandcd
$ type pu
pu is a function
pu ()
{
echo;
pushd $1 > /dev/null;
ls --color=auto
}
$ pwd
/home/it244gh
$ pu ~ghoffman
bin issues omar
bugs it114 public_html
code it116 stdwrk
course_files it116_test submitted
course_materials it117 tests_taken
course_scoring_documents it117_test tmp
demos it244 wrk
flask it244_test xrchiv
html mail
hw1_piazza_filename_create.py messages
$ pwd
/home/ghoffman
pushd
pushd
prints the directory stackls
so I can see the contents of my new directorypu
as the function name because it is shorter than "push"pu
the directory stack keeps a record of my last directorypo
po
does not require an argumentpo
is an alias
$ alias po
alias po="popd > /dev/null; echo; ls'
popd
to return to the previous directoryunset
command
$ cheer 'Red Sox' Go Red Sox! $ unset cheer $ cheer cheer: command not found
source ~/.bash_profile