Wednesday, August 15, 2012

Important Linux Commands

ls ------------------------------ List all files and directories
ls -l ------------------------------ List all files and directories with some extra information
dir ------------------------------ Display directories
mkdir <name> ------------------------------ Create a directory
mkidr -p <dir_name1>/<dir_name2>------------------------------Create multiple directories
rmdir <dir_name>------------------------------Remove an empty directory
rm <file_name>------------------------------Remove a file/directory with confirmation
rm -rf <file/dir_name>------------------------------Remove file/directory without confirmation
cat <file_name>------------------------------View a file
cat > <file_name>------------------------------Create a new file and edit it
touch <file_name>------------------------------Create a file
vi <file_name>------------------------------File editor
vim <file_name>------------------------------File editor
command >file_name------------------------------Write output of the command into the file
cd ------------------------------Change directory
cd .. ------------------------------Move one directory back
cd - ------------------------------Move to previous directory
cd ~ ------------------------------Move to current user’s home directory
cd /home/me ------------------------------Move to /home/me directory
shutdown -h now ------------------------------Shuts the system down to halt immediately.
shutdown -r now ------------------------------Shuts the system down immediately and the system reboots.
mv -i myfile yourfile ------------------------------Move the file from “myfile” to “yourfile”. This effectively changes the name of “myfile” to “yourfile”.
mv -i /data/myfile . ------------------------------Move the file from “myfile” from the directory “/data” to the current working directory.
echo <text> ------------------------------Display the text
find ------------------------------Search for files in a directory hierarchy
locate ------------------------------Search for files in a directory hierarchy
grep ------------------------------Depth Search
wc ------------------------------Word count
kill ------------------------------To kill a process
reboot ------------------------------Reboot the system
poweroff ------------------------------poweroff the system
mount ------------------------------mount a partition
umount ------------------------------unmount a partition
fdisk -l ------------------------------Partition manipulator

System Informations
pwd ------------------------------Prints present working directory
hostname ------------------------------Prints hostname
uname ------------------------------ prints the name of OS
whoami ------------------------------ Prints your login name
date ------------------------------ Prints system date
cal <year> ------------------------------Prints calendar of the year
who ------------------------------ Determine the users logged on the machine
w ------------------------------ Determine who is logged on the system
rwho -a ------------------------------ Determine the remote users
finger <user_name> ------------------------------System info about user
last ------------------------------Show list of users last logged-in on your system
lastb ------------------------------Show last unsuccessful login attempts on your system
history ------------------------------Show the used commands
history -c ------------------------------Clears all history
comman ------------------------------Run the most recent command from the bash history commands that start with the string “ comman “
uptime ------------------------------Display the system uptime
ps ------------------------------Process status
ps -aux | more ------------------------------ List all the currently running process
top ------------------------------ List the currently running process, sorted by CPU usage
gtop, ktop, htop ------------------------------ GUI choice for top
arch ------------------------------ Display the system architecture
Xorg -version ------------------------------ Show the version of X windows I have on my system
cat /etc/issue ------------------------------ Check what distribution you are using
free -m ------------------------------ Check your usage, free memory of primary memory
df -h ------------------------------ Disk free information in human readable form
du / -bh | more ------------------------------ Print detailed disk usage for each sub-directory starting at the “/” (root) directory
cat /proc/cpuinfo ------------------------------ Displays cpu information
cat /etc/interrupts ------------------------------ List the interrupts in use
cat /proc/version ------------------------------ Linux version and other info
cat /proc/filesystems ------------------------------ Show the type of filesystem currently in use
cat /etc/printcap | less ------------------------------ Show the setup of printers
lsmod ------------------------------ Show the currently loaded kernel modules
set | more ------------------------------ Show the current user environment
env | more ------------------------------ Show environment variables
dmesg | less ------------------------------ Print kernel messages
chage -l <user_login_name> ------------------------------See my password expiry information
chage username ------------------------------ Change User's Expiry
quota ------------------------------ Display my disk quota
sysctl -a | more ------------------------------ Display all the configurable Linux kernel parameters
runlevel ------------------------------ Print the previous and current runlevel

IP tables
iptables –L ------------------------------ Lists the current filter rules
iptables –F ------------------------------ Flush the rules temporarily / Disable the rules temporarily
iptables –h ------------------------------ Prints help information

