150 likes | 239 Views
Linux Files and Directories. Linux directories.
E N D
Linux directories • Linux system are arranged in what is called a hierarchical directory structure. This means that they are organized in a tree-like pattern of directories (called folders in other systems), which may contain files and other directories. The first directory in the file system is called the root directory.
Understanding Linux directories • Ubuntu uses the Linux file system, which is based on a series of folders in the root directory. Each of these folders contains important system files that cannot be modified unless you are running as the root user or use sudo. • This restriction exists for both security and safety reasons: computer viruses will not be able to change the core system files, and ordinary users should not be able to accidentally damage anything vital.
Linux directories Below are some of the most important directories. • The root directory—denoted by /—contains all other directories and files. Here are the contents of some essential system directories: • /bin & /sbinMany essential system applications (equivalent to C:\Windows) • /etcSystem-wide configuration files • /home Each user will have a subdirectory to store personal files (for example • /home/your-username, equivalent to C:\Users or C:\Documents and Settings) • /lib Library files, similar to .dll files on Windows
Linux directories • /media Removable media (CD-ROMs & USB drives) will be mounted in this directory • /root contains the root user’s files (not to be confused with the root directory) • /usrPronounced “user,” it contains most program files (not to be confused with each user’s home directory, equivalent to C:\Program Files) • /var/log Contains log files written by many applications
Understanding Linux directories • Think of the file system tree as a maze, and you are standing in it. At any given moment, you are located in a single directory. • Inside that directory, you can see its files and the pathway to its parent directory and the pathways to the subdirectories of the directory in which you are standing. • The directory you are standing in is called the working directory. • To find the name of the working directory, use thepwd command. • me@linuxbox$pwd/home/me • When you first log on to a Linux system, the working directory is set to your home directory. This is where you put your files. • On most systems, your home directory will be called /home/your_user_name
Looking around using LS • Thels command is used to list the contents of a directory. It is probably the most commonly used Linux command. It can be used in a number of different ways.
Closer look at LS command • If you use the -l option with ls, i.e. (ls –l) you will get a file listing that contains a wealth of information about the files being listed.
Interpreting results of ls -l • File Name: The name of the file or directory. • Modification Time: The last time the file was modified. If the last modification occurred more than six months in the past, the date and year are displayed. Otherwise, the time of day is shown. • Size: The size of the file in bytes. • Group: The name of the group that has file permissions in addition to the file's owner. • Owner: The name of the user who owns the file. • File Permissions: A representation of the file's access permissions. The first character is the type of file. A "-" indicates a regular (ordinary) file. A "d" indicates a directory. The second set of three characters represent the read, write, and execution rights of the file's owner. The next three represent the rights of the file's group, and the final three represent the rights granted to everybody else.
Some ls options • -a or --all Displays hidden files as well • -i or --inode Displays the unique file number (inode number) • -l or --format=long Displays extra information • -o or --no-color Omits colour-coding the output • -p or -F Marks file type by adding a special character • -r or --reverse Reverses sort order • -R or --recursive Recurses into subdirectories (DOS: DIR/S) • -S or --sort=size Sorts files by size (longest first) • -t or --sort=time Sorts file by modification time (newest first) • -X or --sort=extension Sorts file by extension (“file type”)
Important facts about file names • File names that begin with a period character are hidden. • This only means that ls will not list them unless you say ls -a. • File names in Linux, like Unix, are case sensitive. The file names "File1" and "file1" refer to different files. • Linux has no concept of a "file extension" like legacy operating systems. • Though Linux supports long file names which may contain embedded spaces and punctuation characters, limit the punctuation characters to period, dash, and underscore. • Most importantly, do not embed spaces in file names. If you want to represent spaces between words in a file name, use underscore characters. You will thank yourself later.