Sunday, February 16, 2014

A to Z LINUX IMPORTANT COMMANDS (VERY USEFUL)

 A to Z LINUX IMPORTANT COMMANDS (VERY USEFUL)

A
alias: If creating an alias is what you want, then this is it.
apropos: We’re not the only ones providing help. This command you to search through the Help manual pages.
apt-get: This one works on Debian and Ubuntu distros. It is used to install and search for software packages.
aptitude: See the similarity with the above command? This one does the same thing.
aspell: Got bad spellings? Use the spell checker.
awk:No, this command is not for awkward situations. It lets you find text and replace it. Also, you can sort, index and validate things in a database.

B
basename: Sometimes files and directories have suffixes to their names. This one strips them off it.
bash: GNU Bourne-Again Shell
bc: This command is an arbitrary precision calculator language
bg: bg could stand for background couldn’t it? Regardless, that’s what it does, sends to the background
break: Exit from a loop
builtin: Run a shell builtin
bzip2: When there’s ‘zip’ in the name, that’s what it does. It compresses or decompresses files that are named.

C
cal: Need a calendar? This command displays one.
case: In ‘case’ you want to perform a command conditionally. This is how to do it.
cat: In programming, ‘cat’ usually stands for concatenate. Here too, but this command displays the content of the files after concatenation.
cd: Change Directory
cfdisk: In Linux, this command is the partition table manipulator
chgrp: This is how you change the ownership of a group.
chmod:‘Ch’ is for change. This one changes the access permissions.
chown: This one sounds too much like clown! Anyway, it’s not funny though. It changes the owner and group of a file.
chroot: Using this you can run a command, but with a different root directory
chkconfig System services (runlevel)
cksum: It displays the CRC checksum ad byte counts.
clear: If you need to clear the terminal screen, use this command.
cmp: Compare two files
comm: Compare two sorted files line by line
command: Run a command - ignoring shell functions
continue: This is for resuming the next iteration of a particular loop.
cp: Make a copy of files to a different location.
cron: Daemon to execute scheduled commands
crontab: Scheduling is sometimes very important. This command does it, it schedules a command that will run at a specified time.
csplit: Split a file into context-determined pieces
cut: When you need to cut down a file into parts, this is the command to use.

D

date: Use this command to change the date and time.
dc: The command stands for Desk Calculator.
ddrescue: Like most other such commands, this is the disk recovery tool.
declare: This command is used to declare the variables and to give attributes.
df: When you want to know the free space on your disk, use this.
diff: This command prints the differences between two files.
diff3: This is the same command as the previous one, but for three files.
dig: Need to lookup the DNS? Use this.
dir: Use this command for listing directory contents briefly.
dircolors: This command is used for colour setup for the ‘ls’ command.
dirname: Use this command to change a full pathname into just a path.
dirs: This command shows you the list of directories that are remembered.
dmesg: Use this command when you want to print kernel and driver messages.
du: Use this command to get an estimation of the file space usage.

E

echo: This command is used for displaying message on the screen.
egrep: This searches for files that have lines matching an extended expression.
eject: Use this when you need to eject a removable media.
enable: Use this to disable or enable bulletin shell commands.
env: Environment variables
ethtool: Ethernet card settings
eval: This command is used when you need to evaluate a many commands.
exec: For executing a command.
exit: Exiting the shell.
expand: This command converts all the tabs to spaces.
export: This command sets an environment variable.
expr: Some evaluate commands, this evaluates expressions.

F

false: Do nothing, unsuccessfully
fdformat: This command is used for low level format of a floppy disk.
fdisk: This is a partition table manipulator for Linux systems.
fg: This command is used for sending a task to the foreground.
fgrep: Use this command to search through files for tasks that match a string.
file: This is used to determine the file type.
find: This is used to find files that match a desired criteria.
fmt: This is used for reformatting paragraph text.
fold: The name is quite suggestive, it wraps text in order to fit a certain width.
format: This simply formats tapes or disks.
free: Use this to see the memory usage.
fsck: This is used for checking the consistency of the file system and repair it.
fuser: This command identifies and kills the process accessing a file.

G

gawk: This command is used to find text within files and replace it.
getopts: Parse positional parameters
grep: Through this you can search in files for lines matching a certain pattern.
groupadd: Use this command to add security user groups.
groupdel: This one is used for deleting a certain group.
groupmod: While the last one deletes, this one modified a group.
groups: Print the names of groups in which an user is located.
gzip: This command is used for compressing and decompressing files.

H

hash: This command is used to refer to the complete pathname of a name argument.
head: Use this for output for the first part of files.
help: Display the built in help for a command.
history: Command History
hostname: Print or set system name

