Fc (Unix)
The fc command is required to be an "intrinsic" utility by POSIX[2], and as such is implemented as a builtin in the Bash, Zsh, and Almquist shells. Invoked with no options, fc will open a text editor, allowing the user to modify the last-run command. Upon exiting the editor, the modified command is executed in the current shell. Various other command-line options are supported, allowing quick substitutions, repetition or modification of a specific command from the session history, or a range of commands from the history. ExamplesWhen invoked with the $ fc -l
1 pwd
2 whoami
3 ls
4 ls -a
When invoked with $ fc -s ls
ls -a
. .. .bash_logout .bashrc .profile
Though, more powerfully, $ ls floder # user typo
$ fc -s flod=fold # revise and re-run with correction
ls folder
Invoking $ fc # change 'ls -a' to 'ls -la' in editor and exit
ls -la
total 20
drwxr-x--- 2 user user 4096 Apr 22 15:38 .
drwxr-xr-x 1 root root 4096 Apr 22 15:38 ..
-rw-r--r-- 1 user user 220 Apr 22 15:38 .bash_logout
⋮
The editor to be used can be specified with the It is also possible to edit and re-invoke a range of commands from the history: $ fc -l
1 pwd
2 whoami
3 ls
4 ls -a
5 ls -la
$ fc 1 2 # specify start and end history entries, separated by whitespace
pwd
/home/user
whoami
user
External links
See alsoReferences
|
Portal di Ensiklopedia Dunia