...
Here are some examples. Follow along if you can – and use the Tab key to help out! (See Tab key completion)
Expand | ||
---|---|---|
| ||
...
- touch to create a new, empty file or update the last modification date on an existing one
- mkdir to create a new directory
- cp to copy files (locally, within the current host computer)
- mv to move a file from one name to another (so rename the file)
- scp to securely copy files (to/from a remote computer)rm to remove (permanently delete) files and directories
Let's practice:
Code Block | ||
---|---|---|
| ||
cd # make sure you're in your Home directory mkdir tmp # create a new directory called "tmp" and change into it cd ./tmp # the "./" syntax is optional; means relative to current directory touch f1.txt # create empty file called "f1.txt" ls -l >> f1.txt # add some text by redirecting (appending) output from ls mv f1.txt f2.txt # rename the "f1.txt" file to "f2.txt" cp f2.txt f3.txt # copy "f2.txt" to a new file called "f3.txt" in this directory mkdir dir2 # make a new "dir2" sub-directory mv *.txt dir2/ # move the "f2.txt" and "f3.txt" to the "dir2" sub-directory rm f*.txt # delete all f*.txt files in the current directory cp dir2/*.txt . # copy all the *.txt files in the "dir2" directory to this directory cp -r dir2/ dir3/ # copy the "dir2" directory and its contents to a new "dir3" directory rm dir3/f3.txt # delete the "f3.txt" file from the "dir3" directory rm -rf dir2 # delete the "dir2" sub-directory and its contents |
Notice:
- Both cp and rm have a -r (recursive) option that is used when operating on directories.
- It is a good idea to specify directory names with a trailing slash ( / ) to indicate that they are directories
- The "./" syntax means "relative to the current directory". It's optional but explicit.
See the Create, rename, linkto, delete files and Copying files and directories sections of the Some Linux commands page for more information.