I

iconv: Use this to convert the character set in files.
id: Display the group ids or user ids.
if: Conditional command.
ifconfig: Used to configure network interfaces.
ifdown: Use this command for stopping a network interface.
ifup: Start a network interface app with this command.
import: Used for the X server. Capture a screen and save image.
Install: Set attributes and copy files

J

jobs: Use this for listing jobs that are active.
Join: This one joins lines, which are on a common field.

K

kill: Stops a process from running.
Killall: Kills the processes by name.

L

less: This command displays the output on a single screen at a time.
let: This is for doing arithmetic on shell variables.
link: This command is used for creating a link to another file.
ln: This one creates a symbolic link to another file.
local: Use this for creating variables.
locate: This one is used for finding files.
logname: This is used to print the login name being used currently.
logout: Use this command to exit a login shell.
look: When you just want to see lines that start with a particular string.
lpc: It stands for Line Printer Control.
lpr: This is for offline print.
lprint: Use this command to print a file.
lprintd: Use this to abort an ongoing print job.
lprintq: This command lists the print queue.
lprm: This removes the jobs from the print queue.

M

make: This command is used for recompiling the group of programs.
man: This is short for manual and provides help on a command.
mkdir: Creating directories.
mkfifo: Use this to make FIFOs.
mknod: This is to create character special files or block files.
more: This displays the output, but in a single screen at a time.
mount: Used for mounting a particular filesystem.
mtools: Manipulating files from MS-DOS.
mtr: Network diagnostics command for things like ping and traceroute.
mv: Used for moving and renaming files and directories.
mmv: Mass Move and Rename

N

netstat: Get information on networking.
nice: Use this to set the priority of a job or a command.
nl: Write files and number lines.
nohup: This one runs a command, which is not affected by hangups.
notify-send: This command sends desktop notifications.
nslookup: This command is used to query internet name servers interactively.

O

open: This command opens a file in its default application.
op: Use this command for gaining operator access.

L

less: This command displays the output on a single screen at a time.
let: This is for doing arithmetic on shell variables.
link: This command is used for creating a link to another file.
ln: This one creates a symbolic link to another file.
local: Use this for creating variables.
locate: This one is used for finding files.
logname: This is used to print the login name being used currently.
logout: Use this command to exit a login shell.
look: When you just want to see lines that start with a particular string.
lpc: It stands for Line Printer Control.
lpr: This is for offline print.
lprint: Use this command to print a file.
lprintd: Use this to abort an ongoing print job.
lprintq: This command lists the print queue.
lprm: This removes the jobs from the print queue.

M

make: This command is used for recompiling the group of programs.
man: This is short for manual and provides help on a command.
mkdir: Creating directories.
mkfifo: Use this to make FIFOs.
mknod: This is to create character special files or block files.
more: This displays the output, but in a single screen at a time.
mount: Used for mounting a particular filesystem.
mtools: Manipulating files from MS-DOS.
mtr: Network diagnostics command for things like ping and traceroute.
mv: Used for moving and renaming files and directories.
mmv: Mass Move and Rename

N

netstat: Get information on networking.
nice: Use this to set the priority of a job or a command.
nl: Write files and number lines.
nohup: This one runs a command, which is not affected by hangups.
notify-send: This command sends desktop notifications.
nslookup: This command is used to query internet name servers interactively.

O

open: This command opens a file in its default application.
op: Use this command for gaining operator access.

P

passwd: Use this command to modify user passwords.
paste: This command is used for merging lines in files.
pathchk: It is used to check the portability of a file name.
ping: This command is used for testing network connections.
pkill: This command stops processes from running.
popd: This command restores the previous value of the directory you’re currently in.
pr: Prepare your files for printing using this.
printcap: Printer capability database
printenv: Print environment variables
printf: This command is used for formatting and printing data.
ps: This stands for Process Status.
pushd: Change the directory and save it first.
pwd: It stands for Print Working Directory.

Q

quota: This command displays the disk usage and its limits.
quotacheck: This commands lets you scan a file system to find its disk usage.
quotactl: This is used to set disk quotas.

R

ram: Ram disk device
rcp: When using two machines, this command copies files between them.
read: This commands is used for reading a line from standard input.
readarray: This commands reads from stdin into an array variable.
readonly: This command marks the variables and functions as readonly.
reboot: Self explanatory, use this command to reboot your system.
rename: Rename files
renice: This command alters the priority of the processes running.
remsync: This command synchronises remote files through email.
return: This is used to exit from a shell function.
rev: This command reverses the lines in a file.
rm: Use this to remove particular files.
rmdir: Same as above, but for directories.
rsync: This is for synchronising file trees.

