I was just on a system that didn't have this hack, and it reminded me how useful it is, so I thought I'd share it for others. Maybe you all can reply with your own shell tricks.
Some of you may know about the pushd and popd commands. pushd is like cd, but keeps track of where you've been. Then you can popd back as many levels as you want. It's like cd and cd - but with a history bigger than one.
The big issue I have with pushd and popd is that in order for popd to work, I have to remember to pushd first. But, like many of you, by default, I navigate the terminal using the cd command instead. By the time that I realize popd will be useful, it's already too late because I didn't remember to pushd up front.
Now the hack. Just toss this in your ~/.bashrc:
function cd
{
if [ $# -eq 0 ]; then
pushd ~ > /dev/null
elif [ " $1" = " -" ]; then
pushd "$OLDPWD" > /dev/null
else
pushd "$@" > /dev/null
fi
}
And start a new shell. From that point forward, cd will actually execute pushd under the hood, and popd will always be available when you need it.
Do you have a tip or trick that you'd like to share? If so, complete the Join Our Community form and join our ever-growing list of authors.
[ Free download: Advanced Linux commands cheat sheet. ]
저자 소개
Ray is a Desktop Software Engineer who works on GNOME, Fedora, and Red Hat Enterprise Linux.
유사한 검색 결과
Behind the scenes of RHEL 10, part 3
Alliander modernises its electricity grid with Red Hat for long-term reliability in balance with rapid innovation
The Overlooked Operating System | Compiler: Stack/Unstuck
Linux, Shadowman, And Open Source Spirit | Compiler
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래