Until recently, Linux/Unix was considered OS of the geeks. However, with GUI and more desktop Linux distributions, things have simplified on both Linux and Unix. Still you can geek out with Unix/Linux using its terminal. Just follow the steps below to master the terminal.
1. Never used Linux!
Get Ubuntu CD available for free download online or you can get it free with most Computer Magazines. Other *nix clones available for free are FreeBSD, OpenSolaris, CentOS, Fedora, Mint, Debian, Ubuntu’s flavors Kubuntu, ubuntu netbook edition, etc. Most run directly from CD and you may not need to install it.
2. Get the console mode on Linux
Press Ctrl+Alt+F2 to F6 to go to console mode also known as terminal or command line mode as against GUI mode. Use this mode when you want to geek off. Press Ctrl+Alt+F1 or F7 (default for most *nix) to revert to GUI mode. In GUI you can try ‘terminal’, ‘console’, ‘xterm’, etc till you are comfortable. If you are a Mac fan then you can use ‘terminal’ too on iPod, iPhone and Mac. It’s Unix underneath! Windows™ also has a command line mode too, but the commands are quite different and lack the effectiveness of *nix commands. Still it is worth learning windows commands, formerly known as DOS commands.
3. Understand directory structure
type – cd /
‘/’ is the top level directory also known as the root of filesystem or root directory. This is the most confused thing during Linux installation.
type – ls
/bin – system binaries
/dev – Device files go in this directory
/home – similar to my documents of individual users in windows and has configurations specific to each user
/root – root user’s home directory. Adminstrator in *nix systems is known as root.
/usr – user accessible libraries, binaries, documentation
/mnt – mount points for devices are located here. Recent systems mount devices under /media.
/sbin – administration tools
/opt – user installed applications
/boot – files and configurations for booting linux
/var – files varing in size lie here. eg. log files, printer spool, etc.
/tmp – temporary files here
/lib – system library files reside here.
/etc – Most configuration files go here. Most of *nix strength lies within these configuration files.
/proc – this directory has running system information which is automatically generated by system
/usr/src – Source code of linux kernel & other packages
This is just a guide. But what goes in which directory changes from *nix to *nix and also sometimes vary in different version of same *nix.
type – cd ~
The ’tilde’ is a shortcut to your home directory.
4. Simple commands to master console:
Note : All commands and filenames under *nix are case-sensitive.
i. ls : to get directory list. Use ls -l | more – detailed directory list one page at a time. try – ls -lA. Use ‘ls’ to check results of all commands mentioned below.
ii. touch <filename> : create empty file or changes access time of existing file. Try touch linuxGeek.txt
iii. echo : print a line on terminal. Use echo ‘How R U?’. Try echo ‘How R U’> linuxGeek.txt Also try echo ‘How R U’ >> linuxGeek.txt
iv. cat <filename> : to see contents of text files. use cat linuxGeek.txt – read one screen full at a time. Try cat linuxGeek.txt -n
v. rm <filename> : delete a file. try rm -v linuxGeek.txt
vi. pwd : know your present working directory
vii. cd <directory> : to go to directory (known as ‘folder’ in Gui parlance). use cd .. – previous directory. try cd ~
viii. mkdir <directory> : create new directory. try mkdir tmp1 tmp1. Use ls to see results.
ix. rmdir <directory> : delete a directory. Try rmdir tmp1 tmp2
x. su <username> : Switch User. While logged in as a user you can login as another user (We know it as fast user switching available in Windows since WinXp) and use the system as another user. Try su (does not work in Ubuntu by default. It prefers ‘sudo’ to ‘su’)
xi. mount <partition> <directory>: mount (map in Windows parlance) physical or virtual or network drive to existing directory. use umount <mounted directory> to unmount.
xii. sudo <command>: Run a command with root (administrative) privileges. sudo mount -a
xiii. exit : to logout of system
Q.What can you do with these simple commands?
A.These are the most powerful and useful tool you can have. Among other things, it can be used for
a. Recovering your windows/linux installation
b. Data backup/recovery
c. Deleting virus. Yes! Linux is immune to windows viruses and you can just delete it and its gone. Beware, though linux is itself immune to windows viruses, it can spread virus on connected devices and windows computer. There are known Linux viruses but they are very few and do not affect the system very easily.
5. Other interesting commands
i. cal : prints calendar. Try cal 2011
ii. date : shows current date and time. As root/admin can also use it to set date & time
iii. time <command> : Shows execution time of a command. try time cal 05 2011
iv. file <filename> : Tells you the type of file – binary, ascii, directory, etc among other details
v. type <command> : Shows location of a command. Use type date. Try type su. Also try type sudo
vi. bc : binary calculator. You can have all functions of a scientific calculator and it also has programming ability. Use quit to close the calculator.
6. Know you system
i. df : know disk space usage. try df -h
ii. ps : processes currently running. Gives process Id and process name. Try ps -A|more
iii. top : real-time view of current tasks. (task manager in Windows).
iv. uname : gives OS version, name, etc. Try uname -a
v. lsusb : list available usb devices. Try lspci
vi. fdisk -l : list available drives
vii. who : all users who have logged in to your computer.
viii. whoami : Username you used for login.
ix. chmod <permission> <filename>: modify file permissions. try chmod +ugo +rwx <filename> allow user, group and others read, write and execute permission to filename. try chmod 777 <filename> to get same result. But remember you are giving all permissions to everybody on that file!
x. chown <otheruser> <filename> : change ownership of a file/directory. The creator of a file is the owner of the file. Based on file permissions as above a user may or may not be able to access a file. Do not create/change any file as ‘root’ user under home directory.
7. Working with files
i. sort <filename> : sort a file alphabetically. It does not change the contents of a file. Try sort -r <filename>.
ii. split <filename>: splits file in size of 1000 lines. Keeps original file intact. Split files are named xaa, xab, xac and so on. Try split -n 10 <filename>. Use cat x* > <filename> to join them back.
iii. locate <filename>: find a file from database created using ‘updatedb’.
iv. updatedb : creates/updates database to find files using locate.
v. cat <file1> <file2> > <file3>: concatnate file1 and file2 to create file3.
vi. grep ‘<searchword>’ <filename> : list lines matching a search-word in a file.
vii. vi <filename> (viSUAL editor not roman six) : A powerful text editor and available on all flavors of *nix. It has 2 modes command (using ‘esc’ key) and editing [using i (insert), a (append), r (replace characters)]. Use vi <filename> esc + :wq to save and quit. Refer basic vi commands to learn more.
i. ifconfig : shows list of network InterFaces with IP addresses and other details.
ii. route : shows routing table
iii. ping <IP address> : check whether a IP is alive and can be connected. try – ping 127.0.0.1
iv. telnet / ssh/ ftp <IP address> : connect to remote computer using respective protocols.
v. netstat : network statistic info.
vi. tracert <IP address> : Shows names of routers on each hop to destination.
You are on a console and don’t know what a command does or how to use it. Don’t worry there’s help at hand.
• <command> –help : Shows how to use a command and its available options. Very useful tool. try it with all commands above.
• man <command>: gives detailed help (manual).
• info <command> : gives hyperlinked detailed information of the command if available.
• apropos <word> : gives list of commands with short info related to the <word> specified. try this if you don’t know/remember a command.
• cd /usr/share/local/docs: It is not separate command but the location of documentation for most packages/software available on *nix.
10. *nix Basics
So now you are a geek too. But wait! There are some important things a *nix geek must know.
i. What is kernel? What is shell?
Unix/Linux is an Operating System. A part of this OS, which interacts with the hardware and manages various functions of OS is called kernel. The other part is the shell, which interacts with this kernel and is available to users to work on. Most applications run on top of this shell. To summarize: Hardware <–> Kernel <–> shell <–> applications
ii. What is Unix? What is Linux?
Now that we now what is kernel and what is shell, we must also know how Unix and Linux are different. Simply speaking Unix is a Specification and Linux is the kernel. Not clear, right?
OS which matches POSIX specifications (now a part of SUS – Single Unix Specification) is considered Unix. It comprises both the kernel and its shell. Those that do not comply with this specification are termed Unix-like OSes.
All unix like OSes running Linux kernel are considered Linux. Unix is proprietary (exceptions include FreeBSD, OpenSolaris) and Linux is Open Source.
Some more things you must know to be a *nix geek:
iii. What is file? What is process?
iv. What are commands? What are command options?
v. What are the different types of shell available?
vi. What is shell scripting?
vii. What is a Window Manager? How is it different from GUI?
This guest post is written by Milind Lokde. Milind is a co-author of the online book ‘Attaining Nirvana’, which can be read at http://attainingnirvana.com. It is available for free download and distribution for non-commercial purposes under creative commons license. He also likes to delve into mysteries of the world and mind, which you can read on his blog at http://mindcanmatter.wordpress.com