S

screen: Use this to run remote shells using ssh.
scp: This is used to create a secure copy.
sdiff: This command is used to merge two files in a secure manner.
sed: This is for the stream editor.
select: This is used when you need to accept keyboard inputs.
seq: This command is used for printing numeric sequences.
set: This command lets you manipulate shell functions and variables.
sftp: Run the secure file transfer program using this.
shift: This command is used for shifting positional parameters.
shopt: Shopt stands for Shell Options.
shutdown: Use this command when you want to shutdown Linux or restart it.
sleep: Add a delay using this command.
slocate: This is used to find particular files.
sort: Text files are sorted using this.
source: This command is used for running commands from a file.
split: This command is used to break a file into fixed sizes.
ssh: This is used to run the remote login program, that is, the secure shell client.
strace: This is used to trace signals and system calls.
su: Substitute the user identity using this command.
sudo: This is used for executing commands as a different user.
sum: File cheksums are printed using this command.
suspend: This command is used to suspend the execution of the current shell.
sync: This command is used in order to synchronise data from a disk with the memory.

T
tail: Use this command when you want to output only the last part of a file.
tar: This command is used in order to store a list or extract files in an archive.
tee: This command is used for redirecting output into multiple files.
test: This command is used for evaluating conditional expressions.
time: The running time of a program can be measured using this command.
timeout: This command is used to put a time limit on a command.
times: Use this to find the user and system times.
touch: Timestamps on a file can be changed using this.
top: This is used to get a list of the processes that are running on the system.
traceroute: Use this command to Trace Route to a host.
tr: Delete characters, translate or squeeze them.
tsort: This is used for topological sorting.
tty: This is used for printing the filename of terminal on stdin.

U

ulimit: This commands limits the user resources.
umask: This is used to determine the file permission for a new file.
umount: This command will unmount a device from the system.
unalias: This command will remove an alias.
uname: This command will print the system information.
unexpand: This command will convert the spaces in a file to tabs.
uniq: This command will uniquify your files.
units: This will convert the units from one scale to another.
unset: This command removes the variable names or the function names.
unshar: This command unpacks the shell archive scripts.
until: This command will execute a command until there is an error.
uptime: This command will show the uptime.
useradd: Use this command when you need a new user account to be created.
userdel: This command will delete an user account from your system.
usermod: Self explanatory, modify an user account.
users: This command gives you a list of users who are currently logged in.
uuencode: This command will encode binary files.

V

v: This command lists the contents of a directory.
vdir: Same as above.
vi: This is a text editor.
vmstat: This command will report on the virtual memory statistics.

W

wait: This command directs the system to wait for a process to finish.
watch: This command will display or execute a program periodically.
wc: This command prints the word, byte and line counts.
whereis: This command will search a user’s $path, source files and man pages
which: This command searches only for a user’s $path for a program.
while: Use this to execute commands.
who: This command will print the usernames that are currently logged into the system.
whoami: This is a command that prints the current name and user id.
wget: This will retrieve the web pages or files through HTTP, HTTPS or FTP.
write: Use this to send messages to other users.

X

xargs: This command execute’s a utility and passes a constructed argument list.
xdg-open: This lets you open an URL or a file in the user's preferred application.

Y
yes: This command will print a string until it is interrupted.

Wednesday, May 8, 2013

Linux Which Command, Whatis Command, Whereis Command Examples

 

12 Linux Which Command, Whatis Command, Whereis Command Examples


This Linux tutorial will explain the three “W” commands. The three “W”s are whatis, whereis and which commands.

You already know how to use find command to efficiently fo find a file.
Now, these three W commands will help you to locate more stuff from Linux command line.

I. Linux whatis Command

Whatis command is helpful to get brief information about Linux commands or functions. Whatis command displays man page single line description for command that matches string passed as a command line argument to whatis command. Whatis command searches for string in its index databases which is maintained by mandb program. Whatis command picks short description of NAME section of man page of command that matches to input given to the whatis command.
Whatis provides several command line options to help user in getting brief information of specific Linux commands as per their need or interest.
Syntax:
$ whatis [-options]
For example, here is the output of whatis command, when it is run without any option.
$ whatis write
write (1)            - send a message to another user
write (2)            - write to a file descriptor
It displays brief information about “write” from man pages.

1. Get information from specific sections of man pages using -s option

