Making Files and Folders
Shivm Soaini
Math Major Turned AI Enthusiast: Mastering Computer Vision | Building Robust Python Code | Delving Deep into the Math of AI | Sharing Knowledge Through Writing | Ready to Transform Ideas into Reality
The touch command
To create a new file from the command line, use the touch command. Provide a filename, and that file will be created for you (assuming it doesn't already exist).
For example, touch chicken.txt would create a chicken.txt file in the current directory.
If you try to use touch with a file that already exists, it will simply update the access and modification dates to the current time.
touch <filename>
We can also create multiple files with the touch command in one line.
touch <file1> <file2> <file3> <file4>
The file command
The file command can be used to determine the file type of a specified file. It's honestly not that important!
You can try it out.
For example, running file contract.pdf will tell us the file type like
"contract.pdf: PDF document, version 1.4"
领英推荐
Note, it does not use the file extension to "decide" on the file type. We could have a PDF file named "app.png".
According to the man page for file command,
"file tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic tests, and language tests. The first test that succeeds causes the file type to be printed."
You can read the full description using man file command.
file <filename>
The mkdir command
To create new directories, we use the make directory (mkdir) command. We provide one or more directory names, and it will create them for us.
For example, to create two new folders, images and styles, we could run mkdir images styles.
mkdir <foldername>
We can also make nested directories with the help of -p or --parents option to the mkdir command.
In this example, we are creating the "Horses" directory and another directory "Mares" nested within it.
Thanks for reading : )