Directory Structure PoSIX

Note: Files are grouped according to purpose. Ex: commands, data files, documentation.
Parts of a Unix directory tree. See the FSSTND standard (Filesystem standard)

/ Root
|—root The home directory for the root user
|—home Contains the user’s home directories
| |—-ftp Users include many services as listed here
| |—-httpd
| |—-samba
| |—-user1
| |—-user2
|—bin Commands needed during bootup that might be needed by normal users.
|—sbin Like bin but commands are not intended for normal users.
Commands run by LINUX.
|—proc This filesystem is not on a disk. Exists in the kernels imagination (virtual)
| | This Directory holds information about kernel parameters and system configuration.
| |—-1 A directory with info about process number 1 | Each process has a directory below proc.
|—usr Contains all commands, libraries, man pages, games and static files for normal operation
| |—-bin Almost all user commands. some commands are in /bin or /usr/local/bin.
| |—-sbin System admin commands not needed on the root filesystem. e.g., most server programes
| |—-include Header files for the C programming language. Should be below /user/lib for consistency
| |—-lib Unchanging data files for programs and subsystems
| |—-local The place for locally installed software and other files.
| |—-man Manual pages
| |—-info Info documents
| |—-doc Documentation for various packages
| |—-tmp
| |— X11R6 The X windows system files. There is a directory similar to usr below this directory
| |—-X386 Like X11R6 but for X11 release 5
|—boot Files used by the bootstrap loader, LILO. Kernel images are often kept here.
|—lib Shared libraries needed by the programs on the root filesystem
| |—-modules Loadable kernel modules, especially those needed to boot system after disasters.
|—dev Device files for devices such as disk drives, serial ports, etc.
|—etc Configuration files specific to the machine.
| |—-skel When a home directory is created it is initialized with files from this directory
| |—-sysconfig Files that configure the linux system for networking, keyboard, time, and more.
|—var Contains files that change for mail, news, printers log files, man pages, temp files
| |—-file
| |—-lib Files that change while the system is running normally
| |—-local Variable data for programs installed in /usr/local.
| |—-lock Lock files. Used by a program to indicate it is using a particular device or file
| |—-log Log files from programs such as login and syslog which logs all logins, logouts, and other
Systems messages.
| |—-run Files that contain information about the system that is valid until the system is next booted
| |—-spool Directories for mail, printer spools, news and other spooled work.
| |—-tmp Temporary files that are large or need to exist for longer than they should in /tmp.
| |—-catman A cache for man pages that are formatted on demand
|—mnt Mount points for temporary mounts by the system administrator.
|—tmp Temporary files. Programs running after bootup should use /var/tmp.

Locating OR Finding Files in GNU/Linux

There are three good methods of finding files in linux:

1. The slocate database
2. The whereis command
3. The find command

The slocate database

To use the locate command, you will need to have a slocate database set up on your system. On many systems it is updated periodically by the cron daemon. Try the slocate command to see if it will work on your system:
locate whereis

Will list all files that contain the string “whereis”. If that command did not work you will need to run the command:

slocate -u

This command will build the slocate database which will allow you to use the locate command. This command will take a few minutes to run.

The whereis command

This command will locate binary (or executable) programs and their respective man pages. The command:
whereis linuxconf will find all binaries and manpages with the name linuxconf.

The find command

The following are examples of the find command:
find /home -user mark Will find every file under the directory /home owned by the user mark.
find /usr -name *spec Will find every file under the directory /usr ending in “.spec”.
find /var/spool -mtime +40 Will find every file under the directory /var/spool that has data older than 40 days.

Find is a very powerful program and very useful for finding files with various characteristics. For more information, read the man page about find by typing “man find”.

Locating man pages by subject

There is a keyword option in the man command that can be used to find man pages that have specific words in their descriptions. An example is: man -k process
to find all man pages that talk about processes. Use the command:
man -k process |grep kernel
to find information on kernel processes. An equivalent command is the apropos command as follows:
apropos process

The which command

The which(1) program is a useful command for finding the full path of the executable program that would be executed if the name of the executable program is entered on the command line. The command:
which startx
Will show the full path of the startx command that will be run if “startx” is entered on the command line when an X session is started.
================================================================

boot, root, var, etc, usr, bin, sbin, home, dev, tmp, mnt, proc

Basic Linux Commands.

Logging in

Once you have completed your system install and booted your system, you should see a login prompt on your monitor. When you did your Linux install you should have set a root password. You may have also created a user with a password. Therefore to log in, you will want to type the name of a user or “root” for the login name and enter the appropriate password. If you logged in as a normal user and know the root password and want to use administration commands, you may use the command “su” to become a “super user”. Some systems also support the “sudo” command, which allows administrative privileges on a command by command basis.
linux how tos, linux-how-tos, linux-howto, useradd, adduser, ls, dir, pwd, groupadd, passwd, redhat, ubuntu, festi, suse, centos, debain, slackware, mandrake, knopix
Linux Shell levels and the su command