ifconfig ------------------------------ Displays all the interface information
ifstat ------------------------------ Check the current network usage
iptraf ------------------------------ A network utility allows you check the network activities
ifup ------------------------------ Bring a network interface up
ifdown ------------------------------ Bring a network interface down

man <command_name> ------------------------------ Display man pages of the command
<command_name> –help ------------------------------ Command help
info <command_name> ------------------------------ Helping command
whatis <command_name> ------------------------------ Display man pages description

Compress and decompress
tar –cvf <file_name.tar> <file_name_1> <file_name_2> . . ------------------------------ Compress files
tar –xvf <file_name.tar> ------------------------------ Decompress the compressed file
tar –xvf <file_name.tar> – C <location> ------------------------------ Decompress files to desired location
tar –zcvf <file_name.tar.gz> <file_name_1> <file_name_2> ------------------------------ Compress files with gz
tar –zxvf <file_name.tar.gz> ------------------------------ Decompress the compressed gz files
tar –zxvf <file_name.tar.gz> -C <location> ------------------------------ Decompress files to desired location

apt-get commands
apt-get install <package_name> ------------------------------ Installing package(s)
apt-get remove <package_name> ------------------------------ Removing package(s)
apt-get update ------------------------------ Update the repository
apt-cdrom add ------------------------------ Add CD ROM archives to repository
apt-cdrom ident ------------------------------ Identify CD-ROM disk
apt-get -d install <package_name> ------------------------------ Download packages, no installation or unpacking
apt-get –purge remove <package_name>--------- Remove all traces of a package, incl. Configuration files etc.,
apt-get –u update ------------------- Upgrades all installed packages, but does not remove any packages to resolve dependencies
apt-get –u dist-upgrade -------------- Upgrades all the installed packages, removes or installs packages as needed to satisfy all dependencies
apt-cache search <package_name> -------------------- Search package in the cache
apt-get check ------------------------------ Check broken dependencies
apt-cache autoclean ------------------------------ Remove cached packages that are no longer needed
apt-cache clean ------------------------------ Remove all cached packages
apt-get help ------------------------------ Help

dpkg commands
dpkg –l ------------------------------ List all the installed packages
dpkg –L <package_name>------------------------------ List files belonging to a package
dpkg –S <file_name> ------------------------------ To See which package a file belongs to
dpkg –s <package_name>------------------------------ To show complete package information
dpkg –yet-to-unpack ------------------------------ To look for downloaded, uninstalled packages
dpkg –audit ------------------------------ Show partially installed packages
dpkg -i <package> ------------------------------ Install a new package
dpkg -r <package> ------------------------------ Remove a package

Yum Commands
yum list [available|installed|extras|updates|obsoletes|all|recent] [pkgspec]
yum list ------------------------------ List packages enabled in the repository
yum list all ------------------------------ List packages enabled in the repository
yum list available ----Lists all the packages available to be installed in any enabled repository on your system
yum list installed -------------------------- Lists all the packages installed on the system
yum list extras -------- Lists any installed package which no longer appears in any of your enabled repositories
yum list obsoletes ------Lists any obsoleting relationships between any available package and any installed package
yum list updates -----Lists any package in an enabled repository which is an update for any installed package
yum list recent -----------------Lists any package added to any enabled repository in the last seven(7) days
yum list pkgspec ---------------------Refine your listing for particular packages
yum check-update -----------------------It returns an exit code of 100 if there are any updates available
yum info -----------------------------Displays information about any package installed or available
yum search ------------------------------ Search and list the packages
yum provides/yum whatprovides Searches for which packages provide the requested dependency of file and also takes wildcards for files
yum clean ------------------------- Clean up the cache of metadata and packages
yum clean packages ----------Cleans up any cached packages in any enabled repository cache directory
yum clean metadata -------Cleans up any xml metadata that may have been cached from any enabled repository
yum clean dbcache ---------------- Clean up the cached copies of those from any enabled repository cache
yum clean all ------------------------------ Clean all cached files from any enabled repository
yum shell / yum makecache ------------------------------These two commands are used to download and make usable all the metadata for the currently enabled yum repos

RPM Commands
rpm –ivh <package_name>--------------------- Install a new package
rpm –Uvh <package_name>------------------- Update an already installed package
rpm –e<package_name> -------------------------- Remove a package
rpm –aq ------------------------------ To list all rpm packages installed on your system
rpm –F <package_name> ------------------------------ Freshening up the already installed package
rpm –version ------------------------------ Prints rpm version

No comments:

Post a Comment