Scenario Context: You've created initial configuration snippets. Now, a senior engineer informs you that the company has a standard for storing device configurations. You must organize your files according to this structure, learn to move, copy, and back them up, and prepare for the next step: backing up the actual device configurations from the network.
1. Create the standard directory structure for network backups.
2. Move your existing config snippets into the correct folders.
3. Practice copying files and creating backup archives with timestamps.
4. Understand the difference between moving (mv) and copying (cp).
Welcome back. You're logged into Ubuntu-MGMT. Open terminal and ssh to Linux server. First, let's ensure we're in our network configuration directory.
cd ~/network-configs
Press Enter. Your prompt should be root@kvm:~/network-configs#. Good. Let's see what we have.
ls -l
You should see your two files: sw_vlan_config.txt and r1_interface_config.txt.
Now, the senior engineer says the standard directory is /etc/netbackup/. This is a common practice—keeping system-wide configuration backups under /etc/. We need to create this structure. Let's look at what's required: separate folders for switches and routers.
We'll use mkdir -p again. This is crucial. The /etc/netbackup directory might not exist, and we want to create it and its subdirectories in one command.
mkdir -p /etc/netbackup/switches /etc/netbackup/routers
Press Enter. Let's break this down:
● mkdir -p: Make directories, creating parent directories as needed.
● /etc/netbackup/switches: The full path for the switches directory.
● /etc/netbackup/routers: The full path for the routers directory.
Now, let's verify the structure was created. Use ls with the -d flag to list directories themselves, not their contents.
ls -ld /etc/netbackup
Press Enter. You'll see details about the /etc/netbackup directory (permissions, owner, etc.). Now let's look inside it.
ls -la /etc/netbackup/
Press Enter. You should see two entries: . and .. (the current and parent directory), and your two new directories: switches and routers. Perfect.
Now, we need to place our configuration files into the correct folders. The file sw_vlan_config.txt belongs in /etc/netbackup/switches/. We will move it there, not copy. Moving removes it from the original location. The command is mv, which stands for "move."
Remember, you are still in network-configs directory (cd ~/network-configs)
The syntax is mv
mv sw_vlan_config.txt /etc/netbackup/switches/
Press Enter. It seems like nothing happened—that's usually a good sign in Linux. Now, let's check if the file is gone from our current directory.
ls -l
Press Enter. The sw_vlan_config.txt file should no longer be listed. It has been moved. Now, let's verify it arrived safely in its new home.
ls -l /etc/netbackup/switches/
Press Enter. There it is! You should see sw_vlan_config.txt.
Now, let's move the router configuration file. We'll move r1_interface_config.txt to the routers folder.
mv r1_interface_config.txt /etc/netbackup/routers/
Press Enter. Verify both moves are complete. Let's check our current directory and both backup directories.
ls -l
ls -l /etc/netbackup/switches/
ls -l /etc/netbackup/routers/
Press Enter after each. Your ~/network-configs directory should be empty. The switches and routers folders should each contain one file.
Now, here's a critical concept. What if you want to keep a working copy in your home directory but also have the official one in /etc/netbackup? You wouldn't move it; you would copy it. The command for copying is cp.
Let's simulate this. First, we need to get our files back into our working directory. We'll copy them from the backup location. We'll use cp. The syntax is the same as mv: cp
cp /etc/netbackup/switches/sw_vlan_config.txt ~/network-configs/
cp /etc/netbackup/routers/r1_interface_config.txt ~/network-configs/
Press Enter. Let's verify the copy worked.
ls -l ~/network-configs/
Press Enter. Both files should be back. Now, let's also check the original locations to confirm they are still there.
ls -l /etc/netbackup/switches/ /etc/netbackup/routers/
They are still there. Good. So now you have two identical copies of each file in different places. This is the difference between mv (cut/paste) and cp (copy/paste).
In network operations, you often need to create timestamped backups. Before you push a new config to a device, you back up the old one with the date. Let's learn how to do that. We'll create a backup of the switch config with today's date.
First, let's see how to get a date string in the terminal. The date command is powerful. We can format its output. A common format for backups is YYYY-MM-DD. Let's try.
date +%Y-%m-%d
Press Enter. It prints something like 2026-1-17. That's perfect for a filename.
Now, let's create a backup. We'll copy the official switch config to a new file with that date appended. We can do this in one command using command substitution. The syntax $(command) runs the command inside and uses its output. We'll embed the date command inside our cp command.
cp /etc/netbackup/switches/sw_vlan_config.txt /etc/netbackup/switches/sw_vlan_config_$(date +%Y-%m-%d).bak
Press Enter. Let's read this command carefully:
● cp: The copy command.
● /etc/netbackup/switches/sw_vlan_config.txt: The source file (the original).
● /etc/netbackup/switches/sw_vlan_config_$(date +%Y-%m-%d).bak: The destination.
● sw_vlan_config_: The start of the new filename.
● $(date +%Y-%m-%d): This runs date +%Y-%m-%d and puts its output (e.g., 2026-1-17) right here in the filename.
● .bak: The file extension, short for "backup."
Also do the same for r1_interface_config in /etc/netbackup/routers/
cp /etc/netbackup/switches/sw_vlan_config.txt /etc/netbackup/routers/r1_interface_config_$(date +%Y-%m-%d).bak
Now, let's verify the new backup file exists.
ls -l /etc/netbackup/switches/
Press Enter. You should now see two files: the original sw_vlan_config.txt and a new one like sw_vlan_config_2026-1-17.bak.
ls -l /etc/netbackup/routers/
Press Enter. You should now see two files: the original r1_interface_config.txt and a new one like r1_interface_config_2026-1-17.bak.Excellent. You've just created your first automated, timestamped backup using a Linux command.
One more useful command: rm. This removes files. Use it with extreme caution. There is no "Recycle Bin" in the Linux terminal. Once you rm a file, it's generally gone for good. Let's clean up our ~/network-configs directory since we have the official copies.
rm ~/network-configs/sw_vlan_config.txt ~/network-configs/r1_interface_config.txt
Press Enter. Verify they are gone.
ls -l ~/network-configs/
Press Enter. The directory should be empty again.
Let's also look at the -i (interactive) flag for rm, which is a good safety habit. It asks you for confirmation before deleting each file. Let's create a dummy file to test it.
touch testfile.txt
touch creates an empty file. Now let's remove it interactively.
rm -i testfile.txt
Press Enter. The prompt will ask: rm: remove regular empty file 'testfile.txt'? You must type y for yes or n for no and then press Enter. Type y and press Enter. The file is deleted. Verify with ls.
Finally, let's see the final, organized state of our backup system.
tree /etc/netbackup/
If tree is not installed, you can use:
find /etc/netbackup/ -type f
This find command lists all files under /etc/netbackup/. You should see your two original config files and the dated backup for the switch.
Summary: You have now learned the core Linux file operations for a network engineer:
● Create directories: mkdir -p for creating nested structures.
● Move files: mv to relocate files (like organizing configs into standard folders).
● Copy files: cp to duplicate files (for keeping working copies or creating backups).
● Remove files: rm (use -i for safety) to delete files.
● Timestamped Backups: Using cp with $(date +%Y-%m-%d) to create automated backup filenames.
Your configuration files are now properly archived in the company-standard location, /etc/netbackup/. In the next lab, we will secure this critical directory so that only you, the network administrator, can modify these configurations.