If we want to get Linux command information from specific section of man pages, then we can provide sections list using “-s or —sections or –section” option. It will restrict whatis command to display brief information from specified man page section only.
$ whatis -s "1","2" open
open (1)             - start a program on a new virtual terminal (VT).
open (2)             - open and possibly create a file or device
It displays open command and function brief information from man page sections 1 and 2.
$ whatis -s "2" open
open (2)             - open and possibly create a file or device
It displays open function brief information from man page section 2.

2. Search information through wild-cards using -w option

If we want to search Linux commands or functions information using wild card, then whatis command gives “-w or –wildcard” option. It will make your search specific as per user’s need.
$ whatis -w 'ab*'
abort (3)            - cause abnormal process termination
abs (3)              - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab”.
$ whatis -w 'ab?'
abs (3)              - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab” and followed by any single character.

3. Search information through regular expressions using -r option

If we want to search Linux commands or functions information using regular expressions, then whatis command gives “-r or –regex” option. It will give flexibility to customize your search for Linux commands or functions throughout the Linux system.
$ whatis -r '^ab'
abort (3)            - cause abnormal process termination
abs (3)              - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab”.
$ whatis -r 'ab$'
anacrontab (5)       - configuration file for anacron
baobab (1)           - A graphical tool to analyse disk usage
crontab (1)          - maintain crontab files for individual users (Vixie Cron)
crontab (5)          - tables for driving cron
fstab (5)            - static information about the filesystems
inittab (5)          - init daemon configuration
swab (3)             - swap adjacent bytes
tc-stab (8)          - Generic size table manipulations
It displays brief information of Linux commands or functions which ends with “ab”.

4. Disable trimmed output using -l option

Generally whatis command trims long output of Linux commands or functions information to avoid “Not good” output display on terminal that is going beyond screen. To allow whatis command to show complete output on screen, “-l or –long” option can be used.
$ whatis ssh-import-id
ssh-import-id (1)    - retrieve one or more public keys from a public keyserver (Launchpad.net by default) and append them to the current user's authorized_keys file (or some other specifie...
It displays trimmed output of brief information of Linux command.
$ whatis -l ssh-import-id
ssh-import-id (1)    - retrieve one or more public keys from a public keyserver (Launchpad.net by default) and append them to the current user's authorized_keys file (or some other specified file)
It displays complete output of brief information of Linux command.

5. Restrict search up to specified path using -M option

By default, whatis command uses $MANPATH environment variable. But whatis provides “-M or –manpath” option to restrict search up to specified path of man pages.
$ whatis -M /usr/share/man hexdump
hexdump (1)          - ASCII, decimal, hexadecimal, octal dump
It displays brief information of Linux hexdump command from man pages available at path /usr/share/man.
$ whatis -M /usr/man hexdump
hexdump: nothing appropriate.
It could not find brief information of Linux hexdump command from specified path /usr/man.

II. Linux whereis Command

Whereis command is helpful to locate binary, source and manual pages of commands in the Linux system. It is very simple utility and provides several options which are given below with examples.
Syntax:
$ whereis [-options]
For example, whereis command is run without any option.
$ whereis open
open: /bin/open /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz
It locates binary, source and man pages of “open” command and here it displayed paths where binary, man pages of open command is available in the system.

6. Locate binaries using -b option

If we want to locate binary of Linux command, use “-b” option.
$ whereis -b whereis
whereis: /usr/bin/whereis /usr/bin/X11/whereis
It locates binary of “whereis” command and displays paths where binary of command is available in the system.

7. Locate man pages for a command using -m option

If we want to locate man page of Linux command, use “-m” option.
$ whereis -m whereis
whereis: /usr/share/man/man1/whereis.1.gz
It locates man page of “whereis” command and displays path where man page of command is available in the system.

8. Locate source of a command using -s option

If we want to locate source of Linux command, use “-s” option.
$ whereis -s whereis
whereis:
It locates source of “whereis” command, but source of “whereis” command does not exist in the system, so it did not display path for source of command in the system.

9. Locate unusual entries using -u option

This option is something different that searches for unusual entries. These entries are those command whose source, binary or man page does not exist in the system as per options “[-bms]” specified along with “–u”.
$ whereis  -m  -u wcgrep
wcgrep:
It checks if specified command (i.e. wcgrep) man page does not exist in the system. Whereis command with options “-m and -u” locates for the commands in the system whose man page does not exist.
$ whereis  -m  -u grep
$
Here, whereis command with same options is applied on “grep” command whose man page exists in the system, so whereis returned nothing and exits normally.

10. Locate binaries in a specified path using -B option

