Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Unlike Windows, Linux uses no drive letters, such as 'C:' to refer to disks. In Linux everything is a directory. The top most directory is equivalent to the drive letter. In Cygwin, which pretends to be a Linux but runs on Windows, the windows 'C:' disk is refered to as directory '/cygdrive/c'. And the root of Cygwin directory tree looking from Windows side is (usually) 'C:/cygwin', under which you find 'home', 'bin', 'etc' ... File and directory names can contain all kinds of letters but it is best to use names that only use english lowercase letters and digits plus maybe dashes and underlines. Especially you should avoid names with spaces (' ') in them. They will make your life miserable. Names that begin with period '.' are not usually visible in directory listings which is why the many operating system tools store configuration data into files beginning with '.'. Or actually it is the other way round, because tools store info into those files they are hidden. Names are case sensitive in Linux whereas in Windows they are not. This can be very confusing if you are testing something, say a web page, in Windows and it works but does not work when you upload it to the server which is most likely a Linux box. Each session has current directory assosiated with it. What this means in Finglish is that if you do not specify (in a command) otherwise it is assumed that you are refering to the current directory. By having multiple sessions it is easy to work in multiple directories because in effect every terminal window has its own current directory. Here are the most common commands that are used to work with (current) directories.
pwd cd dirname cd .. directory cd ~ mkdir dirname rmdir dirname first be deleted Show the directory you are currently in Change current directory to 'dirname' directory Move to (make current) the parent of your current Move to your home directory Make a new directory named 'dirname' Remove a directory named 'dirname' Note:
Paths
Files and directories are referd to by path names. There are relative and absolute path names. A relative pathname begins with a letter and it refers to a file or directory that is in the current directory or a subdirectory of current directory. An absolute path name begins with a slash and specifies the full 'path' from the highest level of the file system to the file/directory in question. The current directory can be referenced as '.' and the parent directory of the current directory as './..' and so on.
Every user, based on their username, has a special directory called home directory. Immediatelly after login current director is set to your home directory. The home directory can be referenced as '~' in a path. The asterisk ('*') can be used as a wild card in most situations when specifying files on a command line. There are conventions in Linux world on how to organize the file hierarchy. There is nothing to enforce these conventions but most system are organized along these lines. Here are some often used directories:
/bin /dev /etc /tmp /home for for for for for binary (executables), device files, admin and personal information, temporary files, and home directories of individual users
cat file "Concatenate" the file--that is, print its entire contents to the screen, all at once. For big files, use more file.
Getting Help
Most commands list a short description of their usage and possible argumenst i.e. parameters when given the parameter --help. For example:
ls --help
You can also access a lot of documention for each command with the man command. This lists the manual pages for a given command page by page. Press 'space' to get to the next page, press 'q' to quit reading. For example:
man ls
The 'configure' is actually a script that contains shell commands to do the configuration. While I'm on the subject: the 'configure' script usually creates a Makefile, which is used to build the tools. More on that later. To make a file executable (for everybody) you use the chmod command, like this:
chmod a+x filename
Instead of 'x' you could add (with '+') or remove (with '-') read ('r') or write ('w') access to a given file. To see if a file is executable and other stuff use:
ls -l filename
It also possible to direct the output of one program to the input of another. This is called piping and is effected with '|'. Very often used with 'more' command, (or maybe with 'less' command as 'more' does not seem to be available in Cygwin) , which is a command that just outputs what it inputs, but does it page by page so that you have a chance to read it. For example if you invoke the 'ls' command recursively to see all the files in your current directory or any subdirectory you will be creating a looooooooong listing, which will whirl by at speed of light. To cut it to readable chunks use:
ls -R | less
One of the most common uses for piping is to use it to feed input to grep command.
Following is a way to list all '*.java' files and the directories in which they are starting recursively from current directory:
ls -R1 | grep -e ".java\|/"
Finds word 'b*lean' where '*' stands for anything Counter intuitively and unfortunatelly the following DOES NOT work:
grep -Rn void *.h
If you want search all files of certain type in current directory and sub directories you need to use:
find . -name "*.c" -exec grep -l -n 'this' {} \;
Finds 'this' in any '*.c' file. Following gibberish executes wc< (word count) command on each '*.java' file in current directory and any subdirectory and stores the results to a text file 'wc.txt'. Handly for collecting statistics of you lates software project.
find . -name "*.java" -exec wc {} \; >wc.txt
Unpacking Files
A lot of things in the Linux world are distributed as tar (aka tarball) files which are compressed with gzip or gzip2.
tar the tar the xfj collection1.bz2 arcieve 'collection1' xfz collection1.tar.gz arcieve 'collection2' Uncompresses and then extract all the files from Uncompresses and then extract all the files from
Programs
This is a way too complex subject, but amazingly a lot of GNU based Free software actually can be installed and compiled by going to top level directory of the source distribution and entering following:
./configure make make install
Note that many packages can take hours to compile! If you do not see any output, that is a good sign, in the best tradition of "no news is good news" most Linux tool produce no output when things are going smoothly!
Compiling Software
This is even more complex subject but a simple hello word program such as
#include <stdio.h> int main (void) { printf ("Hello, world!\n"); return 0; }
cc hello.c -hello
all
folks,
Miscallenious
To create a check an md5sum index of files (to facilitate dumplicate file finding):
find DIRECTORY -type f -exec md5sum "{}" \; | sort >/tmp/index find . -name "*.java" -exec grep -v '^[[:space:]]*$' $ {} \; | wc