Linux Commands
From HPC
Contents |
Linux Commands
Remember Linux is Case Sensitive. myscript is different to MyScript.
Files and Directories
Copy files
cp from to
Examples
cp * mywork/
Copies all files in current directory to a sub directory called mywork.
cp myfile.txt myfile.txt.backup
Copies a file in the same directory and renames that file.
Copy directories
cp -R directory destinantion
The -R switch means recursive, meaning it will copy the contents of subdirectories as well.
Examples
cp -R dir1 dir2
This copy dir1 and it's contents to dir2. The end result is dir2/dir1/files
cp -R dir1/ dir2/
This copies the contents of dir1 (but not actually the direcory it's self) to dir2. Note dir2 must already exist. The end result is dir2/files
Moving Files/Directories
Move file to a different directory
mv myfile dir/to/move/to/
Move files using wild cards
mv file* dir/ (would move any file starting "file" i.e. file1, file2, file-that-should-be-moved)
Move the contents of a directory (files + sub directories) to another directory.
mv mydir/* mydir2/
As above but move to current directory
mv mydir/* ./
Renaming Files/Directories
To rename a file or directory, use the mv (move) command
mv myfile myfile-newname
mv dir dirnewname
Delete Files
To delete a file
rm <filename> rm myjob.log
To delete multiple files
rm <partfilename>* rm mywork* (delete all files starting with mywork) rm *.log (delete all files ending with .log)
Delete Directories
To delete a directory (note the directory should be empty)
rmdir <directory> rmdir myworkdir