Linux Commands
From HPC
(→Copy directories) |
|||
Line 35: | Line 35: | ||
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 | 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=== | + | ===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=== | ===Renaming Files/Directories=== | ||
+ | To rename a file or directory, use the mv (move) command | ||
+ | |||
+ | mv myfile myfile-newname | ||
+ | mv dir dirnewname | ||
[[Category:Getting Started]] | [[Category:Getting Started]] |
Revision as of 12:56, 20 October 2008
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