<<

Filesystem Commands

Note Packet # 8

CSN 115 – Operating Systems Ken Mead Genesee Community College

Commands in this chapter

These are the basic commands for the chapter: (create) a – remove (delete) an empty directory directories/files from one location to another (or rename) files/directories – remove directories or files

mkdir mkdir (makes a directory) MS-DOS equivalent command: mkdir or md

General form:

mkdir

where is a directory in relative or absolute form.

Notes: mkdir -p

will create any missing parent directories below current directory.

mkdir examples mkdir (makes a directory) Examples: a. ~; mkdir sampdir b. cd sampdir; mkdir subdir1 . cd ..; mkdir sampdir/subdir2 d. mkdir sampdir/one/two (fails) e. mkdir -p sampdir/one/two (works)

rmdir rmdir (removes an empty directory) MS-DOS equivalent command: rmdir

General form:

rmdir

where dir is a directory in relative or absolute form.

Notes: You do not have to know any switches associated with rmdir.

rmdir examples rmdir (removes an empty directory) Examples:

$ cd; rmdir sampdir (fails, why?)

$ cd sampdir $ rmdir subdir1

$ rmdir one (fails, one not empty) $ rmdir one/two $ rmdir one

cp cp (copy files) MS-DOS equivalent command: copy

General form: cp cp

where file1 and file2 are files, and dir is a directory

Notes: You can use wildcards * and ?, and patterns [a-m] with the cp command. A useful switch for the cp command is -r (recursive copy) .

cp examples

Examples. Note: the (.) means current directory. $ cd ~/sampdir $ cp /usr/bin/ . (copies cal from /usr/bin to current directory). $ cp cal car (copies cal to car)

$ cp /usr/bin/ba* . (copies files in/usr/bin starting with ba to sampdir.)

$ cp /usr/share/zsh . (fails, zsh is a directory)

$ cp -r /usr/share/zsh . (works, recursively copy the zsh directory)

mv mv (move files) MS-DOS equivalent commands: and move General form: mv mv

where file1 and file2 are files, and dir is a directory

Note: You can use wildcards * and ?, and patterns [a-m] with the mv command.

mv examples

Examples: $ cd ~/sampdir;

$ mv smash (renames bash as smash)

$ mv car zsh (moves car into the zsh directory)

$ mv bas* zsh (moves car into the zsh directory)

$ mv zsh zeesh (renames the zsh directory)

$ cd zeesh; mv *64* .. (moves files to parent directory)

rm rm (remove files) MS-DOS equivalent commands: and General form: rm rm -r

rm -rf (dangerous)

Notes: You can use wildcards * and ?, and patterns [a-m] with the rm command. Useful switches for the rm command are -r (recursive move) and -f (force -- don't ask me if I really want to remove this .)

rm examples

Examples: $ cd ~/sampdir $ rm cal

$ rm *[0-9]* (removes files with a number in the name)

$ rmdir zeesh (fails, not empty) $ rm zeesh (fails, not a file)

$ rm -r zeesh (works, recursive remove).

A few commands

A few more useful commands: - shows the disk usage in the directory - shows the system disk usage – displays a file or concatenates multiple files. - sorts the contents of a file (or a piped command) – displays the first few lines of a file (default = 10) – displays the last few lines of a file (default = 10) - displays a user's history of commands – creates an empty file, or changes the timestamp of an existing file date – displays or modifies the current date cal – displays a monthly or annual calendar