CHAPTER 8. Linux Files and Directories
If you're going to get stuff done on Linux, especially using the command line, you'll need a solid sense of where files are kept and how to work with them. The good news is that figuring all that out isn't as hard as it might seem. In this chapter, we're going to learn some basic file and directory administration skills, explore some powerful tools you can use to search for both files and text strings contained within those files, and then manipulate the data you find. Moreover, you will learn how to create and use compressed data archives, and then identify hardware peripherals on your system and if required, enable the kernel modules you'll need to use your devices. 
When identifying directory trees, you can use the forward slash. Thus, the absolute address of a directory called scripts in your home directory would be “/home/ubuntu/scripts” where Ubuntu is the name of your account. If you would preface the tree with “cd”, which stands for change directory, you would move to that directory. Once you ready, just try it out; Type the command: “pwd”, which stands for present work directory, and you will see your new directory location displayed. To make it easier to understand the basic Linux file and directory management commands, create a new directory and populate it with some useless stuff. The command “mkdir” will make a directory called “data.” list the contents of the parent directory to show the new subdirectory and then change location to that directory. To create a few files, you can launch the text editor “nano” followed by the name of either an existing or a new file. In this case, it'll be “new”. You can enter some text and then type Ctrl and “X” and then “Y” to save and exit. “File1” now should exist. A quick way to create empty files with unused names is through “touch”. Using “touch” on an existing file will simply update the date timestamp of the file, which can be useful for some administrative purposes. You can hit the up arrow and raise the number a few times to make it easier to create a few more files. Once you have a series of empty numbered files, let's create a new directory within data and call it “newdata”. If you would want to copy files to “newdata”, you can use “cp”. This will create a copy of the “file1” file. But it would be boring to have to repeat that command for each of the files in your series, so you can use what's called “globbing”. The command “globbing” just a way of spreading an action across on a global target. So typing “cp file* new data” will copy all files that begin with file no matter what characters follow that string. Type “cd” to “newdata” to see what's there. The asterisk will cause a Linux command to act on any string starting with file no matter how many characters follow. However, you can also limit the action to a single character using the question mark. You can create a couple more files with longer names, and use “rm” with a question mark to delete or remove all files starting with “file”, but having only a single digit extra. You should see that some of your files are still there. If you were to use “rm file” with an asterisk, all files would be removed as well. Additionally, to move a file rather than just make a new copy, use the command “mv”. If you want to clean up your files, you can use the command “rm” and an asterisk to remove all the files in our “newdata” directory. Be careful with this because you can sometimes end up deleting a lot more than you expected, and you should definitely keep in mind the Linux terminal has no “trashcan” from which deleted files can be restored. You can “cd back up to data” and run “rm dir” to remove the “newdata” directory.