File and Directory Management
Managing files and directories is essential when working with HPC systems. This section covers commands that allow you to manipulate files, move them between directories, create new directories, copy files, change file ownership and permissions, and delete them as needed.
Useful Commands
Move or Rename Files and Directories
mv source_file_or_directory target_directory_or_filename
Moves a file or directory from one location to another. It can also be used to rename files and directories.
Remove Files or Directories
rm filename
Removes (deletes) a file. Use with caution, as deleted files are not recoverable.
rm -r directory
Recursively removes a directory and its contents. This command is used for deleting directories.
Remove Empty Directories
rmdir directory
Removes an empty directory. This command only works if the directory is empty.
Create Directories
mkdir directory_name
Creates a new directory with the specified name.
Copy Files or Directories
cp source_file target_file
Copies a file to a new location.
cp -r source_directory target_directory
Recursively copies a directory and its contents to a new location.
Create Empty File
touch filename
Creates an empty file with the specified name. If the file already exists, update its timestamp.
Change File Ownership
chown new_owner:new_group filename
Changes the owner (and group) of a file to the specified user (group).
chown -R new_owner:new_group directory
Recursively changes the owner of a directory and its contents to the specified user (group).
Change File Permissions
chmod permissions filename
Changes the permissions of a file. Permissions can be specified using octal numbers (e.g.,
chmod 644 file
) or symbolic notation (e.g.,chmod u+x file
). See Linux file permissions explained | Enable Sysadmin (redhat.com) for more information on file permissions.chmod -R permissions directory
Recursively changes the permissions of a directory and its contents.
These commands are fundamental for manipulating files and directories on HPC systems. Each command may have additional options (flags) to modify its behavior. For more detailed information about each command and its available flags, consult the manual pages by executing man command
(e.g., man mv
) on the login nodes.
Related content
Center for Computational Sciences