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
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
Hence, if you want to move to the parent directory, you type:
cd ../
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/
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>
Did I miss something? Let me know!
Image taken from unsplash by Gabriel Heinzer
Top comments (1)
Thx! I think another good beginner hint is to use the
TAB
key for auto-completion.