Difference between revisions of "Linux/file/cmd"
m (Woozle moved page Linux file/directory command syntax to Linux/file/cmd: reorganizing command pages) |
|||
Line 1: | Line 1: | ||
− | [[Computing]]: [[Software]]: [[Operating Systems]]: [[Linux]]: [[{{PAGENAME}}|file/ | + | [[Computing]]: [[Software]]: [[Operating Systems]]: [[Linux]]: [[{{PAGENAME}}|file/folder command syntax]] |
− | {{ | + | {{fmt/title|Linux file/folder commands and syntax}} |
==Notes== | ==Notes== | ||
* ''directoryname plus slash plus asterisk'' (<u>directoryname/*</u>) as a source means "the contents of <u>directoryname</u>" | * ''directoryname plus slash plus asterisk'' (<u>directoryname/*</u>) as a source means "the contents of <u>directoryname</u>" | ||
Line 6: | Line 6: | ||
* A slash preceding the [[filespec]] indicates the root of the filesystem | * 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 [[Samba|smb://]], [[FTP|ftp://]], [[HTTP|http://]], etc.), and the native Linux file commands (mv, cp, etc.) do not understand protocols. | * 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 [[Samba|smb://]], [[FTP|ftp://]], [[HTTP|http://]], etc.), and the native Linux file commands (mv, cp, etc.) do not understand protocols. | ||
− | * Some systems may have different defaults, often accomplished by {{ | + | * Some systems may have different defaults, often accomplished by {{l/cmd|alias}}ing the command to command-with-options |
==Examples== | ==Examples== | ||
; To move the contents of directory <u>A</u> into directory <u>B</u> | ; To move the contents of directory <u>A</u> into directory <u>B</u> | ||
− | : {{ | + | : {{l/cmd|mv}} <u>A</u>/* <u>B</u>/ |
− | : {{ | + | : {{l/cmd|mv}} <u>A</u>/* <u>B</u> {{faint|the terminating slash doesn't have any effect}} |
; To move directory <u>A</u> into directory <u>B</u> | ; To move directory <u>A</u> into directory <u>B</u> | ||
− | : {{ | + | : {{l/cmd|mv}} <u>A</u> <u>B</u> |
; To copy the directory <u>A</u> into directory <u>B</u> (so you end up with <u>/B/A/''contents-of-A''</u>) | ; To copy the directory <u>A</u> into directory <u>B</u> (so you end up with <u>/B/A/''contents-of-A''</u>) | ||
− | : {{ | + | : {{l/cmd|cp}} -dpR <u>A</u> <u>B</u> {{faint|don't follow symbolic links, preserve attributes, recursive}} |
− | : {{ | + | : {{l/cmd|cp}} -a <u>A</u> <u>B</u> {{faint|-a is an alias for -dpR}} |
; To copy the ''contents'' of <u>A</u> into <u>B</u> (so you end up with <u>B/''contents-of-A''</u>) | ; To copy the ''contents'' of <u>A</u> into <u>B</u> (so you end up with <u>B/''contents-of-A''</u>) | ||
− | : {{ | + | : {{l/cmd|cp}} -a <u>A</u>/* <u>B</u> {{faint|this has not been tested!}} |
; To remove everything, including subdirectories, from the current directory (careful!) | ; To remove everything, including subdirectories, from the current directory (careful!) | ||
− | : {{ | + | : {{l/cmd|rm}} -r * {{faint|confirms each file before deleting}} |
− | : {{ | + | : {{l/cmd|rm}} -rf * {{faint|deletes all files/directories without asking}} |
==Notes for DOS refugees== | ==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. | + | Some command utilities in [[DOS]] (e.g. xcopy) used a convention wherein a trailing backslash on a name (e.g. <tt>c:\name\</tt>) 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 {{ | + | For {{l/cmd|mv}} and {{l/cmd|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. |
Latest revision as of 23:04, 13 November 2022
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.