pwd(1) is a simple utility which shows the directory you are currently working in. The pwd does not require any parameters. This is an example output of pwd:
$ pwd /home/danieldk
ls is similar to the dir command in DOS and Windows. ls can be used to display files and directories located in specific directories. Running the ls command without any parameters shows the contents of the current directory:
$ ls slackware-beginselen slackware-beginselen-20december2002.tar.gz
Naturally it is also possible to show the contents of other directories. You can do this by specifying the path as a parameter tot the ls command:
$ ls / bin dev home lost+found opt root tmp var boot etc lib mnt proc sbin usr
A disadvantage of the default output is that it provides little information about files and directories. For example, it is not possible to see whether some entry is a file or directory, what size a file is, or who the owner of the file is. The ls has the "-l" parameter to show more information:
$ ls -l total 20 drwxr-xr-x 7 danieldk users 4096 Dec 21 09:24 slackware-beginselen -rw-r--r-- 1 danieldk users 14317 Dec 21 08:35 slackware-beginselen-20december2002.tar.gz
Another important command is the cd command. It can be used to change the current working directory:
$ cd /home/danieldk/
With the pwd command you can see it worked:
$ pwd /home/danieldk
As you might have guessed, the mkdir(1) command can be used to create directories. For example:
$ pwd /home/danieldk $ mkdir test $ cd test $ pwd /home/danieldk/test
It might happen that you want to create a directory in a parent directory which does not exist yet. For example, if you want to create the test2/hello/ directory, but the test2 directory does not yet exist. In this case you can make both directories with only one mkdir command:
$ mkdir -p test2/hello
The rm(1) is used to remove files and directories. Let's look at a simple example:
$ rm hello.c
This commands removes the file hello.c. Sometimes the rm asks for a confirmation. You can ignore this with the '-f' parameter:
$ rm -f *
This command removes all files in the current directory without asking for confirmation. It is also possible to delete directories or even whole directory trees. rm provides the '-r' parameter to do this. Suppose we want to delete the ogle directory and all subdirectories and files in that directory, this can be done in the following way:
$ rm -r -f ogle/
Many commands allow you to combine parameters. The following example is equivalent to the last one:
$ rm -rf ogle/
Every file in GNU/Linux has permissions. As you might have noticed, file permissions can be shown with the ls -l command:
$ ls -l logo.jpg -rw-r--r-- 1 danieldk users 9253 Dec 23 19:12 logo.jpg
The permissions are shown in the first column. Permissions that can be set are read(r), write(w) and execute(x). These permissions can we set for three classes: owner(u), group(g) and others(o). The permissions are visible in the second to nineth character in the first column. These nine characters are divided in three groups. The first three characters represent the permissions for the owner, the next three characters represent the permissions for the group, finally the last three characters represent the permissions for other users. Thus, the example file shown above can be written to by the owner and can be read by all three classes of users (owner, group and others).
Eacht GNU/Linux system has many distinct users (a list of users can be found in /etc/passwd), and a user can be a member of certain groups. This kind of user management provides makes it possible to manage detailed permissions for each file. In the example shown above danieldk is the owner of the file and group permissions apply to the group users. In this example groups rights do not differ from the rights of other users.
The chown(1) command is used to set the file owner and to which group group permissions should apply to. Suppose we want to make danieldk the owner of the file logo2.jpg, this can be done with the chown:
$ chown danieldk logo2.jpg
Using the ls we can see that the owner is now danieldk:
$ ls -l logo2.jpg -rw-r--r-- 1 root root 9253 Dec 29 11:35 logo2.jpg $ chown danieldk logo2.jpg $ ls -l logo2.jpg -rw-r--r-- 1 danieldk root 9253 Dec 29 11:35 logo2.jpg
But group permissions still apply for the root group. This group can be changed by adding a dot after the owner, followed by the name of the group (in this example the group is nedslackers):
$ chown danieldk.nedslackers logo2.jpg $ ls -l logo2.jpg -rw-r--r-- 1 danieldk nedslackers 9253 Dec 29 11:35 logo2.jpg
It is also possible to change ownershit recursively, this can be done with the recursive (-R) parameter:
$ chown -R danieldk.users oggs/
File permissions can be manipulated using the chmod(1) command. The most basic syntax of chmod is chmod [u,g,o][+/-][r,w,x] filename. The first parameter consists of the following elements: 1. which classes this manipulation permission applies to, 2. if the permissions should be added (+) or removed (-), and 3. which permissions should be manipulated. Suppose we want to make the file memo writeable for the owner of the file and the groups for which the group permissions apply. This can be done with the following command:
$ chmod ug+w memo
As you can see below the memo is now writable for the file owner and group:
$ ls -l notities -r--r--r-- 1 daniel users 12 Mar 9 16:28 memo bash-2.05b$ chmod ug+w memo bash-2.05b$ ls -l notities -rw-rw-r-- 1 daniel users 12 Mar 9 16:28 momo
Just like the chown command it is also possible to do recursive (-R) operations. In the following example the secret/, including subdirectories and files in this directory, is made unreadable for the group set for this directory and other users:
$ chmod -R go-r geheim/