
기록에서 특정 항목을 삭제하려고 합니다. 설명 - 주어진 명령/또는 텍스트가 포함된 모든 이벤트를 제거한다는 뜻입니다. Aliteralmind의 hxf 스크립트를 사용했습니다.
:<
Examples
hxf "rm -rf"
#The unalias prevents odd errors when calling". ~/.bashrc" (May result in
#"not found" errors. That's okay).
unalias hxf
hxf() {
read -r -p "About to delete all items from history that match \"$1\".
Are you sure? [y/N] " response
response=${response,,} # tolower
if [[ $response =~ ^(yes|y)$ ]]
then
#Delete all matched items from the file, and duplicate it to a temp
#location.
echo -e "grep -v \"$1\" \"$HISTFILE\" > /tmp/history"
grep -v "$1" "$HISTFILE" > /tmp/history
#Clear all items in the current sessions history (in memory). This
#empties out $HISTFILE.
echo "history -c"
history -c
#Overwrite the actual history file with the temp one.
echo -e "mv /tmp/history \"$HISTFILE\""
mv /tmp/history "$HISTFILE"
#Now reload it.
echo -e "history -r \"$HISTFILE\""
history -r "$HISTFILE" #Alternative: exec bash
else
echo "Cancelled."
fi
}
(에서https://unix.stackexchange.com/a/178956/115826)
그러나 hxf 스크립트를 실행한 후 기록에 다음이 표시됩니다. (예:)
401 254: 263: 287: 288: 293: cd ~
402 203: 243: 290: 309: 315: 332: 370: 377: 389: 400: ls
403 200: 207: 255: 263: 302: 325: 359: 378: 385: 393: 397: 399: nedit
명령이 발생할 때마다 인덱스 목록 표시 기록을 제거하려면 hxf() 스크립트를 어떻게 수정해야 합니까? hxf()를 실행한 후 위의 결과를 얻었습니다. 실행하기 전에 기록은 다음과 같습니다.
401 cd ~
402 ls
403 nedit
항목 목록이 금방 길어져서 읽기 어려울 수 있습니다. hxf를 실행하기 전과 같이 기록 출력을 표시해야 합니다. 유일한 차이점은 hxf()로 삭제한 명령이 이제 삭제된다는 것입니다.
답변1
기록에서 명령을 삭제하는 방법을 묻는 경우:
기록-d(숫자)
"역사"를 실행하여 숫자 얻기