File Operations
Advanced file manipulation and processing commands
tar - Archive Operations
Archive creation, extraction, and management
# Create tar archive
tar -cvf archive.tar files/
# Create compressed tar archive
tar -czvf archive.tar.gz files/
# Extract tar archive
tar -xvf archive.tar
# Extract compressed tar archive
tar -xzvf archive.tar.gz
# List contents of archive
tar -tvf archive.tar
# Extract specific files
tar -xvf archive.tar file1.txt file2.txt
# Create archive excluding files
tar -czvf archive.tar.gz --exclude='*.tmp' files/
# Update existing archive
tar -uvf archive.tar newfile.txt
Individual commands:
tar -cvf archive.tar files/
tar -czvf archive.tar.gz files/
tar -xvf archive.tar
tar -xzvf archive.tar.gz
tar -tvf archive.tar
tar -xvf archive.tar file1.txt file2.txt
tar -czvf archive.tar.gz --exclude='*.tmp' files/
tar -uvf archive.tar newfile.txt
zip/unzip - Compression
ZIP compression and extraction operations
# Create zip archive
zip archive.zip files/
# Create zip with compression level
zip -9 archive.zip files/
# Extract zip archive
unzip archive.zip
# Extract to specific directory
unzip archive.zip -d /path/to/directory/
# List contents of zip
unzip -l archive.zip
# Extract specific files
unzip archive.zip file1.txt file2.txt
# Create password-protected zip
zip -e archive.zip files/
# Extract with overwrite
unzip -o archive.zip
Individual commands:
zip archive.zip files/
zip -9 archive.zip files/
unzip archive.zip
unzip archive.zip -d /path/to/directory/
unzip -l archive.zip
unzip archive.zip file1.txt file2.txt
zip -e archive.zip files/
unzip -o archive.zip
diff/patch - File Comparison
File comparison and patch management
# Compare two files
diff file1.txt file2.txt
# Compare files with context
diff -c file1.txt file2.txt
# Compare files with unified format
diff -u file1.txt file2.txt
# Compare directories
diff -r dir1/ dir2/
# Create patch file
diff -u original.txt modified.txt > changes.patch
# Apply patch file
patch original.txt changes.patch
# Reverse patch
patch -R original.txt changes.patch
# Show only differences
diff --brief file1.txt file2.txt
Individual commands:
diff file1.txt file2.txt
diff -c file1.txt file2.txt
diff -u file1.txt file2.txt
diff -r dir1/ dir2/
diff -u original.txt modified.txt > changes.patch
patch original.txt changes.patch
patch -R original.txt changes.patch
diff --brief file1.txt file2.txt
ln - Link Operations
File and directory linking operations
# Create symbolic link
ln -s /path/to/target link_name
# Create hard link
ln /path/to/target link_name
# Create symbolic link to directory
ln -s /path/to/directory link_dir
# Remove symbolic link
rm link_name
# List symbolic links
ls -la | grep '^l'
# Find broken symbolic links
find /path -type l -exec test ! -e {} \;
# Create relative symbolic link
ln -s ../target link_name
Individual commands:
ln -s /path/to/target link_name
ln /path/to/target link_name
ln -s /path/to/directory link_dir
rm link_name
ls -la | grep '^l'
find /path -type l -exec test ! -e {} \;
ln -s ../target link_name