The Definitive Guide to Bash Command Line History
20 abril, 2010 Dejar un comentario
Now, I found a nice guide that you should read:
"The definitive guide to Bash command line history" from Peteris Krumins’ blog.
# echo -n 3 > /sys/power/state
20 abril, 2010 Dejar un comentario
2 abril, 2010 Dejar un comentario
To list the entire history, type
history
To list a previous number of history commands, follow history with a number. This lists the previous five commands in your history:
$ history 5
975 mkdir extras
976 mv *doc extras/
977 ls -CF
978 vi house.txt
979 history
To move among the commands in your history, use the up arrow and down arrow. When a command is displayed, you can use the keyboard to edit the current command like any other command: left arrow, right arrow, Delete, Backspace, and so on. Here are some other ways to recall and run commands from your bash history:
Run the previous command
$ !!
Run command number 997 from history
$ !997 ls -CF
Append *doc to command 997 from history
$ !997 *doc ls -CF *doc
Run previous command line containing the CF string
$ !?CF? ls -CF *doc
Run the previous ls command
$ !ls ls -CF *doc
Run previous ls command, replacing CF with l
$ !ls:s/CF/l ls -l *doc
Another way to edit the command history is using the fc command. With fc, you open the chosen command from history using the vi editor. The edited command runs when you exit the editor. Change to a different editor by setting the FCEDIT variable (for example, FCEDIT=gedit) or on the fc command line. For example:
Edit command number 978, then run it
$ fc 978
Edit the previous command, then run it
$ fc
Use nano to edit command 989
$ fc -e /usr/local/bin/nano 989
Use Ctrl+r to search for a string in history. For example, typing Ctrl+r followed by the string ss resulted in the following:
(reverse-i-search)`ss’: sudo /usr/bin/less /var/log/messages
Press Ctrl+r repeatedly to search backward through your history list for other occurrences of the ss string.
____________________________________
1. Wiley Publishing, Inc., 2008, ISBN: 978-0-470-37603-4. Buy it in Amazon or download it from Rapidshare.
15 septiembre, 2009 1 comentario
Más sencilla aún que la fórmula anterior
curl icanhazip.com
(La encontré en un blog y no recuerdo cuál…)
28 enero, 2009 2 comentarios
find "ruta" -type f | xargs grep "cadena a buscar"
Con find (y la opción usada) se buscan archivos en el directorio especificado (usar . para el directorio actual), el comando xargs combina cada elemento con el comando especificado y grep busca patrones en el archivo.
Tambień en varias ocasiones tendremos la necesidad de buscar una cadena de texto y suplirla por otra en n cantidad de archivos, para lograr esto de manera sencilla:
for arg in `find <ruta del directorio de los archivos> -type f`; do perl -pi -e 's/<texto a buscar>/<texto nuevo>/g' $arg; done;
un ejemplo:
for arg in `find /etc/apache2 -type f`; do perl -pi -e 's/90.0.0.20/192.168.1.60/g' $arg; done;
[Fuente: LinuxData y CómoCarajos.]
2 diciembre, 2008 Dejar un comentario