M BUZZ CRAZE NEWS
// news

How to list directories "above" working directory

By Sarah Rodriguez

My professor showed me how to list the directories above the current working directory using the cd command. I thought it was cd ..[tab] but this lists commands in my current directory.

1

3 Answers

I am assuming you just want to list directories on the parent of the current directory, you can use find:

find .. -maxdepth 1 -type d -not -name '..'

Alternately, you can use ls:

ls -p .. | grep '/$'

Or shell:

echo ../*/

or elaborately:

for i in ../*; do [ -d "$i" ] && echo "$i"; done

Or in zsh using glob qualifier / (redundant though :)):

echo ../*(/)
3

cd .. navigates to directory above your current working directory in the tree.

For example,

home:$ pwd
/home
home:$ cd ..
:$ pwd
/

As for listing directories in the parent directory, heemayl's answer sufficiently covers that. I'll just throw in another one:

 stat ../* --format="%n %F" | awk '/directory/' 
0

If you want to list contents of "above" working directory (parent directory) use:

ls ..

However, it shows both files and directories of the parent folder.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy