Commands
Linux Commands By Vishal Vyas
Encryption tools
- gpg - Encrypts data using GNU Privacy Guard.
- mcrypt - Encrypts the specified file.
- mimencode - Encodes the specified binary file to on eof the ASCII encoding formats.
- mpack - Pack a file in MIME format.
- uuencode - Encodes the specified binary file so that it can be transferred over a medium which does not support non-ASCII characters.
Decryption tools
- gpg - Decrypts data using GNU Privacy Guard.
- mdecrypt - Decrypts any file with the .enc suffix, that was encrypted by mcrypt.
- munpack - unpack messages in MIME or split-uuencode format.
- uudecode - Decodes the uuencode coded file.
- uudeview - a powerful decoder for binary files.
- cd - Change directories
- df - print the free space available in a directory
- du - print the size of a directory
- ln - Create a link to a file or directory
- ls - Lists the files contained in the directory
- mkdir - Create a new directory
- pwd - Print the current working directory
- rmdir – Remove the specified directory
- symlinks - Find symbolic links
Partitioning
- cfdisk - Interactive hard disc partition utility for text mode.
- fdisk - Launches a menu-driven program that partitions a hard disk.
- parted - command line partitioning tool. (parted sometimes complains about boundaries of partitions created with fdisk. parted can format a partition of type ext2 or fat32 partition while creating it.)
Formatting
- mkfs - front-end to various filesystem-creation tools
- parted can create a filesystem while partitioning
- mkfs.vfat /dev/sde1 to format a fat32 partition sde1
- mkfs.ext2 /dev/sde2 to format an ext2 partition sde2
Tuning
- tune2fs - command to tune ext2/ext3 filesystems
- tune2fs -j /dev/sde2 to convert an ext2 filesystem sde2 to ext3 by adding a journal
- tune2fs -L /dev/sde2 bulkdata to set the volume label of sde2 to “bulkdata”
- debugfs - Interactive utility to repair the ext2 filesystem on specified drive.
- e2fsck- Performs an analysis of the filesystem’s integrity and optionally repairs errors.
- badblocks - Scans the specified drive for bad blocks.
Using a configured hard drive or tape
- df - Displays the amount of disc space used and remaining on all mounted filesystems.
- hwinfo - Automatically recognizes all available CD-ROM drives.
- mount - Attaches the device to a specified directory, which will serve as the filesystem’s mount point.
- sync - Flushes the filesystem buffers.
- umount - Unmounts the filesystem specified by the device.
- du - Displays the amount of disc space used in the current directory.
- duchs – Lists the largest directories in human readable format
- eject - Ejects the media in the specified drive.
Rescuing
- mc (midnight commander) – Command line file manager. Can undelete files in unmounted ext2 filesystems.
Backing-up
- partimage - Backs up disk partitions into image files and restores them.
Logical Volume Management
See LVM.
File Search
- find - Versatile tool for searching for files based on name, size, date, etc.
- locate - Lists all files with a given word in the name
- whereis - Finds commands, source, and manpages
- which - Finds commands on the path
- grep - Searches for text/patterns within a file
File Analysis
- cksum - Calculate the checksum of a file.
- diff - Find differences between two files.
- file - Determine file type.
- ls - List the contents of a directory.
- lsattr - List the attributes of a file.
- md5sum - Calculate or check the MD5 checksum of a file
- wc - Displays line, word and character count for specified filename.
File Manipulation
- cp - Copy a file from one location to another.
- dd - Copies a file and performs various conversions at the same time.
- some dd examples – This is good stuff. Must read for anyone serious about Linux
- du - Shows disk usage of files
- install - Copy file(s), preserving permissions.
- ln - Create a link to a file.
- mv - Rename or move a file.
- rename - Another renaming tool
- rm - Remove (delete) a file.
File Attribute Manipulation
- chgrp - Change the group ownership of a file or directory.
- chmod - Change the mode (access permissions) of a file or directory.
- chown - Change the ownership of a file or directory.
- getfacl - View the acl permissions associated with the file or directory.
- setfacl - Change the acl permissions associated with the file or directory.
- touch - Update access times or, potentially, create a file.
File usage
- lsof - List all currently opened files
- fuser - List which processes that are currently using a specific file
Managing Sessions
- login - prompts the user for username and password.
- nohup - Prevents programs from getting killed on logout.
- rlogin - enables you to establish a user session on another computer connected to the LAN. Deprecated, safety-hazard. Use ssh instead.
- screen - Terminal multiplexer. This is somewhat like a virtual terminal, only much more powerful.
- shutdown - Shuts down the system.
- startx - This shell script, enables you to start a X session.
- tty - Displays the number of the terminal device that is currently in use.
- xdm, kdm, gdm - Starting the X (KDE, Gnome) Display Manager
- xterm - Starts the xterm terminal emulation program. requires the X window system.
See also
- shared session
- terminal server
Packing files
To pack means to unite several files in one file, called an archive. Typical commands for packing under Linux are
- zip — for .zip files
Example:
zip -r targetfile sourcedirectory
- tar — for .tar and .tar.gz files
Example (creates a .tar.gz file):
tar cvzf targetfile.tar.gz sourcedirectory
- bzip2 — for .bz2 files
Example:
bzip2 sourcefile
Unpacking files
How to unpack files depends on their suffix:
- .tar.gz
unpack with the command
tar xvzf archive.tar.gz
where archive is the archive’s name without suffix
- .tar
unpack with the command
tar xvf archive.tar
where archive is the archive’s name without suffix
- .zip
unpack with the command
unzip archive.zip
where archive is the archive’s name without suffix
- .bz2
unpack with the command
bunzip2 archive.bz2
where archive is the archive’s name without suffix
- .rar
unpack with the command
unrar x archive.rar
where archive is the archive’s name without suffix
Some programming-related commands:
- compiling
- g++ — C++ front-end to GCC.
- gcc — “GNU Compiler Collection”. Also C compiler.
- gcj — Java front-end to GCC.
- as – the portable GNU assembler
- linking and libraries (see also Library-related_Commands_and_Files)
- ar – tool for creating, modifying, and extracting from archives
- ld – the GNU linker
- ldconfig
- ldd
- ld.so
- pkg-config – tool for outputting linker and compiler flags for a given library
- dealing with object files (see also binutils)
- nm – lists symbols from object files
- objcopy – copies and translates object files
- objdump – display information from object files
- readelf – displays information about ELF files
- lexical analyzer and parser
- bison (the yacc replacement)
- flex (the lex replacement)
- debugging
Main article: debuggers- ddd
- gdb
- lint
- valgrind
- gprof – fight performance problems using profiling
- build tools
- autoconf – generates configuration scripts
- automake – automatically generates ‘Makefile.in’s from ‘Makefile.am’s
- ant
- jam
- libtool
- make, makefile, configure script
- scons
- source code tagging
- ctags — for vim- and NEdit-compatible tag files
- etags — for emacs-compatible tag files
- revision control
- GNU Arch
- Bazaar-NG — aka “Bazaar 2″, aka “bzr”
- CVS
- git
- RCS
- Subversion
- misc
- addr2line – converts addresses into file names and line numbers
- file – find out file type (like “link”, “executable” or shared object)
- strings – finds printable strings in a file
Bash scripting
Main article: bash tips
Hello world
The minimal bash script that only outputs “hello world” looks like this:
#!/bin/bash echo "hello world"
Find out your distribution
Main article: find out your distribution
The following script tells you what distribution you have installed on your computer.
#!/bin/bash found=0; if [ -e /etc/SuSE-release ]; then echo "You have a SUSE distro"; export found=1; fi if [ -e /etc/redhat-release ]; then echo "You have a Red Hat distro"; export found=1; fi if [ -e /etc/fedora-release ]; then echo "You have a Fedora distro"; export found=1; fi if [ -e /etc/debian-version ]; then echo "You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro"; export found=1; fi if [ -e /etc/slackware-version ]; then echo "You have a SlackWare distro"; export found=1; fi if ! [ $found = 1 ]; then echo "I could not find out your distro"; fi
It looks if the respective files exist (if [ -e /etc/SuSE-release ];) and prints the distribution they flag (using the command echo).
Tonka Script
Changes your console to some other colours.
#!/bin/bash
function tonka {
# Named "Tonka" because of the colour scheme
local WHITE="\[33[1;37m\]"
local LIGHT_BLUE="\[33[1;34m\]"
local YELLOW="\[33[1;33m\]"
local NO_COLOUR="\[33[0m\]"
case $TERM in
xterm*|rxvt*)
TITLEBAR='\[33]0;\u@\h:\w07\]'
;;
*)
TITLEBAR=""
;;
esac
PS1="$TITLEBAR\
$YELLOW-$LIGHT_BLUE-(\
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\
$LIGHT_BLUE)-(\
$YELLOW\$PWD\
$LIGHT_BLUE)-$YELLOW-\
\n\
$YELLOW-$LIGHT_BLUE-(\
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \"+%a,%d %b %y\")\
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR "
PS2="$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR "
}
Get your ip
#!/bin/bash
# get ip
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'
To get your Internet address if you are behind a NAT:
## The -n option retrieves the Internet IP address
## if you are behind a NAT
if [ "$1" = "-n" ]
then
ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)
else
if=$1 ## specify which interface, e.g. eth0, fxp0
system=$(uname)
case $system in
FreeBSD) sep="inet " ;;
Linux) sep="addr:" ;;
esac
temp=$(ifconfig $if)
temp=${temp#*"$sep"}
ip=${temp%% *}
fi
printf "%s\n" "$ip"
### CFAJ ###
A shell, also known as a command interpreter, is a specialized program for accepting typed user commands, translating those into programs to run, running those programs, and displaying (or doing something) with the results. A “common” example of a shell is the DOS shell, called COMMAND.COM, which was the complete user interface before Windows.
Different shells exist, offering different feature sets. Two main families of shell exist: the Bourne shell and its variants (sh, bash, ksh) and the C shell and its variants (csh, tcsh). Though many shells have features common to others, the way they make use of those features is unique, so that (for example) Bourne shell conventions don’t usually apply to C shells.
- bash – The Bourne-Again SHell – feature-rich default Linux shell.
- csh - A shell with C-like syntax, with file name completion and command line editing – usually tcsh on modern Linux.
- fish - ‘friendly’ interactive shell
- ksh - Korn SHell – part of the sh rather than csh family.
- sh - the original shell, often a symlink to bash on modern Linux and the most portable.
- tcsh - An extended version of csh, with all its features and some additional ones.
- zsh - One of the newest and most feature-rich shells.
General System Information Tools/Utilities
- cat /var/log/messages — is the same as dmesg
- dmesg – kernel messages given during booting.
- kinfocenter – good overview
- tail -f /var/log/messages — show the last couple of lines and keep outputting new lines
- uname -a — brief OS and kernel information.
Memory Diagnostic Tools/Utilities
- cat /proc/meminfo — static information about your RAM
- ksysguard – real-time RAM and CPU utilization printout and process table
- top – real-time RAM and CPU utilization printout
- free – current memory/swap utilization.
CPU Diagnostic Tools/Utilities
- cat /proc/cpuinfo – static information about your CPU
- hwinfo --cpu — static information about your CPU
Disk and File System Diagnostic Tools/Utilities
- cat /etc/fstab — show configuration file for file system mounting.
- df -h — current disk space usage (“-h” gives human-readable output)
- du -h — determine how much disk space is being used by Cwd, or any directory you specify after the du command (as in df, the “-h” means human-readable)
- fdisk -l [/dev/hda] — show partition table(s), leave off device name to list all
- mount or cat /etc/mtab — show currently mounted file systems.
Local Devices Diagnostic Tools/Utilities
- dmidecode – get all bios information, e.g. computer type.
- hwinfo --pci — list devices on the pci bus.
- hwinfo --scsi — list all scsi devices.
- hwinfo --usb — list all usb devices.
- lsdev – list all installed hardware.
- lspci – list devices on the pci bus.
- lsscsi – list all scsi devices.
- lsusb – list all usb devices.
- setserial -bg /dev/ttyS[0-9]* — list all active serial devices(/dev/ttyS*).
Kernel and Kernel Module Diagnostic Tools/Utilities
- lsmod – list kernel modules currently loaded.
Network Diagnostic Tools/Utilities
- Directory /proc/net/
- File arp: arp cache. Maps IP address to MAC address
- File dev: byte and packet statistics on a per device basis.
- File netstat: various statistics
- File tcp: established connections.
- Directory /proc/sys/net/ipv4/
- File: ip_forward: read/write. Whether or not the kernal will forward IP packets from one interface to another. This is turned on if you want the machine to work as a router or a firewall.
- ethtool $interface — show the card’s speed, capabilities and if a link is detected
- hwinfo --netcard — show the module name, driver activation command, network card name etc.
- ifconfig -a — show all current network interface information
- ifconfig $interface — show the information for $interface (usually something like ifconfig eth0)
- ping $host — use ping to determine if $host is alive on the network (for troubleshooting your local machine $host can equal “127.0.0.1″ or “localhost”
- route -n — show routing table, using numerical addresses.
If you want to set up a proxy firewall, this should be off, as it will be the application that forwards traffic, not the kernel.
- File: ip_local_port_range: read/write. The range of ports that are used as source ports for outgoing connections.
- File: tcp_sack: read/write. Whether or not TCP connections use selective acknowledgement. One=yes, zero=no.
- File: tcp_timestamps: read/write. Whether or not TCP connections add timestamps to their connections. One=yes, zero=no.
Dynamic information
Or: What does my hardware do?
- ethereal – a network sniffer
- lm-sensors — read CPU temperature etc.
- ksysguard – CPU, network load etc. comprehensively
- top – top CPU consuming processes
- vmstat – CPU load, swapping and I/O
- xosview – CPU, network load etc. to get an overview
X-Windows Troubleshooting Tools/Utilities
- cat /var/log/XFree86.0.log — print out the XFree86 error log.
- Note that some systems do not store this log in /var/log. Use either locate XFree86.0.log or find / -name XFree86.0.log to find it.
- glxinfo – show the status of your OpenGL subsystem.
This is a list of startup/shutdown-related commands:
- dmesg - display bootup messages.
- halt - halt the system. (not recommened – use shutdown -h now instead)
- init - set runlevel, or define processes that are begun on a specific runlevel.
- reboot - reboot the system.
- runlevel - show the current system runlevel.
- shutdown - shutdown the system.
- swapoff - disable the paging hardware.
- swapon - enable the paging hardware.
- sync - write buffered memory out to disk.
- telinit - move the system to a new runlevel.
- awk - A utility and scripting language
- cat - Con-cat-enate file(s) to stdout
- cut - Extract portions of lines
- diff - Compare differences of files
- ed - The editor. ED!
- egrep - See grep
- fgrep - See grep
- grep - Global/regular expression/print (print lines matching an expression)
- head - View the top of a file
- less - A more powerful pager
- more - A less powerful pager
- nl - Number lines of files
- sed - Stream editor (non-interactive programmatic editor)
- sort - Sort input
- tac - Cat lines in reverse
- rev - Cat characters in reverse
- tail - View the bottom of a file
- tr - Transform/transliterate text
- uniq - Manipulate duplicate lines of a sorted file
Text processors in file utils’ clothing
- basename - cut a line to the right from the last slash (works with any input)
- dirname - cut a line to the left from the last slash (works with any input)
User Commands
- date - Print or set the system date and time.
- finger - Display information about a user. May be turned off by default.
- id - Display UID and group info about a user.
- passwd - Change a user’s password.
- quota - Assign quota for users and groups.
- su - Change to root or another user id.
- useradd - Add a new user to the system.
- userdel - Delete a user from the system.
- usermod - Modify user information on the system.
- users - Display a list of current users.
- who - Display a list of current users.
- whoami - Print the user name associated with the effective UID.
- w - Display who is logged on and what they are doing.

It is very helpful for us
u r such Linux guru