DEV Community

Cover image for Bash Basics - Navigating the Filesystem.
Julian Toscani
Julian Toscani

Posted on

Bash Basics - Navigating the Filesystem.

Being able to use a server without a UI is a crucial skill for every developer. In this article I will tell how to navigate a servers filesystem using bash.

The Commands

pwd         # print path to current directory
ls <path>   # print visible content of current directory
cd <path>   # change current directory
cat <path>  # print content of a file
Enter fullscreen mode Exit fullscreen mode

Paths can be expressed in different ways. Here is an overview of what this means in practise.

# Ways to express paths
foo/bar      # relative to current directory
./foo/bar    # equivalent to foo/bar

/foo/bar     # from root
~/foo/bar    # from home directory
../          # to parent directory
Enter fullscreen mode Exit fullscreen mode

Hence, if you want to move to the parent directory, you type:

cd ../
Enter fullscreen mode Exit fullscreen mode

In order to check the content of the assets/ folder in your current directory (if one exists) you would type:

ls assets/
# or
ls ./assets/
Enter fullscreen mode Exit fullscreen mode

Some of these commands can show even more information. For that to happen, you can apply flags to them. A good example of this is the ls command. Here are some examples:

# show all files and folders with their current permissions, creation date and file size
# remove `a` to hide hidden files (prefixed with `.`)
ls -ao <path>

# also show all subdirectories recursively
# caution - gets big fast!
ls -R

# show all files and folders including all their subdirectories
# with their current permissions, creation date and file size
ls -aoR <path>

# Add line-numbers to the output
cat -n <path>
Enter fullscreen mode Exit fullscreen mode

Did I miss something? Let me know!

Image taken from unsplash by Gabriel Heinzer

Top comments (1)

Collapse
 
lmachens profile image
DevLeon

Thx! I think another good beginner hint is to use the TAB key for auto-completion.