Linux Files
In Linux system, everything is a file and if it is not a file, it is a process. A file doesn’t include only text files, images and compiled programs but also include partitions, hardware device drivers and directories. Linux consider everything as as file.
Files are always case sensitive. Let’s understand it through an example.
In above example, we have two files named as ‘Demo.txt’ and ‘demo.txt’. Although, they both share the same name but still they are two different files.
Types of Files:
- Regular files (-): It contain programs, executable files and text files.
- Directory files (d): It is shown in blue color. It contain list of files.
- Special files
- Block file (b)
- Character device file (c)
- Named pipe file (p)
- Symbolic link file (l)
- Socket file (s)
Linux File Commands
Command | Description |
---|---|
file | Determines file type. |
touch | Used to create a file. |
rm | To remove a file. |
cp | To copy a file. |
mv | To rename or to move a file. |
rename | To rename file. |
Creating Directory
Now let’s learn how to create your own directory with the help of command prompt.
The mkdir stands for ‘make directory’. With the help of mkdir command, you can create a new directory wherever you want in your system. Just type “mkdir <dir name> , in place of <dir name> type the name of new directory, you want to create and then press enter.
Syntax:
- mkdir <dirname>
Example:
- mkdir created
In above example, I am in /home/sssit directory. I have made a directory ‘created’ by passing command “mkdir created”.
Now if i’ll try to create a new file with the same file name ‘created’ that technically already exists, I’ll get an error message.
Note: If you will not provide a path then by default your file will be created in your current directory only. If you want to create your directory some where else, then provide the path of your destination directory and your file will be created there.
To make multiple directories
Syntax:
- mkdir <dirname1> <dirname2> <dirname3> …
You can also create multiple directories simultaneously. Look the example above, we have created multiple directories ‘file1 file2 file3’ .
Mkdir Options
Options | Description |
---|---|
mkdir -p, -parents | Add directory including its sub directory. |
mkdir -v, -verbose | Print a message for each created directory. |
mkdir -m -mode=MODE | Set access privilege. |