Skip to main content

File Management & Navigation

🧭 1. Navigation Commands

Command Description
pwd Print current directory path
cd Change directory
cd /path/to/dir Go to specific directory
cd .. Go up one directory
cd ~ Go to home directory
ls List files and folders
ls -l Long listing with permissions
ls -a List hidden files
ls -lh Human-readable size in long listing

πŸ“„ 2. File & Directory Management

Command Description
mkdir foldername Create a new directory
mkdir -p /path/to/nested/folder Create nested directories
touch file.txt Create an empty file
cp file1.txt file2.txt Copy file
cp -r folder1 folder2 Copy directory
mv oldname.txt newname.txt Rename or move file/directory
rm file.txt Delete a file
rm -r folder/ Delete directory recursively
rm -rf folder/ Force delete folder (use with caution)

πŸ“¦ 3. Folder & File Sizes

Command Description
du -sh Show total size of current directory
du -sh foldername/ Show size of a specific folder
du -ah Show size of all files and subfolders
du -h --max-depth=1 Show size of each folder in current dir
df -h Show disk space usage (human-readable)

πŸ” 4. Search and Find Files

Command Description
find . -name "file.txt" Find file with exact name in current folder and subfolders
find /path -type f -mtime -7 Files modified in the last 7 days
find /path -type f -mtime +30 Files older than 30 days
find /path -type f -name "*.log" Find all .log files
find /path -type f -mtime +30 -name "*.log" Old log files
find /backups -type f -name "*.zip" -mtime +30 -exec rm -f {} \; Delete .zip files older than 30 days
find /var/log -type f -name "*.log" -mtime +14 -delete Delete .log files older than 30 days
find /path -type f -mtime +30 -delete Delete all files older than 30 days

πŸ“‹ 5. Permissions and Ownership

Command Description
chmod 755 file.sh Change file permissions
chown user:group file.txt Change ownership
ls -l View current permissions and ownership

πŸ—ƒοΈ 6. File Viewing & Editing

Command Description
cat file.txt Display contents
less file.txt View file with scroll (better for large files)
head -n 10 file.txt Show first 10 lines
tail -n 10 file.txt Show last 10 lines
nano file.txt Edit file using Nano
vim file.txt Edit file using Vim (advanced)

🧹 7. File Compression & Archiving

Command Description
tar -cvf archive.tar folder/ Create archive
tar -xvf archive.tar Extract archive
gzip file.txt Compress file
gunzip file.txt.gz Decompress gzip file
zip -r archive.zip folder/ Create zip archive
unzip archive.zip Unzip file