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: mkdir – make (create) a directory rmdir – remove (delete) an empty directory cp – copy directories/files from one location to another mv – move (or rename) files/directories rm – remove directories or files
mkdir mkdir (makes a directory) MS-DOS equivalent command: mkdir or md
General form:
mkdir
where dir is a directory in relative or absolute form.
Notes: mkdir -p
mkdir examples mkdir (makes a directory) Examples: a. cd ~; mkdir sampdir b. cd sampdir; mkdir subdir1 c. 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
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
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 dot (.) means current directory. $ cd ~/sampdir $ cp /usr/bin/cal . (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: ren and move General form: mv
Note: You can use wildcards * and ?, and patterns [a-m] with the mv command.
mv examples
Examples: $ cd ~/sampdir; ls
$ mv bash 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: del and deltree General form: rm
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 file.)
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 more commands
A few more useful commands: du - shows the disk usage in the directory df - shows the system disk usage cat – displays a file or concatenates multiple files. sort - sorts the contents of a file (or a piped command) head – displays the first few lines of a file (default = 10) tail – displays the last few lines of a file (default = 10) history - displays a user's history of commands touch – 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