Introduction to Linux - 3.3.2. Creating and deleting files and directories
< Continued from page 1
to give certain files specific default locations by creating directories and subdirectories (or folders and sub-folders if you wish). This is done with the mkdir command:
Creating directories and subdirectories in one step is done using the -p option:
If the new file needs other permissions than the default file creation permissions, the new access rights can be set in one move, still using the mkdir command, see the Info pages for more. We are going to discuss access modes in the next section on File Security.
The name of a directory has to comply with the same rules as those applied on regular file names. One of the most important restrictions is that you can't have two files with the same name in one directory (but keep in mind that Linux is, like UNIX, a case sensitive operating system). There are virtually no limits on the length of a file name, but it is usually kept shorter than 80 characters, so it can fit on one line of a terminal. You can use any character you want in a file name, although it is advised to exclude characters that have a special meaning to the shell. When in doubt, check with Appendix C .
Now that we have properly structured our home directory, it is time to clean up unclassified files using the mv command:
This command is also applicable when renaming files:
It is clear that only the name of the file changes. All other properties remain the same.
Detailed information about the syntax and features of the mv command can be found in the man or Info pages. The use of this documentation should always be your first reflex when confronted with a problem. The answer to your problem is likely to be in the system documentation. Even experienced users read man pages every day, so beginning users should read them all the time. After a while, you will get to know the most common options to the common commands, but you will still need the documentation as a primary source of information. Note that the information contained in the HOWTOs, FAQs, man pages and such is slowly being merged into the Info pages, which are today the most up-to-date source of online (as in readily available on the system) documentation.
Copying files and directories is done with the cp command. A useful option is recursive copy (copy all underlying files and subdirectories), using the -R option to cp . The general syntax is
cp [-R ] fromfiletofile
As an example the case of user newguy , who wants the same Gnome desktop settings user oldguy has. One way to solve the problem is to copy the settings of oldguy to the home directory of newguy :
This
to give certain files specific default locations by creating directories and subdirectories (or folders and sub-folders if you wish). This is done with the mkdir command:
richard:~>mkdir archiverichard:~>ls -ld archive drwxrwxrwx 2 richard richard 4096 Jan 13 14:09 archive/
Creating directories and subdirectories in one step is done using the -p option:
richard:~>cd archiverichard:~/archive>mkdir 1999 2000 2001richard:~/archive>ls 1999/ 2000/ 2001/richard:~/archive>mkdir 2001/reports/Restaurants-Michelin/ mkdir: cannot create directory '2001/reports/Restaurants-Michelin/': No such file or directoryrichard:~/archive>mkdir -p 2001/reports/Restaurants-Michelin/richard:~/archive>ls 2001/reports/ Restaurants-Michelin/
If the new file needs other permissions than the default file creation permissions, the new access rights can be set in one move, still using the mkdir command, see the Info pages for more. We are going to discuss access modes in the next section on File Security.
The name of a directory has to comply with the same rules as those applied on regular file names. One of the most important restrictions is that you can't have two files with the same name in one directory (but keep in mind that Linux is, like UNIX, a case sensitive operating system). There are virtually no limits on the length of a file name, but it is usually kept shorter than 80 characters, so it can fit on one line of a terminal. You can use any character you want in a file name, although it is advised to exclude characters that have a special meaning to the shell. When in doubt, check with Appendix C .
3.3.2.2.2. Moving files
Now that we have properly structured our home directory, it is time to clean up unclassified files using the mv command:
richard:~/archive>mv ../report[1-4].doc reports/Restaurants-Michelin/
This command is also applicable when renaming files:
richard:~>ls To_Do -rw-rw-r-- 1 richard richard 2534 Jan 15 12:39 To_Dorichard:~>mv To_Do donerichard:~>ls -l done -rw-rw-r-- 1 richard richard 2534 Jan 15 12:39 done
It is clear that only the name of the file changes. All other properties remain the same.
Detailed information about the syntax and features of the mv command can be found in the man or Info pages. The use of this documentation should always be your first reflex when confronted with a problem. The answer to your problem is likely to be in the system documentation. Even experienced users read man pages every day, so beginning users should read them all the time. After a while, you will get to know the most common options to the common commands, but you will still need the documentation as a primary source of information. Note that the information contained in the HOWTOs, FAQs, man pages and such is slowly being merged into the Info pages, which are today the most up-to-date source of online (as in readily available on the system) documentation.
3.3.2.2.3. Copying files
Copying files and directories is done with the cp command. A useful option is recursive copy (copy all underlying files and subdirectories), using the -R option to cp . The general syntax is
cp [-R ] fromfiletofile
As an example the case of user newguy , who wants the same Gnome desktop settings user oldguy has. One way to solve the problem is to copy the settings of oldguy to the home directory of newguy :
victor:~>cp -R ../oldguy/.gnome/ .
This