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_filenameMoves a file or directory from one location to another. It can also be used to rename files and directories.
Remove Files or Directories
rm filenameRemoves (deletes) a file. Use with caution, as deleted files are not recoverable.
rm -r directoryRecursively removes a directory and its contents. This command is used for deleting directories.
Remove Empty Directories
rmdir directoryRemoves an empty directory. This command only works if the directory is empty.
Create Directories
mkdir directory_nameCreates a new directory with the specified name.
Copy Files or Directories
cp source_file target_fileCopies a file to a new location.
cp -r source_directory target_directoryRecursively copies a directory and its contents to a new location.
Create Empty File
touch filenameCreates an empty file with the specified name. If the file already exists, update its timestamp.
Change File Ownership
chown new_owner:new_group filenameChanges the owner (and group) of a file to the specified user (group).
chown -R new_owner:new_group directoryRecursively changes the owner of a directory and its contents to the specified user (group).
Change File Permissions
chmod permissions filenameChanges 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 directoryRecursively 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.
Center for Computational Sciences