The command, “su” will allow a normal user to enter a new shell level as the root user or as another user if they know the root user’s or that user’s password respectively. To become the root user, type “su” then you will be prompted for the root password. To become another user, type “su username”. You must enter either that user’s password to become that user. Every time you use the su command you enter a new shell level which means you have invoked a new running copy of the shell program, such as bash. You can see this change by typing the command “env” and looking at the value of the environment variable “SHLVL”. This value increments when you use the su command and decrements when you use the “exit” command to exit that shell environment. You can also see the shell level value by typing “printenv SHLVL”.

Logging out

Use the command “logout” to exit a given session. If you have logged in, then typed “su” to become a superuser or another user, you may need to type “exit” until your SHLVL environment value is 1. Then you can type “logout” to exit your session. The “exit” command will take you back to previous shell levels.

Shutting Linux Down

The system is intended to be shutdown by the system administrator using the shutdown command in one of the forms shown below. Many systems are set up to capture the CTRL ALT DEL keystroke combination to issue the shutdown command through the init program. This will work on most systems if the root user is logged in. Examples of using the shutdown command are shown below.

shutdown -h now
shutdown -r +10 “Rebooting in 10 minutes”
shutdown -r 13:00

The first command will shutdown and halt the system immediately. The second will reboot the system in 10 minutes and send the message to all users. The third command will shut the system down and do a reboot at 1:00 in the afternoon.

Basic Linux Commands

Command Example Description
cat Sends file contents to standard output. This is a way to list the content on screen.
cat /etc/profile Sends the contents of the “/etc/profile” file to the screen.
cd Change directory
cd /etc
Change the current directory to /etc. The ‘/’ indicates root, and no matter what directory you are in when you execute this command, the directory will be changed to “/etc”.
cd sysconfig
Change the current working directory to sysconfig, relative to the current location which is “/etc”. The full path of the new working directory is “/etc/sysconfig”.
cd ..
Change your present working directory to parent directory. Following to our previous commands you will end up with ‘/etc’ as your present working directory after this command.
cd ~
Move to the user’s home directory which is “/home/username”. The ‘~’ indicates the users home directory.
cp Copy files and directories
cp myfile yourfile
Copy the files “myfile” to the file “yourfile” in the current working directory. This command will create the file “yourfile” if it doesn’t exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfile
With the “-i” option, if the file “yourfile” exists, you will be prompted before it is overwritten.
cp -i /data/myfile
Copy the file “/data/myfile” to the current working directory and name it “myfile”.
Prompt before overwriting the file.
cp -dpr srcdir destdir
Copy all files from the directory “srcdir” to the directory “destdir” preserving links (-p option), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another directory.
dd dd if=/dev/hdb1 of=/backup/
Disk duplicate. The man page says this command is to “Convert and copy a file”, but although used by more advanced users, it can be a very handy command. The “if” means input file, “of” means output file.
df Show the amount of disk space used on each mounted filesystem.
less less text file
Similar to the more command, but the user can page up and down through the file. The example displays the contents of textfile.
ln Creates a symbolic link to a file.
ln -s test symlink
Creates a symbolic link named symlink that points to the file test Typing “ls -i test symlink” will show the two files are different with different inodes. Typing “ls -l test symlink” will show that symlink points to the file test.
locate A fast database driven file locator.
slocate -u
This command builds the slocate database. It will take several minutes to complete this command. This command must be used before searching for files, however cron runs this command periodically on most systems.
locate whereis Lists all files whose names contain the string “whereis”.
logout Logs the current user off the system.
ls List files
ls
List files in the current working directory except those starting with . and only show the file name.
ls -al
List all files in the current working directory in long listing format showing permissions, ownership, size, and time and date stamp
more
Allows file contents or piped output to be sent to the screen one page at a time.
more /etc/profile Lists the contents of the “/etc/profile” file to the screen one page at a time.
ls -al |more Performs a directory listing of all files and pipes the output of the listing through more. If the directory listing is longer than a page, it will be listed one page at a time.
mv Move or rename files
mv -i myfile yourfile Move the file from “myfile” to “yourfile”. This effectively changes the name of “myfile” to “yourfile”.
mv -i /data/myfile Move the file from “myfile” from the directory “/data” to the current working directory.
pwd Show the name of the current working directory
more /etc/profile Lists the contents of the “/etc/profile” file to the screen one page at a time.
shutdown Shuts the system down.
shutdown -h now Shuts the system down to halt immediately.
shutdown -r now Shuts the system down immediately and the system reboots.
whereis Show where the binary, source and manual page files are for a command
whereis ls Locates binaries and manual pages for the ls command.

linux how tos, linux-how-tos, linux-howto, useradd, adduser, ls, dir, pwd, groupadd, passwd, redhat, ubuntu, festi, suse, centos, debain, slackware, mandrake, knopix