On this page
- Where am I right now?
- How do I move between directories quickly?
- How do I read the long listing format?
- How do I see hidden files?
- How can I sort listings by size or date?
- How do I list a directory itself, or a whole tree?
- What is the difference between pwd -L and pwd -P?
- Why should scripts not parse ls output?
- Questions
Where am I right now?
pwd (print working directory) answers that question with the full path from the root. After an SSH login you start in your home directory, for example /home/deploy, or /root for the root account.
pwd
cd /var/log
pwd
echo "$PWD"The shell also keeps the path in the PWD variable, which scripts use to remember where they started. Most default prompts show a shortened form of the path, where ~ stands for your home directory, so deploy@web1:~/sites$ means you are in /home/deploy/sites. If you have not connected yet, start with the first SSH session tutorial.
How do I move between directories quickly?
Use cd with an absolute path, a relative path or one of the shortcuts the shell understands.
cd /etc/nginx
cd sites-available
cd ..
cd -
cd ~
cd..is the parent directory,.the current one.cd -jumps back to the previous directory and prints it, handy when switching between two places.cdorcd ~returns home;~deploymeans the home of the user deploy.
Tab completion saves typing and mistakes: type the first letters of a name and press Tab. Pressing it twice lists all matches when there is more than one.
How do I read the long listing format?
ls -l prints one line per entry with type and permissions, link count, owner, group, size, modification time and name.
ls -l /var/www
drwxr-xr-x 3 root root 4096 Nov 28 10:12 html
-rw-r--r-- 1 deploy deploy 2193 Dec 2 18:40 notes.md
lrwxrwxrwx 1 root root 24 Nov 30 09:05 current -> releases/2026-11-30The first character is the type: d for directory, - for a regular file, l for a symbolic link (followed by its target). The next nine characters are read, write and execute rights for owner, group and others. Add -h for sizes such as 4.0K or 1.2G, and -n to see numeric user and group ids instead of names, which helps when files were copied from another machine. The file permissions guide explains each permission letter.
How do I see hidden files?
Names that begin with a dot are hidden from a plain ls. -a shows them all, including the . and .. entries; -A shows hidden files but leaves those two out.
ls -la ~
ls -A /etc/skelYour shell settings (.bashrc, .profile), SSH keys (.ssh) and many application configs live in such dotfiles. Ubuntu and Debian define the alias ll for ls -alF in the default .bashrc; Rocky and Alma define ll as ls -l --color=auto. Run alias to see what your system provides.
How can I sort listings by size or date?
ls sorts alphabetically unless told otherwise. -t sorts by modification time, newest first, and -S by size, largest first; -r reverses either order.
ls -lt /var/log | head
ls -lhS ~/downloads
ls -ltr /var/log/nginx
ls -l --time-style=long-isols -ltr is a classic for log folders: the most recently written file appears at the bottom, right above your prompt. The long-iso style prints dates as 2026-12-02 18:40, which is easier to compare than the default and does not switch to a year display for older files. To see what really fills a disk, ls is the wrong tool because it does not total folder contents; use du as shown in the disk usage guide.
How do I list a directory itself, or a whole tree?
Without extra flags, ls -l /etc shows the contents of /etc. Add -d to show the entry for the directory instead, which is what you want when checking its owner or mode.
ls -ld /var/www/example.net
ls -R /srv/app | head -n 40
sudo apt install tree
sudo dnf install tree
tree -L 2 /srv/app-R lists recursively but quickly becomes long. The small tree package (apt on Ubuntu and Debian, dnf on Rocky and Alma) draws the hierarchy with indentation, and -L 2 limits the depth. Other useful flags: -i prints inode numbers, -1 forces one name per line, --group-directories-first lists folders before files, and on Rocky or Alma -Z shows SELinux labels.
What is the difference between pwd -L and pwd -P?
When you enter a directory through a symbolic link, pwd (same as pwd -L) shows the logical path you typed, while pwd -P resolves every link and shows the physical location on disk.
cd /var/www/current
pwd
pwd -P
realpath /var/www/currentIf current points to releases/2026-11-30, the first pwd prints /var/www/current and the second prints /var/www/releases/2026-11-30. realpath and readlink -f resolve any path the same way without changing directory. The symlinks guide shows why deploy scripts rely on this.
Why should scripts not parse ls output?
ls formats its output for people, so names containing spaces, newlines or unusual characters can break a script that splits that output into words. In scripts, loop over a glob or use find instead.
for f in /var/log/app/*.log; do
echo "processing $f"
done
find /var/log/app -name '*.log' -print0 | xargs -0 gzipBoth forms keep each name intact. If ls shows Permission denied or cannot access, check that you have execute rights on every directory along the path with namei -l /full/path, which lists each level and its permissions.
Questions about List files with ls, find your place with pwd
What do the colours in ls output mean?
By default blue marks directories, cyan symbolic links, green executable files and red archives. They come from --color=auto and the LS_COLORS variable.
How do I count the files in a folder?
Run ls -1A | wc -l for a quick number, or find dir -type f | wc -l to count files in all subfolders.
Why does ls -l show 4096 for every directory?
That is the size of the directory entry table, not of its contents. Use du -sh dir to see how much space a folder really uses.
How do I see full timestamps with seconds?
Use ls -l --full-time or stat file, which also shows access and change times.
Is pwd a program or a shell builtin?
Both exist. Bash uses its builtin, and /usr/bin/pwd is the coreutils program. They print the same result for normal use.
More in Linux command line
- Copy files and directories with cp
- Move and rename with mv
- Create directories and empty files
- Read files with cat, less and tail
- Find files with find and locate
- Search text with grep
- Edit and report text with sed and awk
- echo, tee and wc
- Edit files with nano
- Edit files with Vim
- Read manual pages
- Users and groups
- Ownership with chown and chgrp
- Symbolic and hard links
- Pipes, redirection and xargs