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.
ps
only shows you your processes ...ps
will not show you them ...-U
option ...ps -U root
ps
with the -aux options-U
option allows you to see all processes running o$ 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
$ team="Red Sox' echo $team Red Sox $ cheer='Go $team' $ echo $cheer Go $team
$ cheer="Go $team" $ echo $cheer Go Red Sox
unset
command
$ echo $foo
FOO
$ unset foo
$ echo $foo
$
$ echo $foo
FOO
$ foo=
$ echo $foo
$
init
or systemd
...init
or systemd
has PID (Process ID) of 1 ...ps -f
displays a full listing of information about each process running for the current user
$ 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 ...history
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 a list in RAM 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 | Size |
---|---|---|
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 ...fc
will bring up an editor window ...fc
with an event number ...fc
editor ...fc
will try to execute whatever you have left in the windowfc
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 command lines ...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 eventsfc -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
emacs
modevim
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 |
$ ls hw[Tab][Tab]
hw2/ hw4/ hw5/ hw6/
$ 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
$ bar=BLETCH
$ echo $b[Tab]ar
BLETCH
$ foo1=FOO; foo2=BAR
$ echo $foo[Tab][Tab]
$foo1 $foo2
ls -l
is quite a few charactersalias 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
commandalias
uses the following format in Bash
alias ALIAS_NAME=ALIAS_VALUE
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 name of an alias ...$ 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'
bash
can consist of many commands ...alias foo="foo foo foo'
$ alias foo="echo foo' $ foo foo $ alias foo="foo foo foo' $ foo foo: command not found
$alias ll="ls -l'
$ bash
$ ll
ll: command not found
alias
command is a built-in
$ type alias alias is a shell builtin
alias
were not a built-in ...alias
command ....bash
$ 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
$ pwd /home/it244gh $ echo $PWD /home/it244gh
$ alias where="echo My current location is $PWD " $ where My current location is /home/it244gh $ cd / $ pwd / $ where My current location is /home/it244gh
$ alias where='echo My current location is $PWD '
$ pwd /home/it244gh $ alias where='echo My current location is $PWD' $ where My current location is /home/it244gh $ cd / $ pwd / $ where My current location is /
$ 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 hw_setup.sh -rwxr-xr-x 1 ghoffman grad 306 Oct 14 00:18 hw_copy.sh -rwxr-xr-x 1 ghoffman grad 156 Nov 5 17:09 step.sh
$ lnwb=/home/ghoffman/public_html/it244 $ alias lnwb="cd $lnwb' $ pwd /home/ghoffman/bin $ lnwb $ pwd /home/ghoffman/public_html/it244
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
assignments_submitted it114 mail public_html vp
bin it244 Mail scans
course_files it341 News test
html it441 nsmail test_taken
$ pwd
/home/ghoffman
pushd
pushd
prints the directory stack ...ls
...
$ alias po
alias po="popd > /dev/null; echo; ls'
popd
to return to the previous directory ...unset
command
$ cheer 'Red Sox' Go Red Sox! $ unset cheer $ cheer cheer: command not found
source .bashrc