File Management & Navigation
File Management & Navigation in Ubuntu
๐งญ 1. Navigation Commands
| Command |
Description |
lspwd |
-lahPrint #current Listdirectory filespath |
with
size,
permscd |
Change directory |
cd /path/to/dir |
#Go Changeto specific directory |
pwd
#
Printcd current.. |
workingGo 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 mydirfoldername |
#Create Createa new directory |
mkdir -p /path/to/nested/folder |
Create nested directories |
touch file.phptxt |
# Create newan 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.phptxt |
# Delete a file |
rm -r folder/ |
#Delete Deletedirectory recursively |
rm -rf folder/ |
Force delete folder recursively(use cpwith file1.phpcaution) |
backup.php
#
Copy
๐ฆ 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 mvwith 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 /path -type f -mtime +30 -delete |
Delete files older than 30 days |
๐ 5. Permissions and Ownership
| Command |
Description |
chmod 755 file.phpsh |
dir/ # Move or renameChange 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 |