Linux File System

Meng Lin, in 02 February 2019
Working with Linux/Unix system is a pleasant experience, even though it requires a slightly steeper learning curve in the beginning. in comparison to Windows, it is totally worthwhile. For those who just started working with Linux/Unix system or wants to know more, I found it useful to understand a few basic concepts, at least I knew that when I started.

Directory is a file

Hardly surprising, every OS would have the concept of directory or folder of some short, which is a recursive structure existed for the purpose of storing more directories or files. This has some interesting implications: each directory has two special files named . and .., where the single dot refers to the current directory itself, the double-dot means the parent of the current directory.

So, what’s the maximum allowed depth of sub directories in different OS? I will leave that to you to find out.

A summary of system directories

In a typical Linux/Unix system, you can normally see the following directories:

Linux file system
Linux file system

I will list out a few commonly used directories for your reference:

Every directory listed here, except “home”, requires administrator privilege to access. For normal system user, it has access and normally only operates under its own directory under “home”.

Hidden files

Files, begin with “.” in the name, are hidden files. Most of the hidden files contain configurations, such as “.bash_history”, it contains a list of command used.

Useful commands

The true potential of Linux/Unix system being a productivity boost can be unleashed with an effecient use of commands.

Navigation:

cd / // go to root folder
cd .. // go to the parent folder
pwd // find out absolute path of the current directory

List directory content:

ls // list the content of current directory
ls -lsa // list all files, including hidden files (-a), with file attributes (-l) and size of each file (-s)

Make a file:

touch file // make an empty file named "file"

Make a directory:

mkdir dir // make a directory called "dir"

Make a directory tree:

mkdir -p temp/sub1 // make the directory "temp" with a sub-directory "sub1"

Copy files and directories:

cp current target // copy "current" file to a file called "target"
cp -R current_dir target_dir // copy "current_dir" directory and its files and subdirectories to a directory called "target_dir"

Move/rename files and directories:

mv current target // rename "current" file to "target"
mv current ../target // move "current" file to "target" file in the parent directory
mv current_dir target_dir // rename "current_dir" directory to "target_dir"

Remove files and directories:

rm file // remove "file"
rm -r dir // remove "directory" and all its content

Important: because rm removes the file permanently, think twice before removing it. Alternatively, use a softer approach with option -i, or create an alias for rm to it moves files to a trash bin, and clean it afterwards.

By now, you should be good to go explore the fascinating Linxu/Unix system for yourselves.