The UNIX Philosophy
We also went over file types and file paths, which is mostly covered as my keyword. There are two different file paths, an absolute path and a relative path.
An absolute path looks like this if you change directory: cd /home/name/src
A relative path would look something like this: cd src
That relative path would only work if you were in the /home/name directory (confirming that using the pmd command)
/lib - library files/functions. Libraries hold and reference to many smaller programs. ldd - command that lists the necessary functions to perform a command.
libc is the standard C library
/media - Directory for mounting file systems on removable media like CD-ROM drives, floppy disks, and Zip drives.
/mnt - where removable devices or temporary file systems are placed upon plug-in. Such as flash drives.
“Vi (pronounce: “vee eye”, not “six”, not “vye”) is an editor. An editor is a program to edit files. Goodbye.”
To launch Vi, just use the vi command. Use vi with a filename after it to open a file, in Vi Two modes..
Here are a few commands in no special order..
The colon : is extended command mode, which has some notable commands..
This day we went over the archiving and compression commands known as tar, which is the archiver and gzip, the compressor. The neat thing about having two commands for this process, you have the option to do one or the other, or both. If you've seen a .zip file before, that is an extension that indicates it was compressed AND archived. That limitation is that you cannot have one or the other through the means of a Windows program like WinZip or 7Zip. tar by definition, saves many files together into a single tape or disk archive and can restore individual files from the archive. Some worthy extensions may include..
gzip is the compression/decompression tool that is often used after archiving a file. Use gzip [filename] to compress your file Some worthy extensions that should be used accordingly..
In class we also went over the command last and eventually learned how to get personalized information through a super incantation.
The command last lists all the logins for a complete month, in the case of this day, it listed all the logins from the month of September. This will reset once it has become October. You can imagine this being a very hectic, long list but luckily we have some ways to get the information we need.
We can use a pager command such as more which will show a “page” full of lines being generated, and you press space to move onto the next page. You can also use less to list these pages in reverse (from the beginning of the month to end).
A command with the more or less commands must be an incantation through the use of the pipe | . Which would look something like this: last|more or last|less This can be useful but we want more specific information from the last command so we created a super incantation, which is the following.. echo “You logged in `last|grep $USER|wc -l` times this month” To break this down..
On the current day (9/30/2012), this incantation displays You logged in 28 times this month. This is really cool and all, but imagine if you had to type that every time you wanted to know how many times you've logged in? Let's get lazy!
We next learned how to make any file an executable or program. We can use the incantation we created above and just type it up into a file, or you can be even lazier, and type the incantation and direct its output into a new file by using a full quotation and adding another echo, like so: echo 'echo “You logged in `last|grep $USER|wc -l` times this month”' > login
This will display our incantation into a new file known as login or overwrite the existing file login.
And finally to make this a working program, we need to change the permissions which can be viewed using ls -l.
To change permissions, use the command chmod with the corresponding numbers 744: chmod 744 login
This will make our file a program and you can just run it using ./login assuming you are in the same folder, otherwise change the path accordingly.
The Regular, Directory, and Special File Types
Unlike most keywords, this one isn't just one simple keyword. A file type is a vague term that represents files, and in order to really know what one is, they should be defined, SUCH AS:
An important consideration when we're talking files is that each file has permissions for them that determine which users can Read, Write, or Execute a file. These are formally known as access modes. These access modes are often represented in this format: Eg. drwxrwxr– or srwxr—–
ls is a command for directory listing. What this mean is it lists all the contents of the directory in a curt manner. Usually just the names of the directories, files, and their file types by color coordination.
Home Directory
The Home Directory is basically the place that all of a user's files and folders are stored. From the home directory, one may be able to access all of their files, or just access specifically places files. The user is able to completely customize their home directory. When files and folders are in a home directory (including readable, writable, and executable files), they are only able to be accessed by the user or any other administrator on the system. That can be changed at any point, however.
Firstly, we identify where the home directory is. When you log in, you should be able to use the pwd command and boom, you it shows the absolute path of your home directory. Another way to ensure that it is YOUR home directory, you can use pwd $USER and the same result should display. Try that in another relative directory and you will get the same result every time, because $USER represents your username, which is mainly used to identify your home directory.
We can also change directory or cd to your home directory using an absolute path or a relative path if you are in the /home directory.
The home directory is the one directory where it's not recommended to even consider changing the Owner access controls.
One of the most useful things you can do related to your home directory is usage of the cd command in order to quickly return to it, from anywhere in the file system, including finding your way into another user's home directory, you can easily change back to yours with simply cd
And finally you can use ls to see what it looks like to verify that they are your directories.
Assume your username is rabidrabbit
Back to back demonstration..
lab46:~$ pwd /home/rabidrabbit lab46:~$ pwd $USER /home/rabidrabbit lab46:~$ cd / lab46:/$ cd /home/$USER lab46:~$ pwd /home/rabidrabbit lab46:~/src/submit$ cd lab46:~$ pwd /home/rabidrabbit lab46:~$ cd /home/tmong lab46:/home/tmong$ cd lab46:~$ pwd /home/rabidrabbit lab46:~$ ls Desktop Downloads Music Public Videos closet file.txt src Documents Maildir Pictures Templates archives data public_html
I notice we always archive a group of files before we compress. What would happen if we compressed these files individually first, then we archived them, would it still give us the same outcome?
I'll be using the information I learned from class to generate some sort of outcome from this, using the tar and gzip commands exclusively. Most of this information can be referred to my dated entries in this Opus.
I think that this will work normally. The archiving before compression feels like a good practice but doing it the other way feels taboo. At the end of this experiment, I think we will have the same files we created.
I plan on creating a directory for this experiment, to keep all my other stuff safe. Then I'll use the touch command to create 3 files and type in some information in them. Instead of normally using tar first, I'll proceed to compress each of these files, then I'll select them all for archiving. Once that is completed, I'll proceed to reverse this process and hopefully have the same 3 files and the information within them in tact.
lab46:~/closet$ mkdir thelab lab46:~/closet$ cd thelab lab46:~/closet/thelab$ touch file1 file2 file3 lab46:~/closet/thelab$ ls file1 file2 file3 lab46:~/closet/thelab$ vi file1 lab46:~/closet/thelab$ vi file2 lab46:~/closet/thelab$ vi file3 lab46:~/closet/thelab$ cat file1 This is file 1 lab46:~/closet/thelab$ cat file2 This is not file 1 or file 3 lab46:~/closet/thelab$ cat file3 file 3 this is. lab46:~/closet/thelab$ gzip file1 file2 file3 lab46:~/closet/thelab$ ls file1.gz file2.gz file3.gz lab46:~/closet/thelab$ tar cvf archive.tar file1.gz file2.gz file3.gz file1.gz file2.gz file3.gz lab46:~/closet/thelab$ tar tvf archive.tar -rw-r--r-- escoute1/lab46 39 2012-09-30 17:17 file1.gz -rw-r--r-- escoute1/lab46 49 2012-09-30 17:09 file2.gz -rw-r--r-- escoute1/lab46 42 2012-09-30 17:09 file3.gz lab46:~/closet/thelab$ rm file1.gz file2.gz file3.gz lab46:~/closet/thelab$ ls archive.tar lab46:~/closet/thelab$ tar xvf archive.tar file1.gz file2.gz file3.gz lab46:~/closet/thelab$ ls archive.tar file1.gz file2.gz file3.gz lab46:~/closet/thelab$ gzip -d file1.gz file2.gz file3.gz lab46:~/closet/thelab$ ls archive.tar file1 file2 file3 lab46:~/closet/thelab$ cat file1 This is file 1 lab46:~/closet/thelab$ cat file2 This is not file 1 or file 3 lab46:~/closet/thelab$ cat file3 file 3 this is.
Based on the data collected:
It does not matter which order you do archiving and compression, you will eventually end up with the same files you had before. The archive before compression method we use however is just a lot easier and I now understand why we don't compress first.