In this article you will learn about directories and file names in Unix with examples. You will also learn associated commands with directories and file names in Unix like ls, pwd, mkdir, cd and du.
All the files in the system will have unique names. When we try to print the list of files and/or directories in the current directory, it will not display the absolute path of the file/directory. It will only print the file/directory names as shown below:
This is because every process like ls will have current working directory, and all filenames are implicitly assumed to start with the name of that directory. We can print the current working directory by using the pwd command as shown below:
The current directory is an attribute of a process, not a program. The notion of current directory is purely for organizational purposes. We can create a directory in the current working directory using the mkdir command as shown below. After creating your directory you can move into that directory using the cd command as shown below:
The du (disc usage) command can be used to find out how much space is consumed by the files in the current directory and subdirectories as shown below:
The number at the starting of each line represents the number of disk blocks occupied by each file/directory. The character ‘.’ (dot) represents the current directory and ‘..’ represents parent directory. The directory / is called the root of the file system. Every file in the system is in the root directory or one of its subdirectories, and the root is its own parent directory.
I hope you enjoyed this article. You will learn about Unix directory hierarchy and inodes in the coming articles.
For additional information you can visit the following links:
Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.
He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.
He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.
Leave a Reply