Home Technical Support Files and Directories in Practical DevSecOps Labs: Creating, Editing, and Navigating

Files and Directories in Practical DevSecOps Labs: Creating, Editing, and Navigating

Last updated on Sep 03, 2026

Files and Directories in Practical DevSecOps Labs: Creating, Editing, and Navigating

Working with files and directories is one of the most common tasks in the Practical DevSecOps labs. This article covers essential commands for creating, navigating, editing, renaming, and removing files and directories.


Table of Contents

  1. Navigating Directories
  2. Working with Files
  3. Here Documents
  4. Common Questions

Navigating Directories

Creating and listing directories

mkdir new-directory    # creates a new directory (silent on success)
ls new-directory       # lists contents (empty produces no output)

Checking your current location

pwd
/

/ means you are in the root directory of the filesystem.

Changing directories

cd new-directory   # enter a directory
cd ..              # go to parent directory
cd .               # stay in current directory (rarely needed)

Removing directories

rmdir new-directory   # removes an empty directory

Note: rmdir only removes empty directories. Use rm -r to remove directories with contents (use with caution).


Working with Files

Creating and editing files with nano

nano myfile

Once in the editor, type your content, then:

  • Save: Ctrl + O, then Enter
  • Exit: Ctrl + X (or Ctrl + X, then Y to confirm save)

Viewing file contents with cat

cat myfile

cat reads a file's content and displays it on the terminal.

Renaming files with mv

mv myfile newfile

mv (move) is used to rename or move files.

Deleting files with rm

rm newfile

Warning: rm permanently deletes the file. There is no trash bin in Linux.


Here Documents

You can create files non-interactively using here documents (useful for automation and CI/CD):

cat > filename <<EOL
Some text content
Some text content 2
Some text content 3
EOL

How it works:

  1. cat followed by > creates a file
  2. <<EOL starts a here document block — everything between the markers is treated as input
  3. The closing EOL on its own line ends the block

Verify with ls to see the file, and cat filename to review its contents.


Common Questions

Question Answer
How do I go back to the previous directory? Use cd .. to go to the parent directory.
What's the difference between . and ..? . refers to the current directory, .. refers to the parent directory.
Can I create a file without an editor? Yes, use touch filename to create an empty file, or a here document (cat > filename <<EOL).
Why does rmdir fail on some directories? rmdir only works on empty directories. Remove contents first, or use rm -r directory.
How do I view hidden files? Use ls -la to show all files, including those starting with a dot (.).

Wrap-Up

Mastering file and directory operations is essential for every lab exercise. Remember the core commands: mkdir, cd, pwd, ls, cat, nano, mv, rm, and rmdir. Use here documents for quick, non-interactive file creation. Happy file management!