The Unix File System: A Comprehensive Guide for Beginners and Pros
Introduction
Listing files and directories
Creating and deleting files and directories
Copying and moving files and directories
Permissions and ownership
Links and symlinks
Conclusion
Introduction
The Unix file system is a hierarchical system that organizes files and directories into a tree-like structure. It is a powerful and flexible system that is used in a wide variety of operating systems, including Unix, Linux, and macOS.
In this blog post, we will explore some of the most important commands used to manage the Unix file system. We will also learn about some of the key concepts of the Unix file system, such as permissions, links, and symlinks.
Listing files and directories
Web servers: Web servers use the Unix file system to store the web pages and other resources that are served to web browsers.
Databases: Databases use the Unix file system to store database files, which contain the data that is stored in the database.
The
ls
command is used to list the contents of a directory. By default, thels
command will list all of the non-hidden files and directories in the current directory. To list hidden files and directories, use the-a
option.ls -a
To list the contents of a specific directory, specify the path to the directory after the
ls
command.ls /tmp
To list the contents of a directory in a long format, use the
-l
option. This will list information such as the file size, permissions, and date and time of modification.ls -l
Creating and deleting files and directories
The
touch
command is used to create a new file. If the file already exists, thetouch
command will update the timestamp of the file.touch myfile.txt
The
mkdir
command is used to create a new directory.mkdir mydir
The
rm
command is used to delete a file.rm myfile.txt
The
rmdir
command is used to delete a directory.rmdir mydir
Copying and moving files and directories
The
cp
command is used to copy a file or directory. To copy a file, specify the source file and the destination file after thecp
command. To copy a directory, specify the source directory and the destination directory after thecp
command.cp myfile.txt mydir/myfile.txt
cp -r mydir mynewdir
The
mv
command is used to move a file or directory. To move a file, specify the source file and the destination file after themv
command. To move a directory, specify the source directory and the destination directory after themv
command.mv myfile.txt mydir/myfile.txt
mv mydir mynewdir
Permissions and ownership
Every file and directory in the Unix file system has a set of permissions that determine who can read, write, and execute the file or directory. The permissions are divided into three categories:
Owner: The owner of the file or directory has the highest level of permissions.
Group: The group of the file or directory has the next highest level of permissions.
Other: The other users of the system have the lowest level of permissions.
You can use the chmod
command to change the permissions of a file or directory.
chmod 755 myfile.txt
The number 755
represents the following permissions:
Owner: read, write, and execute
Group: read and execute
Other: read and execute
more generally, the read command has an octal value of four, the write command has an octal value of two and the execute command has an octal value of one
You can use the chown
command to change the ownership of a file or directory.
chown myuser myfile.txt
This will change the ownership of the file myfile.txt
to the user myuser
.
Links and symlinks
A link is a special file that points to another file. When you access a link, the system will automatically access the file that the link points to.
To create a link, use the ln
command.
ln myfile.txt mylink.txt
This will create a link to the file myfile.txt
named mylink.txt
.
A symlink is a special type of link that points to a file or directory that may not exist. When you access a symlink, the system will check to see if the file or directory that the symlink points to exists. If it does not exist, the system will return an error.
To create a symlink, use the ln -s
command.
ln -s myfile.txt mysymlink.txt
This will create a symlink to the file myfile.txt
named mysymlink.txt
.
Conclusion
The Unix file system is a powerful and flexible system that is used in a wide variety of operating systems. By understanding the basic commands and concepts of the Unix file system, you will be able to manage your system files without the use of an operating system which will ease your work from constantly moving the mouse on your machine.
Subscribe to my newsletter
Read articles from Assah Bismark directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Assah Bismark
Assah Bismark
hello everyone and greetings.i am assah Bismark a computer engineering student currently studying cloud based software engineering at clemios in partnership with adorsys,studying at the university of buea. i have knowledge in front end development using from works like react and vue.i really hope to get the most out of this community to extend my Carrier path collaborative with other in the field.