Linux has a rich command line experience that can sometimes be a little complicated for people changing over from Windows. Showing the list of recent commands is easy to understand, though:
> history
1 ps -ef
2 kill 24188
3 ps -ef
4 tail logfile.log
If you want to get a command that you used before but you have a huge history list, you can quickly find it by passing it through grep. Let’s say we remember typing the ftp command, but can’t remember the domain name of the server:
> history | grep ftp
321 ftp ftp.cdrom18.com
Pretty simple stuff! What if we want to display the list of items that we use the most often? We can use a much more complicated command like this:
> history|awk ‘{print $2}’|awk ‘BEGIN {FS=”|”} {print $1}’|sort|uniq -c|sort -r
114 ls
105 ./runreports.sh
97 cd
24 uptime
15 mysql
13 vi
> history
1 ps -ef
2 kill 24188
3 ps -ef
4 tail logfile.log
If you want to get a command that you used before but you have a huge history list, you can quickly find it by passing it through grep. Let’s say we remember typing the ftp command, but can’t remember the domain name of the server:
> history | grep ftp
321 ftp ftp.cdrom18.com
Pretty simple stuff! What if we want to display the list of items that we use the most often? We can use a much more complicated command like this:
> history|awk ‘{print $2}’|awk ‘BEGIN {FS=”|”} {print $1}’|sort|uniq -c|sort -r
114 ls
105 ./runreports.sh
97 cd
24 uptime
15 mysql
13 vi
0 comments:
Post a Comment