...
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 rmcp fdir2/*.txt . # deletecopy all the f*.txt files in the current "dir2" directory to this directory cp rm dir2/f*.txt . # copydelete all the f*.txt files in the "dir2" directory to thiscurrent 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 |
...
- Both cp and rm have a -r (recursive) option that is used when operating on directories.
- mkdir and rm also have a -f (force) option that does not report an error if the file, directory, or component of a directory path, doesn't exist.
- 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.
...