All your data is contained within files: office documents, songs, movies, etc. We present some commands to organize and manage those files.
ls (LiSt) is equivalent to the DOS command dir. Its syntax is as follows:
ls <directory>
-R
:
recursively list the contents of the directory and all its
subdirectories. Please note that before displaying a directory's
contents the name of the directory itself is shown.
-l
: use
a long listing format. Details about the file such as the file's
type, permissions, owner and size are displayed.
-a
:
show also hidden files. In UNIX
® systems, all files whose
names start with a period (.
) are hidden. Use
this option to show such files when listing a directory. If you
don't want the current directory and its parent (namely,
.
and ..
) to be displayed
use the -A
option instead.
ls -lA
/tmp/movies /tmp/images: list the contents of both the
movies
and images
directories inside the /tmp
directory,
displaying file details and hidden files, but not displaying the
.
and ..
entries for each
directory;
ls -R ~/: display, recursively, all the files and directories you have inside your personal directory.
cp (CoPy) is equivalent to the DOS commands copy and xcopy but has more options. Its syntax is as follows:
cp <file|directory> [file|directory ...] <destination>
cp -f
/tmp/images/* images/: copies all files in the
/tmp/images
directory to the
images
directory located in the current
directory. It doesn't request confirmation if a
file is going to be overwritten.
cp -vR docs/
/shared/mp3s/* mystuff/: copies the whole
docs
directory, plus all files in the
/shared/mp3s
directory to the
mystuff
directory, displaying all actions
performed.
cp foo bar: makes
a copy of the foo
file with the name
bar
in the current directory.
mv (MoVe) is equivalent to the DOS command move. Its syntax is as follows:
mv <file|directory> [file|directory ...] <destination>
Note that when you move multiple files the destination must be a directory. To rename a file you simply move it to the new name.
mv
/tmp/pics/*.png .: move all files in the
/tmp/pics
directory whose names end with
.png
to the current directory.
mv foo bar:
rename file foo
to bar
. If
a bar
directory already existed, the effect of
this command would be to move file foo
or the
whole directory (the directory itself plus all files and directories
in it, recursively) into the bar
directory.
mv -vf file* images/
trash/: move, without requesting confirmation, all files
in the current directory whose names begin with
file
, together with the entire
images
directory to the
trash
directory, and show each operation
carried out.
The rm command (ReMove) is equivalent to the DOS commands del and deltree, but has more options. Its syntax is as follows:
rm <file|directory>
rm
images/*.jpg file1: deletes all files with names ending in
.jpg
in the images
directory and deletes file1
in the current
directory.
rm -Rf images/misc/
file*: deletes, without requesting confirmation, the whole
directory misc
in the
images
directory, together with all files in
the current directory whose names begin with
file
.
mkdir (MaKe DIRectory) is equivalent to the DOS commands mkdir and md. Its syntax is as follows:
mkdir
Only the -p
option is worth noting. It does two things:
creates parent directories if they did not exist previously. Without this option, mkdir would just fail, complaining that these directories do not exist;
returns silently if the
directory you wanted to create already exists. If the
-p
option is not specified,
mkdir sends back an error message, complaining
that the directory already exists.
The current working
directory, symbolized by a period (.
), is the place
on the file system you are “standing onto”. The
double period (..
) symbolizes the parent directory of
the current one which is “one level up”(or back) on the
file system structure.
cd (Change Directory) lets you navigate the file system structure. Its syntax is as follows:
cd <directory>