You can create new directories using the mkdir command. You can remove them with the rmdir command.
kent@moosebase:~$ ls bookstuff code labs other students web kent@moosebase:~$ cd comp217 kent@moosebase:~/comp217$ mkdir kent kent@moosebase:~/comp217$ ls bookstuff code kent labs other students web kent@moosebase:~/comp217$ rmdir kent kent@moosebase:~/comp217$ ls bookstuff code labs other students web
You can't use rmdir of directories that have files in them. You can either first remove all the files and directories and them remove the directory you want or you can use a powerful but dangerous version of the rm command. The -r option says to remove the file (or directory) you put on the command line, but also any children of that directory. Add the -f option, and it won't give you any odd error messages. In this case, if I wanted to remove the public_html directory and all files and directories under it, the command would be
rm -rf public_htmlRemember, this won't ask if you really wanted to, it will immediatly and irrevocably remove everything. So, be very careful!.
After you create a directory, you can change its permissions to control access to it. In this case, we are allowing everybody to do everything. The -d option on ls only shows directories.
kent@moosebase:~/comp217$ mkdir kent kent@moosebase:~/comp217$ chmod 777 kent kent@moosebase:~/comp217$ ls -ld kent drwxrwxrwx 2 kent kent 4096 Mar 10 12:52 kent
You can search files for specific words or other combinations of characters. The grep command is very useful in finding information in a collection of files.
kent@moosebase:~/comp217/web$ cd notes kent@moosebase:~/comp217/web/notes$ ls architecture.html controls.html intro.html pointers2.html arrays.html datatypes.html midrev.html strexample.html bookerrata.html finalrev.html oddsandends.html strings.html class.html firstapp.html pgmnotes.html stuff.html class2.html functions.html pizzaprob.html unix1.html classes index.html pointers.html
Let's search all the HTML files for the phrase C++.
kent@moosebase:~/comp217/web/notes$ grep C++ *.html architecture.html:
Very specific and powerful patterns can be specified on the grep commandBut for now, you can use it to look for words.
Once you have transferred a zip file to the UNIX box (See Using FTP) You can use the unzip command to install it.
[d99110215@puma comp217]$ ls [m[d99110215@puma comp217]$ ls -l total 1048 -rw-r--r-- 1 d99110215 d99110215 1065823 Mar 17 2004 comp217.zip [d99110215@puma comp217]$ unzip comp217.zip Archive: comp217.zip creating: comp217/bookstuff/ extracting: comp217/bookstuff/code.zip extracting: comp217/bookstuff/codeUNIX.tar.Z extracting: comp217/bookstuff/date.zip inflating: comp217/bookstuff/errata.txt extracting: comp217/bookstuff/geofig.zip inflating: comp217/bookstuff/sampleSyl.ps.SYLLABUS.ps inflating: comp217/bookstuff/trans_ma.pdf creating: comp217/code/ creating: comp217/code/ARRAY1/ inflating: comp217/code/ARRAY1/ARRAY1.CPP inflating: comp217/code/ARRAY1/ARRAY1.DSP inflating: comp217/code/ARRAY1/ARRAY1.DSW inflating: comp217/code/ARRAY1/ARRAY1.NCB ... and so on
When it is done, we can check that the new files are there using ls and check the size of the things in the directory.
[d99110215@puma comp217]$ ls -l total 1052 drwxrwxr-x 10 d99110215 d99110215 4096 Mar 17 2004 comp217 -rw-r--r-- 1 d99110215 d99110215 1065823 Mar 17 2004 comp217.zip [d99110215@puma comp217]$ du -s * 5116 comp217 1048 comp217.zip
du -s shows the sizes in blocks, each block is 1024 bytes or 1K. So the zip file was about 1 megabyte and the unzipped directory is about 5 megabytes.
To zip up a directory, use the zip command like this.
[d99110215@puma comp217]$ zip -r comp217 comp217 adding: comp217/ (stored 0%) adding: comp217/bookstuff/ (stored 0%) adding: comp217/bookstuff/code.zip (stored 0%) adding: comp217/bookstuff/codeUNIX.tar.Z (stored 0%) adding: comp217/bookstuff/date.zip (stored 0%) adding: comp217/bookstuff/errata.txt (deflated 61%) adding: comp217/bookstuff/geofig.zip (stored 0%) adding: comp217/bookstuff/sampleSyl.ps.SYLLABUS.ps (deflated 79%) adding: comp217/bookstuff/trans_ma.pdf (deflated 28%) adding: comp217/code/ (stored 0%) ... and so on
The -r option tells zip to include all the files and folders under the one we are interested in. The first comp217 is the name of the folder to be zipped. The second one is the name of the zip file. So, this command will zip up the comp217 folder and everything under it and put it into a file called comp217.zip
We are all done for now, so we can leave the UNIX session by using the exit command.
--> exit