- Chapter 3 Navigating the Linux File System
- Changing Directories with the cd Command
- Listing Directories
- Viewing Text Files
- Creating Files and Directories
- Copying Files and Directories
- Moving and Renaming Files and Directories
- Creating Symbolic Links
- Deleting Files and Directories
- Finding Files and Directories
- Using the GNOME gmc Client
- Using the KDE File Manager kfm
- Searching Text Files
Creating Files and Directories
Creating files and directories is an integral part of organizing your data while using Linux. The following sections show you how to create files and directories, so you can later copy, move, and organize your information.
Using touch to Create and Update Files and Directories
The touch command is used to create or update files and directories. Use touch with a new filename to create a file, or use an existing filename to update the file's access and modification times. For example, the following command line uses touch to create three files:
$ touch file1 file2 file3
Use ls -l to check the modification time of a file, like this:
$ ls -l *.txt -rw-rw-r-- 1 michael users 12 Jan 25 12:38 friends.txt
In the following lines, the touch command is used to update the friends.txt file's access and modification time to be four days more recent:
$ touch friends.txt $ ls -l *.txt -rw-rw-r-- 1 michael users 12 Jan 29 16:14 friends.txt
The touch command is useful to quickly create files, and can be used by other programs during system-management tasks (such as backups). For more information, see the touch manual page.
Creating Directories with the mkdir Command
The mkdir (make directory) command is used to create directories. Use mkdir with a directory name on the command line. For example, the following command line creates a directory called homework:
mkdir can also be used to quickly create a hierarchy of directories. Use the -p (parent) command-line option to create each directory required in the structure (existing directories will not be overwritten):
$ mkdir -p homework/compsci/linux/kernal_hacking/