If user wants to search for binary and wants to limit the scope of search for whereis command up to specified path, then use “-B” option.
$ whereis -B /bin -f for_loop
for_loop: /bin/for_loop
It locates binary of “for_loop” user program from path “/bin”.
$ whereis -B /usr -f open
open: /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz
If open command’s binary is not found at specified path, then it is not shown but whereis command by default searches for other types (i.e. man page and source) of specified command (i.e. open) and displays them if found.

11. Locate man pages with limited scope using -M option

If user wants to search for man pages and wants to limit the scope of search for whereis command up to specified path, then use “-M” option.
$ whereis -M /usr/share/man/man1 -f open
open: /bin/open /usr/share/man/man1/open.1.gz
$ whereis -M /usr/share/man/man2 -f open
open: /bin/open /usr/share/man/man2/open.2.gz
$ whereis -M /usr/share/man/man3 -f open
open: /bin/open
Here, it is observed that whereis command is displaying man page of “open” command which is available in specified path only. But, whereis command by default searches for other types (i.e. binary and source) of specified command (i.e. open) and displays them if found.

III. Linux which Command

Which command is very small and simple command to locate executables in the system. It allows user to pass several command names as arguments to get their paths in the system. “which” commands searches the path of executable in system paths set in $PATH environment variable.
Syntax:
$ which [-option]
For example,
$ which ls gdb open grep
/bin/ls
/usr/bin/gdb
/bin/open
/bin/grep
It locates command names – “ls”, “gdb”, “open” and “grep” specified as arguments to “which” command and displays paths of each executable where it exists in the system.

12. Display all the paths using -a option

“which” command gives option “-a” that displays all paths of executable matching to argument.
$ which echo
/usr/sbin/echo
Above will search display the executable “echo” from all paths set in $PATH environment variable and displays the first path where echo executable is found. It may be case that executable is placed at other paths of $PATH environment variable as well. To get all paths where executable is present in the system, “-a” option can be used.
$ which -a  echo
/usr/sbin/echo
/bin/echo

Sunday, April 21, 2013

Linux Directory Structure

File System Structure. HRFS

every thing starts with  /  (forward Slash) in Unix Family .



1. / – Root

  • Every single file and directory starts from the root directory.
  • Only root user has write privilege under this directory.
  • Please note that /root is root user’s home directory, which is not same as /.

2. /bin – User Binaries

  • Contains binary executables.
  • Common linux commands you need to use in single-user modes are located under this directory.
  • Commands used by all the users of the system are located here.
  • For example: ps, ls, ping, grep, cp.

3. /sbin – System Binaries

  • Just like /bin, /sbin also contains binary executables.
  • But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.
  • For example: iptables, reboot, fdisk, ifconfig, swapon

4. /etc – Configuration Files

  • Contains configuration files required by all programs.
  • This also contains startup and shutdown shell scripts used to start/stop individual programs.
  • For example: /etc/resolv.conf, /etc/logrotate.conf

5. /dev – Device Files

  • Contains device files.
  • These include terminal devices, usb, or any device attached to the system.
  • For example: /dev/tty1, /dev/usbmon0

6. /proc – Process Information

  • Contains information about system process.
  • This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.
  • This is a virtual filesystem with text information about system resources. For example: /proc/uptime

7. /var – Variable Files

  • var stands for variable files.
  • Content of the files that are expected to grow can be found under this directory.
  • This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);

8. /tmp – Temporary Files

  • Directory that contains temporary files created by system and users.
  • Files under this directory are deleted when system is rebooted.

9. /usr – User Programs

  • Contains binaries, libraries, documentation, and source-code for second level programs.
  • /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp
  • /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
  • /usr/lib contains libraries for /usr/bin and /usr/sbin
  • /usr/local contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2

10. /home – Home Directories

  • Home directories for all users to store their personal files.
  • For example: /home/john, /home/nikita

11. /boot – Boot Loader Files

  • Contains boot loader related files.
  • Kernel initrd, vmlinux, grub files are located under /boot
  • For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

12. /lib – System Libraries

  • Contains library files that supports the binaries located under /bin and /sbin
  • Library filenames are either ld* or lib*.so.*
  • For example: ld-2.11.1.so, libncurses.so.5.7

13. /opt – Optional add-on Applications

  • opt stands for optional.
  • Contains add-on applications from individual vendors.
  • add-on applications should be installed under either /opt/ or /opt/ sub-directory.

14. /mnt – Mount Directory

  • Temporary mount directory where sysadmins can mount filesystems.

15. /media – Removable Media Devices

  • Temporary mount directory for removable devices.
  • For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer

16. /srv – Service Data

  • srv stands for service.
  • Contains server specific services related data.
  • For example, /srv/cvs contains CVS related data.


UA-39498145-1