Introduction
Linux is an open-source operating system. It is always developed collaboratively. Linux is one of the greatest ecosystems. That is for use from small digital wristwatches to servers and supercomputers.
In this article, we will attempt to become up to speed with the basics of Linux operating system. We can be overwhelmed by the view of controlling and navigating the file system of Linux from the command line, if we do not have much experience working with Linux systems.
Description
- Linux put in order files using a hierarchical system.
- Files are kept in directories.
- These directories may as well comprise other directories.
- We will find that there are no drive letters in Linux when compare the Linux filesystem to Windows.
- All files are put in storage in a single root directory.
- We also essential the information about the directory hierarchy well-known as the pathname to find a file in Linux.
- The pathname is self-possessed with a top-level directory, a directory hierarchy, and the filename with the file extension.
- All are divided by a forward slash (/).
Important special characters
This is essential for everyone to know about important special characters before getting into commands. They have special functionality in the Linux filesystem.
- The dot (.) stand for the current directory in the filesystem.
- The dot-dot (..) signifies one level above the current directory.
- The forward slash (/) symbolizes the root of the filesystem.
- Each directory or file in the Linux filesystem is nested under the root / directory.
- The tilde (~) stand for the home directory of the presently logged in user.
Linux top-level directories
Top-Level Directory | Files that the directory contains |
/ | Single root directory – file system base |
/bin | Executable files such as Linux commands cat, cp, ls |
/boot | Files that the boot loaders access during start-up – including the Linux kernel |
/dev | Files for the different hardware/devices |
/etc. | Initialization scripts and system config files |
/home | User directories |
/lib | Library files which includes driver modules |
/lost+found | For lost files |
/media | Mounting removal media filesystems |
/mnt | Temporary directory for mounted filesystems |
/opt | For storing application packages |
/proc | Information on Linux processes |
/root | Root user home directory |
/sbin | Executable files for commands that is used by root user |
/srv | For services hosted by the system (e.g. FTP, web) |
/tmp | Temporary directory – deleted during system reboot |
/usr | Contains subdirectories for program files |
/var | Log files |
Navigating the directories
We can use the following ways to navigate in the directories on Linux:
- Using the GUI to find a certain file by going through the folders.
- Using the universal text-based search function.
- By using the command line.
Useful Commands
Now we will discuss about significant commands in Linux operating system. These commands are our navigation tools inside the Linux filesystem. We may use the following valuable commands in our terminal to navigate and work in the file system:
Commands | What it does |
Is | List down all the contents of a director |
cd /bin/ | Changes directory and goes to bin dir |
cd ~ | the tilde (~) sign signifies the user’s home dir – change dir to home directory |
cd. | Means to change directory one level up. For instance, we are currently /home/edulaney/, using the command will take us to /home/ |
mkdir | A command used to create directories |
pwd | Short for present working directory. This command will display the directory where we are currently in. |
cat /home/edulaney/files/file1.txt | Command used to print all the contents of file1.txt in the screen |
cp /home/ /tmp/ | Copy contents of /home/ to /tmp |
mv /home/edulaney/files/file1.txt /tmp/ | Move the file file1.txt to the /tmp/ directory. We can also use this command to move the entire directory to another directory |
rm file1.txt | Delete the file file1.txt. Take extra precaution in using the rm command, especially when we are logged in as root. |
find / -name “linux*” | The find command is a powerful tool that we can use when searching using the command line. The command now will search for any file or directory with a name that starts with linux |
File and Directory Handling
Now we’ll demonstrate how to create and manipulate files and directories.
Create a File with touch
- Several commands and programs can create files.
- The basic method of creating a file is with the touch command.
- This would create an empty file using the name and location stated.
- We should first validate that we are in our home directory.
- This is a location where we have consent to save files.
- Then, we may create a file called file1 by typing:
cd
touch file1
- We can see newly created file if we view the files in our directory:
Ls
file1
- We can similarly create multiple files at the same time.
- We may use absolute paths as well.
- For example, if our user account is called demo, we could type:
touch /home/demo/file2 /home/demo/file3
ls
file1 file2 file3
Create a Directory with mkdir
- The mkdir command permits us to create empty directories.
- For example, to create a directory within our home directory named test, we could type:
cd
mkdir test
- For making a directory within the test directory called example by writing:
mkdir test/example
- The test directory must previously exist for the above command to work.
- We can use the -p option to tell mkdir that it should create any directories needed to construct a given directory path.
- This permits us to create nested directories in one step.
- We may create a directory structure that appearances like some/other/directories by typing:
mkdir -p some/other/directories
- The command would make the some directory initially.
- Then it would create the other directory inside of that.
- Lastly it would create the directories directory within those two directories.
Conclusion
We have presented the basic view of filesystem navigation and manipulation in Linux operating system. The best way to comprehend any concept is by putting it into practice. Therefore, we can further understand better the Linux file system with the help of described commands which are our navigation tools.