Skip to content
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