You are on page 1of 13

Dhanoop Bhaskar

picJanuary2002. Example: echo . etc. If you want to reference a special \ character.txt Command separator. or by itself.txt. Redirect the output of one command into another | command. used to separate a string of directory / names.txt can represent hello1. Example: ls > myfiles. and hello2.. over-write it. Example: cd /var/log . Example: /usr/src/linux Current directory. [ ] Example: hello[0-2].hello1. but not hello22.txt represents the names hello0. Parent directory ~ User's home directory Represents 0 or more characters in a filename.picFeb292002. [0-9].g. Example: touch /tmp/filename\* Directory separator. helloz.txt & 2 . [A- Z]. Allows you to execute multiple commands .txt Redirect the output of a command onto the end of an >> existing file. Example: find / -name core > /tmp/corefiles. Example: ls | more Redirect output of a command into a new file. etc.txt. all files in a directory. . less messages Command separator as above.txt Redirect a file as input to a program.txt Can be used to represent a range of values. < Example: more < phonenumbers. If the file > already exists. you must “escape” it with a backslash first. >> phonenumbers.Mary 555-1234. but only runs the second command if the first one && finished without errors. e.Character Description Escape character. and immediately get & your shell back. ? Example: hello?. Example: cd /var/logs && less messages Execute a command in the background.txt. Can also “hide” files when it is the . Represents a single character in a filename. on a single line.txt.txt “Pipe”. * Example: pic*2002 can represent the files pic2002. first character in a filename.

