Filesystem and navigation
Navigate safely, inspect paths and file types, explain links and inodes, and verify targets before copy, move or removal.
Explanation
Start with your current location
Before creating, copying, moving, or deleting anything, answer two questions:
- Which directory am I in? Use
pwd. - What is in this directory? Use
ls.
Linux uses one directory tree beginning at /, called the root directory. Your personal workspace is normally below /home. Project tools may be installed below /usr or /opt, while logs and changing system data are commonly below /var.
Paths work as follows:
| Form | Meaning | Example |
|---|---|---|
| Absolute path | Starts at / and means the same location from every directory. |
/home/student/project/rtl/dut.sv |
| Relative path | Starts from the current directory. | rtl/dut.sv |
. |
The current directory. | find . -name '*.sv' |
.. |
The parent directory. | cd .. |
~ or $HOME |
Your home directory. | cd "$HOME" |
Names beginning with . are hidden from a normal ls listing. Use ls -a when you need to see files such as .bashrc or .gitignore.
Files, links, and resolved paths
An inode stores metadata about a filesystem object. A hard link names the same inode; a symbolic link stores another path and may become dangling. stat, file, readlink and realpath help inspect before acting. which may miss aliases and functions; type and command -v report shell resolution. locate depends on an optional index and can be stale.
Command reference
The examples below use a disposable directory under your home folder. Replace sample paths only after checking them with pwd, ls and realpath.
| Command | Usage and description | Example |
|---|---|---|
pwd |
Prints the absolute path of the current working directory. Use it before running commands that depend on relative paths. | pwd |
ls |
Lists directory entries. -l shows details, -a includes hidden entries and -h makes sizes readable. |
ls -lah "$HOME/asic-linux-practice" |
cd |
Changes the shell's current directory. cd .. moves to the parent and cd ~ moves home. |
cd "$HOME/asic-linux-practice" |
mkdir |
Creates directories. -p creates missing parent directories and does not fail when the directory already exists. |
mkdir -p "$HOME/asic-linux-practice/source" |
touch |
Creates an empty file when it does not exist or updates its timestamps when it does. | touch source/note.txt |
cp |
Copies a file. Use -r for a directory and -i when you want a prompt before overwriting. |
cp -i source/note.txt backup-note.txt |
mv |
Moves or renames a file or directory. Use -i to ask before replacing an existing destination. |
mv -i backup-note.txt source/note-copy.txt |
rm |
Removes files. -r recursively removes a directory tree and must be used only after checking the resolved target. |
rm -i source/note-copy.txt |
rmdir |
Removes an empty directory. It refuses to remove a directory that still contains entries. | rmdir empty-directory |
stat |
Shows metadata including type, size, permissions, owner, inode and timestamps. | stat source/note.txt |
file |
Examines file contents or metadata to report the likely file type. | file source/note.txt |
find |
Searches below a starting directory using conditions such as name, type or modification time. Always choose a narrow starting path. | find . -maxdepth 2 -type f -name '*.txt' -print |
ln |
Creates a hard link by default. -s creates a symbolic link containing a target path. |
ln -s source/note.txt note-link |
readlink |
Prints the path stored inside a symbolic link. -f follows the complete chain where supported. |
readlink note-link |
realpath |
Resolves an absolute, normalized path and follows symbolic links. Use it to verify a target before changing or deleting it. | realpath note-link |
tree |
Displays a directory hierarchy when the optional tree package is installed. |
tree "$HOME/asic-linux-practice" |
pushd |
Changes directory while saving the previous location on the shell directory stack. | pushd "$HOME/asic-linux-practice/source" |
popd |
Removes the top directory from the stack and returns to the saved location. | popd |
dirs |
Displays the shell directory stack used by pushd and popd. |
dirs -v |
Options can vary between Linux implementations. Read the local manual with man command or concise help with command --help, for example man ls or find --help.
Worked example
Build a safe practice workspace
Run each command one at a time. Read its output before continuing.
mkdir -p "$HOME/asic-linux-practice/source"
cd "$HOME/asic-linux-practice"
pwd
touch source/note.txt
ls -la source
stat source/note.txt
file source/note.txt
ln -s source/note.txt note-link
readlink note-link
realpath note-link
find . -maxdepth 2 -type f -print
Expected observations:
pwdends withasic-linux-practice.ls -la sourceshowsnote.txt, including its permissions and owner.file source/note.txtreports an empty file.readlink note-linkprints the stored relative target.realpath note-linkprints the final absolute target.findprints./source/note.txt.
RTL/DV project example
Create only empty practice files:
mkdir -p "$HOME/asic-linux-practice/project"/{rtl,tb,sim,logs,scripts}
cd "$HOME/asic-linux-practice/project"
touch rtl/dut.sv tb/tb_top.sv
find . -maxdepth 2 -type f -name '*.sv' -print
The find result should list the RTL and testbench source files. Keeping generated simulation output and logs outside rtl/ and tb/ prevents accidental source changes and makes cleanup easier.
Common mistakes
- Running a relative-path command before checking
pwd. - Using
lswithout-aand assuming hidden files do not exist. - Reversing the source and destination arguments to
cpormv. - Using
rm -rbefore resolving and listing the exact target. - Assuming a symbolic link and its target are the same filesystem entry.
Compare cd, pushd, popd and dirs; try tree if installed. Inspect targets before cp, cp -r, mv, rename, rm or rmdir. For a destructive operation, print realpath and list the exact target first. Never copy or remove a computed path you have not checked.
Check yourself
How can a relative path change meaning? Which command reveals the target of a symbolic link?
Practice: Filesystem and navigation
Create a second directory, copy the note into it, move that copy, and report the original and resolved paths. Explain why deleting a symlink differs from deleting its target.
Practice work is non-certified and is not stored by ASIC Campus.