13.MANAGE FILES FROM THE COMMAND LINE


To Learn how to manage files from
The filesystem hierarchy of Linux operating systems.

Do you remember what do you normally see when you open MyComputer in windows? There you can see all the storage drives (with each partitions of the device)  that you have mounted to the system.

But in Linux, when you open MyComputer you will see only the drives not the partitions. When you open the file system inside it, you will reach in to the root of the file system and it is called '/'.

'/' itself is a mount point where the root partition is mounted, and you can mount any other partitions anywhere inside the root partition by creating a new folder or a folder already existing inside.

Here is a small description about the directories present in the root directory.

/ -> the root of the filesystem
/etc ->the place where most of the configuration files are kept.
/usr -> user related executable and binary files
/var -> contains regularly changing system files such as mails and logs
/lib -> library files
/bin -> executable
/sbin -> administrative commands (some)
/root -> home directory of root user
/home -> home directories of all other users
/temp -> stores temporary data
/boot -> boot loader, kernel and other loaders configuration files
/dev ->files representing had wares
/media-> where removable media is loaded
/sys and /proc -> created and managed by the kernel(os)

When ever you are managing a file, you have to give the filename with path.
Path of a file can be an absolute path or a relative path.
absolute path is the complete path starting with /. You can give this path from anywhere in the system.
relative path is the path related to the present working directory.

for example:

Suppose your present working directory is '/home/alimajaf'
if you want to open a file '/home/alimajaf/document/myresume.doc' you can use either of the two options given below
1. using absolute path : cat  /home/alimajaf/document/myresume.doc
2. using relative path cat document/myresume.doc  --> since you are in the directory /home/alimajaf



here are some basic commands used to manage files
-------------------------------------------------
cd -> to navigate through directories
ls -> to list content of a directory
pwd-> to display the current working directory
cp -> to copy and paste a file
ln -s -> to create a shortcut
mv -> to cut and paste a file
rm -> t delete a file
rm -rf -> to remove a directory and its contents
touch -> to create an empty file
mkdir -> to create a directory
rmdir -> to remove an empty directory

Now read the man page of all these commands and be expert on these commands.
Do you know how to read man page?

Simple!! if you need the man page of ls command
type

man ls

that's it.


While Using relative path for a file you can use some sybols as given below
---------------------------------------------------------------------------
The path will be taken as the present working directory as the base.

.. means the one step up from the pwd
. means the pwd
- means the previous working directory
~ means the home directory (~mak means mak's home ie, /home/mak)

example:
Let's take the previous example itself.
if you want to read /home/policy.doc being in the /home/alimajaf itself you can use the following command
cat ../policy.doc --> it says go one step up form the present working directory and read the file policy.doc

For searching a file in a directory you can use wildcards
---------------------------------------------------------

eg:- ls *txt*
will list all the files with txt in their names from pwd