d = directory - = file
The rest of the permissions string displays the permissions given to the file/directory owner, the owner’s primary group and everyone else. If we break the permissions string into groups, it might look like this:
d rwx r-- --- ^ ^ ^ ^ | | | | | | | +-- everyone else's permissions (no access) | | +------ other group members' permissions (read only) | +---------- owner's permissions (read, write and execute) +------------- file type (d = directory)
The “rwx” shown in the example above means that read (r), write (w) and execute (x) permissions are provided to the directory owner. In contrast, “—” means that none of these permissions are provided. Expect to see many instances in which only read (r–) or read and execute (r-x) permissions are granted. You can control who can access your files. For example, you could grant access to a file in your directory with a command like this provided the intended user has access to your home directory as well.
$ chmod o+r myfile
The command shown above would give read access to anyone in the “other” group (i.e., anyone who is neither the owner nor a member of the file’s assigned group). Keep in mind that these users would not have access if they don’t also have access to the directory containing the file.
NOTE: As you likely suspect, only the owner of a file or root can change the file’s permissions.
Viewing file content
Viewing the content of a file depends on the file type. To view text files, you can use the cat (show file content) or the more (show file content a screenful at a time) command. Bash scripts are text files as are startup files like .bashrc. System executables, on the other hand, which are referred to as “binary” files cannot be viewed except with commands that display the content as a long series of 0’s and 1’s – binary content. Finding a command that can display the content (like an image) on the desktop is an altogether different process.
$ cat myfile This is my favorite file. It reminds me about how I felt when I first Discovered Linux! $ head -5 colors aqua azure black blue bronze $ tail -5 colors turquoise violet wheat white yellow $ more colors aqua azure black blue bronze brown chocolate ...
Note that the more command will list file content a screenful at a time. Hit the enter key to move the next screenful.
Copying, moving and deleting files
To make a copy of a file, use the cp (copy) command like this:
$ cp myfile myfile.save
To move a file to a different directory (one you have write access to), use a command like this:
$ mv myscript ~/bin
In the command shown above, you would be a copying a file named “myscript” to the bin directory in your home directory. The bin directory will likely not exist unless you create it with a “mkdir ~/bin” command.
To delete a file, use the rm command. Deleting a file requires that you have write permission to it.
$ rm myfile
Stay tuned for Part 2 of getting started on the Linux (or Unix) command line.