Friday, 20 May 2011

Basic Linux commands – Part I. Working with Files

If you want to look like Lisbeth Salander you should know some of these. If you want to impress even more you could also buy the most expensive Apple laptop :)

There are some commands that you will use very often so it would be a good idea to learn something about them right now.
Each comand may have plenty of parameters, some of them really useful. To keep things simple, here is a quick look at what you really need to know.

cd –  Change directory
cd /home
Change the current working directory to /home.
If the directory name starts with “/” it indicates it is relative to the root, and no matter what directory you are in when you execute this command, the directory will be changed to "/home".
cd john
Change the current working directory to “john”, relative to the current location. If your current location is "/home", the full path of the new working directory is "/home/john".

cp –  Copy file
cp /some/directory/someFile /new/directory/newFile
This will copy the file someFile to newFile (someFile was placed in /some/directory and the new copy will be placed in /new/directory)

df –  Disk space
df
Displays the used and free disk space for all your disks.

mkdir – Create directory
mkdir /home/john
This creates the directory “john” in the directory “/home”. If the directory “/home” does not exist you will get an error.

rm – Delete file / directory
rm a.txt
Deletes the file a.txt from the current current working directory.
rm –r /home/john
Deletes the directory /home/john recursively

ls -  Short listing of directory contents
ls
Displays the contents for current working directory.
ls /home/john
Displays the contents for “/home/john” directory.

touch – Create file
touch /home/a.txt
This will create an empty file, “a.txt”, in the directory “/home”.
You won’t use that too much but you may see it in some tutorials so you should know what it means.

chmod - Change file access permissions
chmod 644 -R /home/john
Change permission to “/home/john” and all its files recursively.

chown - Change file owner and group
chown ftpuser:ftpgroup -R /home/john
Change the owner and group to ftpuser / ftpgroup for  “/home/john” and all its files recursively.

More about users and permissions should be available in a future post.

The next post will be about Installing and Uninstalling software.

No comments:

Post a Comment