Linux/file/cmd

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search

Computing: Software: Operating Systems: Linux: file/folder command syntax

Linux file/folder commands and syntax

Notes

  • directoryname plus slash plus asterisk (directoryname/*) as a source means "the contents of directoryname"
  • A slash after a directory name (as in directoryname/) is optional and not significant
  • A slash preceding the filespec indicates the root of the filesystem
  • The Linux filesystem does not have the concept of "drives"; all drives are mapped into the filesystem, either at the root or via a mount. Anything not mounted may only be accessed via a protocol (such as smb://, ftp://, http://, etc.), and the native Linux file commands (mv, cp, etc.) do not understand protocols.
  • Some systems may have different defaults, often accomplished by aliasing the command to command-with-options

Examples

To move the contents of directory A into directory B
mv A/* B/
mv A/* B the terminating slash doesn't have any effect
To move directory A into directory B
mv A B
To copy the directory A into directory B (so you end up with /B/A/contents-of-A)
cp -dpR A B don't follow symbolic links, preserve attributes, recursive
cp -a A B -a is an alias for -dpR
To copy the contents of A into B (so you end up with B/contents-of-A)
cp -a A/* B this has not been tested!
To remove everything, including subdirectories, from the current directory (careful!)
rm -r * confirms each file before deleting
rm -rf * deletes all files/directories without asking

Notes for DOS refugees

Some command utilities in DOS (e.g. xcopy) used a convention wherein a trailing backslash on a name (e.g. c:\name\) meant that the name was a directory. This helped to disambiguate in certain circumstances where a name might refer to either a directory or a file – that is, you couldn't have a file with the same name as a directory, but (a) the command might involve a search where the first item with that name could be either a file or a directory, or (b) the command might involve creating something new (a file or directory) and the actions to be taken would depend on what was being created.

For mv and cp, apparently "name" and "name/" as a source both indicate "whatever you find that has this name" (to check: can "name/" be a file?), while "name/*" means "the contents of the directory named "name". It's not yet clear if this is a general rule or only applicable with some commands.