Linux File Management
A Beginner's Guide
Linux File Management
Introduction
This article provides a basic understanding of Linux file management, covering essential commands and file attributes. We will explore practical exercises to solidify your understanding.
Commands
ls
Lists directory contents. Example: ls -l
(lists in long format)
ls -l /home
cp
Copies files or directories. Example: cp file1.txt file2.txt
cp -r dir1 dir2 #recursive copy
-r
flag allows recursive copying of directories.mv
Moves or renames files or directories. Example: mv file1.txt newfile.txt
mv file.txt /home/user/documents
rm
Removes files or directories. Use with caution! Example: rm file1.txt
rm -rf directory #force remove, recursive
rm -rf /
. It will delete everything on your system!touch
Creates an empty file. Example: touch myfile.txt
touch file1.txt file2.txt
cat
Displays the contents of a file. Example: cat myfile.txt
cat myfile.txt | grep "keyword"
File Attributes and Metadata
Files in Linux have attributes like permissions (read, write, execute), ownership, timestamps (creation, modification, access). These can be viewed using ls -l
.
Hands-on: Creating and Managing Files/Directories
- Create a directory:
mkdir mydirectory
- Create a file inside the directory:
touch mydirectory/myfile.txt
- Copy a file:
cp myfile.txt mydirectory/myfile_copy.txt
- List the contents of the directory:
ls -l mydirectory
- Remove the directory and its contents:
rm -rf mydirectory
Summary
- Learned basic Linux file management commands (ls, cp, mv, rm, touch, cat).
- Understood file attributes and metadata.
- Practiced creating and managing files and directories.