/usr/sbin Non-vital system binaries (lpd. files. Also often used for software packages installed from source./home/dhanoop). etc). /sbin Essential system binaries (fdisk. Device files. du. Commonly (but incorrectly) referred to as the “slash” or “/” directory. /usr The base directory for most shareable. /lib Essential shared libraries and kernel modules.g. All other directories. The LINUX Directory Layout Directory Description The nameless base of the file system. /root The root (super-user) home directory. and they are kept under this directory.). init.) /boot Static files of the boot loader. /usr/include Header files for compiling C programs. man pages. etc. /etc Host-specific system configuration files. documentation. In Linux. 3 . All users have permission to place /tmp temporary files here. read-only data (programs. Process information pseudo-file system. and much more). This directory only really matters in environments where files are stored on the /usr/local network. hardware devices are accessed /dev just like other files.) /usr/share Architecture-independent data (icons. fsck. etc. libraries. etc. useradd. etc. “Locally” installed files. Temporary files. or software not officially shipped with the distribution. ls. /usr/lib Libraries for most binary programs. terminfo. backgrounds.). The “/” is just a directory separator. tar. Locally-installed files go in /usr/local/bin. /usr/bin Most user programs are kept here (cc. not a directory itself. An interface to /proc kernel data structures. etc. drives. find. /bin Essential command binaries (programs) are stored here (bash.). documentation. and devices are attached to this root. Location of users' personal home directories /home (e. /usr/local/lib. mount.

log files.change file access permissions To get “info” pages info <command name> To print working directory pwd To change directory To return to home directory cd To change into specified directory name cd <directory name> 4 . /usr/X11R6 The X Window System. Variable data: mail and printer spools. BASIC LINUX SHELL COMMANDS To get help on commands help <command name> : help cat <command name> --help : grep --help <command name> -h : chmod -h whatis <command name> : whatis grep To get “man” pages man <command name> : man ls To search for a particular word within a man page type “/word”. The Linux Kernel. To quit from a man page. source /usr/src RPMs. If you don’t remember the actual command man -k <keyword to search> : man -k permission You will find a line in the output that looks something like: chmod (1) . etc. Program source code. lock /var files. just type the “Q” key. etc.g. E.

To return to previous directory cd - To list all files in the current directory To list all files in the current directory. in column format ls To list the files in the specified directory ls <directory name> To list files in “long” format.To change to home or other path relative to home.txt //type the contents and press Ctrl+D to exit To display the contents of a text file cat <file name> To view the contents of a file page by page more <file name> //traversal only in forward direction less <file name> //traversal in both directions To display first few lines of a file head <file name> head -5 <file name> 5 . 1 file per line with additional information ls -l To list all files.. including “hidden” files ls -a To show the directory's detailed information ls -ld <directory name> To list all files whose names begin with the letter “d” in the /usr/bin directory ls /usr/bin/d* To list files based on their size ls -sh To find the type of a file file <file name> To create a file cat > filename. “~” is an alias for your home directory cd ~ To move up one directory cd .

txt /tmp To move a file to a new location mv <source> <destination> : mv mp3files. and then output appended data as the file grows (very useful for following log files!) tail -f /var/log/messages To copy a file from one location to another cp [-r] <source file/directory> <destination> : cp mp3files.child2. and manual page for a command whereis <command name> 6 .txt To create a directory mkdir <directory name> : mkdir dhan mkdir -p <directory path> : mkdir -p /home/sng/dhan To create directories in multiple paths mkdir -p parent/{child1.txt /tmp To delete a file rm [-r] <filename/directory name> : rm /tmp/mp3files.pending}/{a.child3} : mkdir -p work/{in. //first 5 lines To display last few lines of a file tail <file name> tail -5 <file name> //last 5 lines To display the last few lines of a text file. source code.b.out.c} To delete a directory rmdir <directory name> : rmdir /tmp/myfiles/ To show the full path of shell commands found in your path which <command name> : which grep //output like: /bin/grep To locate the program.

-name \*mp3 //starts searching in the current directory “.To search for files anywhere on the file system locate <keyword to search> //find all files and directories that contain the keyword To search for files matching certain patterns find <directory name> <pattern to search> : find . looking for files with “mp3” at the end of their names To list currently running process ps To list all process in the system ps -aux To show who is logged on and what they are doing w who To view the name of current user whoami To view the user details finger To view host name hostname To set host name hostname -a <new host name> To print your user-id and group id's id To get report on file system disk space usage df In MB df -h To view disk usage in a particular directory du To view summary du -s In MB du -h 7 .” and all subdirectories.

txt : chmod -R 777 /home/songs/ { read r=4.To display CPU processes in a full-screen GUI top // type “Q” to quit To display amount of free and used memory in the system free To display information about your CPU cat /proc/cpuinfo To display lots of information about current memory usage cat /proc/meminfo To print system information to the screen uname -a To print kernel version uname -r To display the size of a file wc -l In bytes wc -m In char wc -c In word count wc -w To change permission to a file/directory chmod [-R] <permissions> <file name/directory name> : chmod 754 one. execute x=1 Owner Group Others rwx r-x r-- 7 5 4 } To change ownership of a file/directory chown [-R] <user name> <file name/directory name> : chown dhanoop one.txt : chown -R dhanoop /home/songs/ 8 . write w=2.

To search a file for a particular pattern grep [-R] <word to search> <file name/directory name> : grep science science.txt <command> | lpr : ls -la | lpr To sort a file or program output sort : sort mp3files.txt //multiword search : grep -R passwd /etc/ //search in directory To clear the screen clear To display text on screen echo “<text to display>” : echo “Hello” To print a file or program output lpr <file name> : lpr mp3files.txt //case-sensitive search : grep -i science science.txt To switch user su <user name> //to switch to a particular user account su //to switch to root account su - //to switch to root.txt //case-insensitive search : grep -i ‘spinning top’ science. and log in with root's environment To give an alias name to a command for ease of use alias <name>=”<command>” : alias list=”ls -l” To display last logins of user last 9 .

To display the name of currently working terminal tty To block a user passwd -l <user name> To unblock a user passwd -u <user name> To add a user account useradd [options] <username> With specified home directory useradd -d <home directory> <user name> With specified shell useradd -s <shell> <user name> With specified initial group useradd -g <initial group> <user name> With specified expiry date useradd -e <YYYY-MM-DD> <user name> To lock/unlock a user account usermod [-L or -U] <user name> To delete a user account userdel [-r] <user name> To restart the system shutdown -r now //without delay To turn off the system poweroff To reboot the system reboot To halt the system halt To mount a file system or media mount <source> <destination> : mount /dev/sda1 /mnt //mounting first partition of first SATA hard disk 10 .

All system variables are BLOCK lettered.txt //prints second field : awk ‘{ print $1 $3 }’ sem.txt To print particular fields awk ‘{ print $<field number> }’ <file name> : awk ‘{ print $2 }’ sem. : mount /dev/hdb3 /mnt //mounting third partition of second hard disk To umount a file system or media umount <file system/media> : umount /mnt To view IP address ifconfig To edit IP address temporarily ifconfig -a etho <ipaddress> To view partitions and file systems fdisk -l //view line by line To print selected columns in a file cut -c <column range> <file name> : cut -c 3-5 sem. To know the home directory echo $HOME To print the calendar cal //prints calendar of current month cal <YYYY> : cal 2010 //prints calendar of specified year 11 .txt //prints first and third fields To know the shell echo $SHELL //the symbol “$” precedes every user or system variable.

To print the date date To temporarily switch to root to execute a single command sudo <command> : sudo ifconfig -a eth0 192.101 To run an executable file sh <file name> : sh new\ file //”\ “ denotes white space .1.168./new\ file To view command history history To re execute last command !! To execute nth command in history !n : !444 //executes 44th command in the history To re execute last command that starts with specified character !<char> : !s //executes the last command that starts with letter “s” To repeat the last command changing old character to new character ^old^new : ^l^m //let “wc -l” be the last command now “wc -m” will be executed Signals to a process To list all signals kill -l To kill a process kill <process id> 12 ./<file name> : .

168.101:/home/ 13 .101 df -h //executing “df -h” remotely To copy file from a remote system scp [-r] <source> <destination> : scp /home/a.168.c dhanoopbhaskar@192.168.1.101 To execute a command on remote system through remote login ssh [<user name>@]<ip address> <command> : ssh dhanoopbhaskar@192.1.1.To terminate a process kill -9 <process id> To normally exit a process kill -15 <process id> To login remotely to a system ssh [<user name>@]<ip address> : ssh dhanoopbhaskar@192.