Solaris · Files and Directories

Solaris · Lesson 6

Files and Directories

Solaris filesystem structure and navigation. Permissions, ownership and ACL concepts. Copy, move and delete operations. Important system directories explained.

Why focus on files and directories?

Almost everything in Unix-like systems is represented as a file or directory. If you can navigate the filesystem confidently, you can troubleshoot faster and understand how applications are laid out on a Solaris server.

In this lesson you will learn how to move around, create structure for projects, copy or move data and clean up safely using standard Solaris commands.

Core concepts for working with the filesystem

Paths

Absolute paths start from / (root of the filesystem). Relative paths start from your current directory and are shorter for day-to-day work.

Directories

Directories organise files. Commands like ls, cd and mkdir let you explore and build directory structures for your applications.

Files

Files may be configs, logs, binaries or scripts. cat, more, less and tail help you inspect them without editing.

Step-by-step command examples

The following command sequences show realistic mini-scenarios. Try them in your Solaris VM to build muscle memory.

1. Check your current location and list files

Use pwd to print the current directory and ls to see what files and folders exist there.

terminal — bash
solaris-lab
[root@solaris ~]# pwd
/root
 
[root@solaris ~]# ls
Desktop Documents scripts backup.sh
 
[root@solaris ~]# ls -l
total 12
drwxr-xr-x 2 root root 3 Jan 10 09:10 Desktop
drwxr-xr-x 3 root root 4 Jan 10 09:20 Documents
drwxr-xr-x 4 root root 5 Jan 10 09:30 scripts
-rwxr-xr-x 1 root root 2048 Jan 10 09:35 backup.sh

2. Change directory using absolute and relative paths

Absolute paths start from /, relative paths start from where you are right now.

terminal — bash
solaris-lab
[root@solaris ~]# cd /var/log
[root@solaris /var/log]# pwd
/var/log
 
[root@solaris /var/log]# cd ..
[root@solaris /var]# pwd
/var
 
[root@solaris /var]# cd log
[root@solaris /var/log]# pwd
/var/log

3. Create directories and empty files

mkdir creates directories, the -p option creates parent directories as needed, and touch creates empty files or updates timestamps.

terminal — bash
solaris-lab
[root@solaris ~]# mkdir lab
[root@solaris ~]# cd lab
[root@solaris ~/lab]# mkdir -p project/docs project/scripts
 
[root@solaris ~/lab]# cd project
[root@solaris ~/lab/project]# touch README.txt notes.txt script.sh
 
[root@solaris ~/lab/project]# ls -R
.:
docs notes.txt README.txt script.sh scripts
 
./docs:
 
./scripts:

4. Copy and move files and directories

cp copies files, cp -r copies directories; mv moves or renames files and folders.

terminal — bash
solaris-lab
[root@solaris ~/lab/project]# ls
docs notes.txt README.txt script.sh scripts
 
[root@solaris ~/lab/project]# cp README.txt docs/
[root@solaris ~/lab/project]# cp -r scripts docs/
 
[root@solaris ~/lab/project]# mv notes.txt notes-old.txt
[root@solaris ~/lab/project]# mv docs /tmp/project-docs
 
[root@solaris ~/lab/project]# ls
README.txt script.sh scripts notes-old.txt

5. Remove files and directories safely

Use rm for files, rmdir for empty directories and rm -r for directory trees. Be very careful with rm -r.

terminal — bash
solaris-lab
[root@solaris ~/lab/project]# ls
README.txt script.sh scripts notes-old.txt
 
[root@solaris ~/lab/project]# rm notes-old.txt
[root@solaris ~/lab/project]# rmdir scripts
rmdir: scripts: Directory not empty
 
[root@solaris ~/lab/project]# rm -r scripts
[root@solaris ~/lab/project]# ls
README.txt script.sh
 
# Example of a dangerous pattern – avoid:
[root@solaris ~/lab/project]# rm -rf /
rm: dangerous to operate recursively on '/'

Safety tips when removing files and directories

Be careful with rm -r

  • Always double-check the path before running rm -r.
  • Prefer rm -ri (interactive) when working in critical locations.
  • Avoid running rm -rf with wildcards in system directories.

Use safer alternatives first

  • Move data to a temporary directory before deleting permanently.
  • For logs, prefer log rotation rather than manual deletion.
  • When in doubt, take a quick backup using cp -r or tar before large cleanups.

Practice task – create a small project structure

  • Under your home directory, create a folder solaris-lab with subdirectories configs, logs and scripts.
  • Create some sample files using touch and list them with different ls options.
  • Practice copying and moving files between these directories until the commands feel natural.
  • Finally, clean up using rm, rm -r and rmdir, making sure you understand exactly what disappears at each step.

In upcoming lessons, this directory knowledge will be used when we work with configuration files, logs, user homes and ZFS datasets.