We use DNS (domain name system) to translate between domain names and IP addresses. For example, one can use the dig command/host command for DNS lookup on a Linux and Unix-like systems. Similarly, Linux files are referred by file names, not by inode number. So what is the purpose of a directory? You can group the files according to your usage. For example, all configuration files are stored under /etc/ directory. So the purpose of a directory is to make a connection between file names and their associated inode number. Inside every directory, you will find out two sub-directories named:
- . (single period) – The current directory
- .. (double period) – The pointer to previous directory i.e. the directory immediately above the one I am in now. The ‘..‘ appears in every directory except for the root directory. The ‘..‘ always points to the same inode as ‘.‘
Use the ls command to list files and directories including . and .. directories on Linux or Unix:
ls -la
Find the . and .. directories on Linux or Unix-like systems using the ls command
Directory
A directory contained inside another directory is called a sub-directory. At the end the directories form a tree structure. Use the tree command to see directory tree structure:
$ tree /etc | less
- There is an upper limit of 32768 subdirectories in a single directory
- There is a “soft” upper limit of about 10-15k files in a single directory
- Ext4 and other modern Linux file systems allows an unlimited number of subdirectories
However according to official documentation of ext2/3 file system points that using a hashed directory index (which is under development) allows 100k-1M+ files in a single directory without performance problems. Here are my two favorite bash shell alias commands related to directory :
alias ..='cd ..'
alias d='ls -l | grep -E "^d"'
Command | Description | Example(s) |
---|---|---|
mkdir command | Creates a new directory | mkdir dir1 |
rmdir command | Deletes the specified directory if it is already empty | rmdir dir1 |
cd command | Change the current directory | cd /etc/ |
cd .. command | Go back to previous directory | cd .. |
pwd command | Display name of current/working directory | pwd |
cd command | cd without any parameters changes to the user’s home directory | cd |
mv command | Copies source to target then deletes the original source | mv dir1 dir2 |
cp command | Copies source to target | cp -r dir1 /path/to/dir2 |
rm command | Removes the specified files from the file system. Directories are not removed by rm unless the option -r is used | rm file1 rm -r dir1 |
ln command | Creates an internal link from source to target | ln -s /etc/hosts /tmp/link |
chown command | Transfers ownership of a file to the user with the specified username | chown userName file |
chgrp command | Transfers the group ownership of a given file to the group with the specified group name | chgrp dir1 |
chmod command | Changes the access permissions | chmod 0444 dir1 |
locate command | The locate command can find in which directory a specified file is located | locate file1 |
find command | Search for a file in a given directory | find $HOME -name "hello.c" |
file command | Detect the contents of the specified files | file /etc/resolv.conf |
cat command | Displays the contents of a file | cat data.txt |
less command | See the contents of the specified file | less resume.txt |
more command | It is a filter for paging through text one screenful at a time | more /etc/hosts |
grep command | Finds a specific search string in the specified files | grep "nameserver" /etc/resolv.conf |
egrep command | Same as grep but extended regular expression supported | egrep -i 'err|cri|warn|' /var/log/messages |
diff command | Compares the contents of any two files | diff old.c new.c |
I am sure all of you know the basic commands related to directories and files management. Click the link on the left column to learn more about each command and same usage.
- Understanding UNIX / Linux File System
- Understanding UNIX / Linux filesystem directories
- Understanding the Linux file system directories / hierarchy
- Understanding UNIX / Linux filesystem Superblock
- Understanding filesystem Inodes
- What is a hard and symbolic (soft) link in Linux or Unix?
- Why isn't it possible to create hard links across file system boundaries?
- Surviving a Linux Filesystem Failures
- Linux / UNIX Delete or Remove Files With Inode Number
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 5 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
alias d=’ls -ld */’
Heya,
the correct command to go back to previous directory (as seen in table graphic) should be
cd –
not
cd ..
cd .. go to parent directory
cd – return to previous directory
Hi,
Thx for the useful information abt the ext2 filesystem. What I want to find out is, whether any website is avbl for finding the detailed structure of a superblock ? i.e., all the fields that the superblocks stores, their valid contents, when are they changed, how r they affected when a file is changed etc…
Thanks a lot in advance.
-Swapnil
Nguyen,
Glad to know article is helping out.
Appreciate your feedback.
Thanks alot.This article is very useful for my project call “Describe the files and directory model in Linux?UNIX”