Debian File Commands
Introduction
When working with Debian Linux, understanding how to manipulate files through the terminal is a fundamental skill. File commands allow you to create, view, modify, and manage files directly from the command line without needing any graphical interfaces. This guide will walk you through the most common and useful file commands in Debian, with practical examples to help you become proficient in file manipulation via the terminal.
Basic File Navigation
Before diving into file commands, it's important to understand how to navigate the file system.
Checking Your Location
To see your current directory:
pwd
Output:
/home/username
The pwd
command (Print Working Directory) shows your current location in the file system.
Listing Files and Directories
To list files in the current directory:
ls
Output:
Documents Downloads Music Pictures Videos
For a more detailed view with hidden files:
ls -la
Output:
total 56
drwxr-xr-x 2 username username 4096 Mar 10 14:30 .
drwxr-xr-x 4 username username 4096 Mar 10 14:15 ..
-rw------- 1 username username 220 Mar 10 14:15 .bash_history
-rw-r--r-- 1 username username 3771 Mar 10 14:15 .bashrc
drwxr-xr-x 2 username username 4096 Mar 10 14:20 Documents
drwxr-xr-x 2 username username 4096 Mar 10 14:20 Downloads
drwxr-xr-x 2 username username 4096 Mar 10 14:20 Music
drwxr-xr-x 2 username username 4096 Mar 10 14:20 Pictures
drwxr-xr-x 2 username username 4096 Mar 10 14:20 Videos
Changing Directories
Move to a specific directory:
cd Documents
Move to your home directory:
cd ~
Move up one level:
cd ..
Creating Files and Directories
Creating Directories
To create a new directory:
mkdir projects
Creating nested directories in one command:
mkdir -p projects/website/css
The -p
flag allows you to create parent directories if they don't exist.
Creating Files
There are several ways to create new files in Debian:
Using touch
(creates an empty file):
touch notes.txt
Using redirection:
echo "Hello, Debian!" > greeting.txt
Using text editors:
nano document.txt
Note: After using nano
, you'll enter the editor interface. Press Ctrl+X
, then Y
, and then Enter
to save and exit.
Viewing File Content
Displaying File Content
View the entire content of a file:
cat greeting.txt
Output:
Hello, Debian!
View a file with pagination (for large files):
less large_file.txt
Display the first 10 lines of a file:
head -n 10 large_file.txt
Display the last 10 lines of a file:
tail -n 10 large_file.txt
Live monitoring of file changes (useful for log files):
tail -f /var/log/syslog