Rocky Linux Core Commands: Page 2

This page covers essential commands for creating, copying, moving, deleting, and viewing files.


6. touch - Create Empty Files / Update Timestamps

Purpose: The touch command has two primary uses:

  1. To create new, empty files.
  2. To update the access and modification timestamps of existing files without altering their content.

Syntax: touch [OPTIONS] FILE...

Examples:

touch new_file.txt
touch existing_file.log

7. cp - Copy Files and Directories

Purpose: The cp command is used to copy files and directories from one location to another.

Syntax: cp [OPTIONS] SOURCE DESTINATION

Key Options:

Examples:

cp file1.txt /tmp/backup/
cp -r my_docs /mnt/usb_drive/
cp -i document.pdf ~/archive/

8. mv - Move/Rename Files and Directories

Purpose: The mv command is used for two main operations:

  1. Moving files or directories from one location to another.
  2. Renaming files or directories.

Syntax: mv [OPTIONS] SOURCE DESTINATION

Key Options:

Examples:

mv old_name.txt new_name.txt
mv report.pdf ~/reports/
mv -v project_data /backup/old_projects/

9. rm - Remove Files and Directories

Purpose: The rm command is used to remove (delete) files and directories. Use with caution, as deleted items are typically not recoverable.

Syntax: rm [OPTIONS] FILE...

Key Options:

Examples:

rm unwanted_file.txt
rm -r old_project_folder
rm -i sensitive_data.log

10. cat - Concatenate and Display File Content

Purpose: The cat command (short for concatenate) is primarily used to display the content of files on the standard output. It can also be used to concatenate multiple files into one.

Syntax: cat [OPTIONS] [FILE...]

Key Options:

Examples:

cat my_document.txt
cat -n script.sh
cat file1.txt file2.txt > combined.txt