Working With Files and Directories

These commands can be used to: find out information about files, display files, and manipulate them in other ways (copy, move, delete).

Linux Command DOS Command Description
file Find out what kind of file it is.
For example,

file /bin/ls

tells us that it is a Linux executable file.

cat type Display the contents of a text file on the screen.
For example:

cat mp3files.txt

would display the file we created in the previous section.

head Display the first few lines of a text file.
Example:

head /etc/services
tail Display the last few lines of a text file.
Example:

tail /etc/services
tail -f Display the last few lines of a text file, and then output appended data as the file grows (very useful for following log files!).
Example:

tail -f /var/log/messages
cp copy Copies a file from one location to another.
Example:

cp mp3files.txt /tmp

(copies the mp3files.txt file to the /tmp directory)

mv rename,
ren,
move
Moves a file to a new location, or renames it.
For example:

mv mp3files.txt /tmp

(copy the file to /tmp, and delete it from the original
location)

rm del Delete a file.
Example:

rm /tmp/mp3files.txt
mkdir md Make Directory.
Example:

mkdir /tmp/myfiles/
rmdir rd,
rmdir
Remove Directory.
Example:

rmdir /tmp/myfiles/