Linux/Unix command line: part 3 - managing files
Sunday, December 10, 2006 8:54:27 PM
Let's start by making a directory. But let's first make sure that you're in your home directory:
cd
Let's keep home directory and make a directory for our experiment and move to our new directory:
mkdir experiments cd experiments
So mkdir is command for making directories. That directory is bit empty, let's create some content.
touch foo
Check if the file is really there:
ls
Curious? Let's look inside.
cat foo
Nothing happened. Don't worry though, the file is empty so there was nothing to display. That's what touch does, creates empty files and that's fine for our experiments. Let's continue by creating another directory:
mkdir bar
Now move previously created file to new directory and enter that directory:
mv foo bar cd bar
Another command again, mv is for moving files.
Oops, we need that file in it's original location too, let's make a copy:
cp foo ..
Make sure that the file is really there:
ls ..
Were done with this directory, let's move back:
cd ..
Let's make copy of a directory:
cp bar test
Didn't work? I guess we missed something:
cp -r bar test
It works now. You need to tell cp that you want to copy whole directory (and all it's files as a side effect). Let's check if everything is OK:
ls test
We're done now, let's clean up.
cd .. rm experiments
Same mistake again. Let's fix that:
rm -r experiments
Now you should know how to manage your files. And as always, read the manuals if you wan't to know more about commands, most have all kinds of options that could come handy sooner or later.







