Making Files and Folders

Making Files and Folders

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 : )

要查看或添加评论,请登录

Shivm Soaini的更多文章

  • Pipelines

    Pipelines

    Pipes are used to redirect a stream from one program to another program. We can take the output of one command and…

  • The Standard Streams and Redirection

    The Standard Streams and Redirection

    The three standard streams are communication channels between a computer program and its environment. They are:…

  • Working with Files

    Working with Files

    The cat command The cat command concatenates and prints the contents of files. cat filename will read the contents of…

  • The Shortcuts

    The Shortcuts

    We can speed up our command-line experience by taking advantage of the many built-in shortcuts. These shortcuts are…

  • Deleting, Moving and Copying

    Deleting, Moving and Copying

    The rm command We use the rm (remove) command to remove files from our machine. For example, rm app.

  • The Nano Text editor

    The Nano Text editor

    Nano is a simple text editor that we can access right from the terminal. It's far more accessible than other popular…

  • Navigating the CLI Sea

    Navigating the CLI Sea

    The root directory The starting point for the file system is the root folder. We call it the root, but its actual…

  • Getting Help in Command Line Interface

    Getting Help in Command Line Interface

    Sometimes it's difficult to wrap our head around some of the commands we encounter. In this scenario, man pages can…

  • First Step in Command Line

    First Step in Command Line

    Some Familiar Terms A Shell is a computer interface to an operating system which expose the OS's services to the human…

  • A Brief History of Linux

    A Brief History of Linux

    The world of operating systems has many residents, but they can be segregated into two tribes: The Microsoft NT…

社区洞察

其他会员也浏览了