Linux
File Operations
Copy, move, link, and search files efficiently.
By EZ4Code Team
filefindcopy
Code
# Copy and move
cp -a /src /dest # archive mode, preserves attrs
mv file.txt /tmp/ # move or rename
ln -s /etc/nginx nginx # symbolic link
ln /etc/nginx nginx-hard # hard link
# Find by name, type, mtime
find /var/log -name "*.log" -mtime +7 -delete
find . -type f -size +100M
find . -type d -name node_modules -prune -exec rm -rf {} +
# Locate files (uses indexed db)
locate nginx.conf
updatedb # rebuild index
# Tree view
tree -L 2 -I 'node_modules|.git'Explanation
cp -a preserves permissions, ownership, and timestamps when copying directories. find is the workhorse for locating files by name, size, mtime, or type, with -exec to act on each match. -prune skips directories, and locate is far faster than find for name lookups thanks to its indexed database.
More Linux Snippets
Permissions & Ownership
Manage read/write/execute bits with chmod and chown.
Process Management
List, signal, and monitor running processes.
Networking
Inspect interfaces, ports, connections, and DNS.
Package Management
Install, update, and search packages on Debian and RHEL.
Text Processing
Filter, transform, and summarize text streams.
Disk Usage
Inspect filesystems, large directories, and inodes.