Recently I am reading the article of Windows-to-Linux roadmap . It is very userful and helpful.
As a programmer on Windows, senior develop in .Net world, I want to improve my self skills in much more deep level and have determined to move to Linux from Windows for years ago. After tried for many times, it seems very difficult for me to work on Linux. And the result is no result.
Now I decide to try again. And find the article very helpful, much more than the before reading.
Following is my read notes of article that may help someone who need it.
Part 1. Thinking in Linux
Key difference between Linux and Windows:
- Linux is built for networking not for printing
- The GUI is optional in Linux world and the text is the reality of Linux.
- Everything that can be done on the GUI can be done in console too.
- Linux has not file extension and all kinds of files can be marked as executable
- Even number of kernel is table and the odd is for experiment and development
- Rebooting for Linux should be avoided because it can’t solve the problem although it works on windows
- Commands are case sensitive in Linux.
Part 2. Console crash course
- Each console is a completely different session on the system and can be accessed as different users at the same time
- Remember that all commands and options are case sensitive. -R is different from -r, and will probably do different things. Console commands are almost always lowercase.
- The main trick is to remember that in Linux the forward-slash (/) is used where you are accustomed to using the back-slash (\). The back-slash is still used, but it specifies that a command should be continued on the next line. This is sometimes done for readability when typing in a particularly long command.
- In Linux, the command shell is a layer separated from the operating system.
- A script can specify the shell it wants to run by putting a shebang (#!) at the top of the file pointing to the desired shell.
- One compelling feature in the Linux file system is the file link. A link is a reference to a file, so that you can let files be seen in multiple locations of the file system. However, in Linux, a link can be treated as the original file. A link can be executed, edited, and accessed without having to do anything unusual. As far as other applications on the system are concerned, a link is the original file. When you make edits to a file through the link, you are editing the original. A link is not a copy. There are two kinds of links: a hard link and a symbolic link.
- A hard link can only reference files in the same file system. It provides a reference to the file’s physical index (also called an inode) in the file’s system. Hard links do not break when you move the original file around because they all point to the file’s physical data rather than its location in the file structure. A hard-linked file does not require the user to have access rights to the original file and does not show the location of the original, so it has some security advantages. If you delete a file that has been hard linked, the file remains until all references have been deleted as well.
- A symbolic link is a pointer to a file’s location in the file system. Symbolic links can span file systems and can even point to files in a remote file system. A symbolic link shows the location of the original file and requires a user to have access rights to the original file’s location in order to use the link. If the original file is deleted, all of the symbolic links become broken. They will point to a non-existent location in the file system.
- Both types of links can be made with the command ln <source> <target>. By default ln will make a hard link. The -s switch will make a symbolic link.
Part 3. Introduction to Webmin
- Webmin is a browser-based administration application written in Perl
- In Linux, the primary administrative user is called root. The root user has full control over all aspects of the system. The name of root should never be taken in vain.
- Once installed, Webmin is accessed through a special port, typically 10000, either locally or from a remote browser
Part 4.User administration
- Creating new users: user add, ex. useradd -c “normal user” -d /home/userid -g users -G webadm,helpdesk -s\ /bin/bash userid
- Changing passwords: passwd, ex. passwd userid
- Delete Users: userdel, ,ex. userdel -r userid; The optional -r switch will delete the user’s home directory and all its contents in addition to the user. If the directory is to be preserved, omit the -r switch. This switch will not automatically delete all the files on the system that belong to the user, just the home directory.
- View user list: more /etc/passwd
- User record in passwd: userid:x:75000:75000::/home/userid:/bin/bash
Login ID Password User ID Group ID Comment Home directory Default shell userid x 75000 75000 /home/userid /bin/bash
- User password file, /etc/shadow, which is encrypted.
- Creating a group: groupadd mygroup
- View all groups: more /etc/group
- Group password: /etc/gshadow
- Add members to group: gpasswd -a userid mygroup
- Remove users from a group: gpasswd -d userid mygroup
- Each file can have only one owner and one group.
- In Linux, group definitions tend to be based more on the resource access required than on business units.
Part 5.Linux logging
- One of the keys to success in managing any system is to know what is happening on the system. Linux offers exceptional logging, and the detail in the logs is configurable.
- Linux logs are in plain text, so you can search and read them without having to use special tools
- Linux logs are contained in the /var/log directory.There are several log files that are maintained by the system, but other services and programs may put their log files here too. Most logs are only readable by root, but that can be changed by simply changing the access rights to the file.
- The messages log is the core system log file. It contains the boot messages when the system came up as well as other status messages as the system runs. Errors with IO, networking, and other general system errors are reported in this file. Other information, such as when someone becomes root, is listed here as well. If services are running, such as DHCP servers, you can watch the action in the messages file. /var/log/messages is generally your first place to look when you are troubleshooting.
- This log shows the results of the last execution of the Xfree86 Xwindows server. If you are having problems getting the graphical mode to come up, this file will usually provide answers as to what is failing.
- Linux provides a command to rotate these logs so that you don’t have current log information mixed with older irrelevant data
- Generally logrotate runs automatically on a timed basis, but it can also be run manually. When executed, logrotate will take the current version of the log files and add a “.1” to the end of the filename. Then any other previously rotated files are sequenced with “.2,” “.3,” etc. The larger the number after a filename, the older the log is.
- You can configure the automatic behavior for logrotate by editing the /etc/logrotate.conf file
- Log tools
- dmesg – To get a quick view of the boot log for the last system boot, use the command dmesg. It generally puts out a lot of text, so you will generally want to pipe it through a viewer.
- tail – Sometimes you want to keep an eye on a log file as activity is occurring. Tail is designed to show the last few lines of a text file. By adding the -f switch, tail will continue to show new output as it occurs. ex.tail -f /var/log/messages
- more – Use “q” or [Ctrl]-C to stop looking at a file.
- less – Less is another text viewer, but it allows you to scroll through a file and search for information. Use “q” to quit viewing the file. Use “h” to get help on using less.
- logger – The logger command lets you send your own messages to the logging facility. Use it in scripts to provide messages about execution and errors.
- klogd and syslogd can control logging.
- klogd only deals with kernel messages. syslogd deals with other system messages, such as applications
- You can configure the behavior of both by editing the files /etc/syslog.conf and /etc/sysconfig/syslog.
- Essentially, each message generated by software provides some information to identify where the message came from and what message it is.
- The /etc/syslog.conf file allows you to specify what you want done with that kind of message.
- Remote logging is an excellent security feature. By placing your logs on a remote system, you can prevent a security breach from easily covering its tracks by altering the log files.
Part 6.Working with file systems
- Working with files and storage devices in Linux is different from Windows. There are files and a hierarchical directory structure, but beyond that you will need to develop a different way of thinking.
- There are no drive letters in Linux.
- In Linux, there is just one file structure. It starts with root (/) and all local file systems, all local devices, and all remote file systems are represented as subdirectories in this structure.
- When Linux first boots, it builds this file structure based on information in the /etc/fstab file.The structure of the hierarchy is completely configurable and can be changed on the fly.
- The term for adding a device to the file system is mounting. Linux will automatically mount a / (root) file system. There may also be a separate /boot file system, containing the core kernel boot files. Linux will also mount some special file systems.
- /proc contains a virtual representation of various aspects of the running system. There is information about IRQ settings, memory usage, loaded device drivers, network status, and much, much more. There is even a file called /proc/kcore, which is a virtual representation of all of the used system memory. Each of these files can be parsed just like a normal text or binary file. Some files can be written to change the behavior of the running kernel, without rebooting。
- The main benefit of such a system is that you can use simple scripting techniques to do very deep and powerful things to your running system
- Other file systems, such as removable media or remote file systems, will need to be manually mounted. When mounting a file system, you will need to know the correct way to reference it from Linux, and have an empty directory to use as a mount point. For removable media, Linux will probably create mount points for you during installation. In Red Hat Linux, the cdrom device is set up to mount to the directory /mnt/cdrom
- /etc/fstab：The association between a device and its mount point is configured in the /etc/fstab file. It can be human-edited, or maintained with an administrative tool
- In Linux, file systems are represented by a file-like name. All of the files in the /dev directory are special files called nodes that link to physical devices through the device driver
- The fdisk console command is used to create and manipulate partitions. When you execute fdisk, you must point it toward a device. To see the available devices, use the command fdisk -l
- File system types
- ext2: The standard Linux file system
- ext3: The standard Linux file system with journaling added
- vfat: Microsoft’s Fat32 file system
- jfs: IBM’s journaled file system
- reiserfs: Another popular journaled file system
- Journaled file systems help protect data from unexpected shutdowns. If a volume is shut down without dismounting, there may be unfinished work and files left in an in-between state.A journaled file system keeps a transaction record of each write to the disk for a period of time, such as five seconds. When the volume is not cleanly unmounted, the file system simply rolls back to the last known good state. A volume that would take twenty minutes to come back up now comes up in seconds!
- Formatting partitions – mkfs
- df – stands for “disk free.” It reports the amount of disk space used and available on mounted file systems
- du – stands for “disk usage.” It reports the amount of disk space used by the specified files and for each subdirectory (of directory arguments)
- fsck – used to check and repair file systems, equivalent to chkdsk in Windows. It will have different versions for different file system types, just like mkfs. fsck must be run on unmounted volumes, though it is rarely needed unless the file system was not cleanly unmounted