Go Up As Much Directory Levels As You Need – Easily
This neat and brilliant script by shell-fu allows you to go up as many directory levels as you want.
For example, instead of typing
cd ../../../..
You’ll be able to type the following and get the same functionality:
cd .. 4
Here is the bash function which does the magic:
1
2
3
4
5
6
7
8
9
10 # .. - Does a 'cd ..'
# .. 3 - Does a 'cd ../../..'
#
function .. (){
local arg=${1:-1};
while [ $arg -gt 0 ]; do
cd .. >&/dev/null;
arg=$(($arg - 1));
done
}
In order to use it, add the above code to your ~/.bashrc file (or to a new file, and source the file in your bashrc).
Now open a terminal and try it.
Original post is here.
Enjoy
No related posts.
3 Comments to Go Up As Much Directory Levels As You Need – Easily
Leave a Reply
About Me
Tags
Bash
Collaboration
Command Line Interface
Courses
Debug
Ebooks
Email
Facebook
Firefox
Gnome
Google
Hardware
Illusions
Linux
Linux Development
Macros
Manpages
Multimedia
Networks
Object Oriented Programming
Off-Topic
Open Knowledge
Operating Systems
Productivity
Programming
Religion
Science
Security
sed
Sharing
Shell Scripts
Short Posts
Small Code
Social Media
Studies
Terminal
TIps
Tools
Troubleshooting
Ubuntu
University
Vim
Web Development
Web Services
Websites
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- iPhone
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Regular Expressions
- Science
- Security
- Shell Scripts
- Short Posts
- Social Networks
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Calendar
Archives
- September 2010 (2)
- August 2010 (2)
- July 2010 (5)
- June 2010 (1)
- May 2010 (1)
- April 2010 (3)
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)

I find that aliasing cd … to cd ../.. is a great way to accomplish something similar as well. I also alias cd.. to cd .. and cd… to cd… – this is a hangover of mine from using 4dos many years ago.
Hi John,
Thanks for the comment.
Yep, I also had similar aliased, till I found the above function at shell-fu. I think it’s much easier to type .. 5 than cd …..
And, this function if more general, number of levels you can go up is not limited here. Don’t you agree?
For sure, my way is a hack. The way you use it is true shell-fu.