Here are some commonly used command-line file management tools for various tasks in Unix/Linux environments. These tools help you efficiently handle files and directories:
- Purpose: Display files and directories.
- Example:
ls -l
: List files with details (permissions, size, date).ls -a
: Show hidden files.
- Purpose: Copy files and directories.
- Example:
cp file1.txt file2.txt
: Copyfile1.txt
tofile2.txt
.cp -r dir1 dir2
: Copy directorydir1
todir2
.
- Purpose: Move or rename files and directories.
- Example:
mv file.txt /path/to/directory/
: Move a file.mv oldname.txt newname.txt
: Rename a file.
- Purpose: Delete files or directories.
- Example:
rm file.txt
: Remove a file.rm -r directory/
: Remove a directory and its contents.
- Purpose: Create directories.
- Example:
mkdir newdir
: Create a new directory.mkdir -p /path/to/newdir
: Create nested directories if they don’t exist.
- Purpose: Delete empty directories.
- Example:
rmdir directory/
: Remove an empty directory.
- Purpose: Search for files and directories.
- Example:
find /path -name "*.txt"
: Find all.txt
files under/path
.find /path -size +1G
: Find files larger than 1GB.
- Purpose: Create and extract archives.
- Example:
tar -czvf archive.tar.gz /path
: Create a compressed archive.tar -xzvf archive.tar.gz
: Extract the archive.
- Purpose: Compress and extract files using ZIP format.
- Example:
zip archive.zip file1.txt file2.txt
: Create a ZIP archive.unzip archive.zip
: Extract the archive.
- Purpose: Sync files between directories or machines.
- Example:
rsync -av /source/ /destination/
: Synchronize files from source to destination.
- Purpose: Estimate file and directory space usage.
- Example:
du -sh directory/
: Show human-readable size of a directory.
- Purpose: Display available disk space.
- Example:
df -h
: Show human-readable disk space usage.
- Purpose: Modify file permissions.
- Example:
chmod 755 file.txt
: Set permissions (read, write, execute).
- Purpose: Change file owner and group.
- Example:
chown user:group file.txt
: Change the owner and group of a file.
- Purpose: Create symbolic or hard links to files.
- Example:
ln -s /path/to/file linkname
: Create a symbolic link.
- Purpose: Display the first or last lines of a file.
- Example:
head -n 10 file.txt
: Show the first 10 lines.tail -f log.txt
: Follow the latest lines added to a file.
- Purpose: View or combine file contents.
- Example:
cat file.txt
: Display the content of a file.
- Purpose: Search for patterns within files.
- Example:
grep "search_term" file.txt
: Find lines containing the search term.
- Purpose: Display detailed file information.
- Example:
stat file.txt
: Show details like size, permissions, and timestamps.
- Purpose: Create an empty file or update timestamps.
- Example:
touch newfile.txt
: Create a new empty file or update the timestamp of an existing file.
Do you need help with any specific commands or a more detailed explanation?