LINUX SHELL COMMANDS WITH DESCRIPTION
System information Command Description # arch show architecture of machine(1) # cal 2007 show the timetable of 2007 # cat /proc/cpuinfo show information CPU info # cat /proc/interrupts show interrupts # cat /proc/meminfo verify memory use # cat /proc/swaps show file(s) swap # cat /proc/version show version of the kernel # cat /proc/net/dev show network adpters and statistics # cat /proc/mounts show mounted file system(s) # clock -w save date changes on BIOS # date show system date # date 041217002007.00 set date and time - MonthDayhoursMinutesYear.Seconds # dmidecode -q show hardware system components - (SMBIOS / DMI) # hdparm -i /dev/hda displays the characteristics of a hard-disk # hdparm -tT /dev/sda perform test reading on a hard-disk # lspci -tv display PCI devices # lsusb -tv show USB devices # uname -m show architecture of machine(2) # uname -r show used kernel version
Shutdown, Restart and Logout of a system Command Description # init 0 # logout leaving session # reboot # shutdown -h now # shutdown -h 16:30 & # shutdown -c # shutdown -r now # telinit 0
Files and DirectoryCommand Description # cd /home # cd .. # cd ../.. # cd # cd ~user1 # cd - # cp file1 file2 # cp dir/* . # cp -a /tmp/dir1 . # cp -a dir1 dir2 # cp file file1 # iconv -l # iconv -f fromEncoding -t toEncoding inputFile > outputFile # find . -maxdepth 1 -name *.jpg -print -exec convert # ln -s file1 lnk1 # ln file1 lnk1 # ls # ls -F # ls -l # ls -a # ls * 0-9 * # lstree # mkdir dir1 # mkdir dir1 dir2 # mkdir -p /tmp/dir1/dir2 # mv dir1 new_dir # pwd # rm -f file1 # rm -rf dir1 # rm -rf dir1 dir2 # rmdir dir1 # touch -t 0712250000 file1 # tree
File searchCommand Description # find / -name file1 search file and directory into root filesystem from '/' # find / -user user1 # find /home/user1 -name \*.bin # find /usr/bin -type f -atime +100 # find /usr/bin -type f -mtime -10 # find / -name *.rpm -exec chmod 755 '{}' \; # find / -xdev -name \*.rpm # locate \*.ps # whereis halt # which halt
Mounting a FilesystemCom d Description # fuser -km /mnt/hda2 # mount /dev/hda2 /mnt/hda2 # mount /dev/fd0 /mnt/floppy # mount /dev/cdrom /mnt/cdrom # mount /dev/hdc /mnt/cdrecorder # mount /dev/hdb /mnt/cdrecorder # mount -o loop file.iso /mnt/cdrom # mount -t vfat /dev/hda5 /mnt/hda5 # mount /dev/sda1 /mnt/usbdisk # mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share # umount /dev/hda2 # umount -n /mnt/hda2
Disk SpaceCommand Description # df -h # dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n # du -sh dir1 # du -sk * | sort -rn # ls -lSr |more # rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n
Users and GroupsCommand Description # chage -E 2005-12-31 user1 # groupadd group # groupdel group # groupmod -n moon sun # grpck # newgrp - group # passwd # passwd user1 # pwck # useradd -c "User Linux" -g admin -d /home/user1 -s /bin/bash user1 # useradd user1 # userdel -r user1 # usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1
Permits on Files
CommandDescription # chgrp group1 file1 # chmod ugo+rwx directory1 # chmod go-rwx directory1 # chmod u+s /bin/file1 # chmod u-s /bin/file1 # chmod g+s /home/public # chmod g-s /home/public # chmod o+t /home/public # chmod o-t /home/public # chown user1 file1 # chown -R user1 directory1 # chown user1:group1 file1 # find / -perm -u+s # ls -lh # ls /tmp | pr -T5 -W$COLUMNS
Special Attributes on filesCommand Description # chattr +a file1 # chattr +c file1 # chattr +d file1 # chattr +i file1 # chattr +s file1 # chattr +S file1 # chattr +u file1 # lsattr
Archives and compressed filesCommand Description # bunzip2 file1.bz2 # bzip2 file1 # gunzip file1.gz # gzip file1 # gzip -9 file1 # rar a file1.rar test_file # rar a file1.rar file1 file2 dir1 # rar x file1.rar # tar -cvf archive.tar file1 # tar -cvf archive.tar file1 file2 dir1 # tar -tf archive.tar # tar -xvf archive.tar # tar -xvf archive.tar -C /tmp # tar -cvfj archive.tar.bz2 dir1 # tar -xvfj archive.tar.bz2 # tar -cvfz archive.tar.gz dir1 # tar -xvfz archive.tar.gz # unrar x file1.rar # unzip file1.zip # zip file1.zip file1 # zip -r file1.zip file1 file2 dir1
RPM Packages ( Fedora, Red Hat and like)Command Description # rpm -ivh package.rpm # rpm -ivh --nodeeps package.rpm # rpm -U package.rpm # rpm -F package.rpm # rpm -e package # rpm -qa # rpm -qa | grep httpd # rpm -qi package # rpm -qg "System Environment/Daemons" # rpm -ql package # rpm -qc package # rpm -q package --whatrequires # rpm -q package --whatprovides # rpm -q package --scripts # rpm -q package --changelog # rpm -qf /etc/httpd/conf/httpd.conf # rpm -qp package.rpm -l # rpm --import /media/cdrom/RPM-GPG-KEY # rpm --checksig package.rpm # rpm -qa gpg-pubkey # rpm -V package # rpm -Va # rpm -Vp package.rpm # rpm -ivh /usr/src/redhat/RPMS/`arch`/ package.rpm # rpm2cpio package.rpm | cpio --extract --make-directories *bin* # rpmbuild --rebuild package.src.rpm
YUM packages tool (Fedora, RedHat and alike)Command Description # yum -y install package # yum localinstall package.rpm # yum -y update # yum update package # yum remove package # yum list # yum search package # yum clean package # yum clean headers # yum clean all
DEB packages (Debian, Ubuntu and like)Command Description # dpkg -i package.deb # dpkg -r package # dpkg -l # dpkg -l | grep httpd # dpkg -s package # dpkg -L package # dpkg --contents package.deb # dpkg -S /bin/ping
APT packages tool (Debian, Ubuntu and alike)Command Description # apt-cache search package # apt-cdrom install package # apt-get install package # apt-get update # apt-get upgrade # apt-get remove package # apt-get check # apt-get clean
View file contentCommand Description # cat file1 # head -2 file1 # less file1 # more file1 # tac file1 # tail -2 file1 # tail -f /var/log/messages
Text manipulationCommand Description # cat example.txt | awk 'NR%2==1' # echo a b c | awk '{print $1}' # echo a b c | awk '{print $1,$3}' # cat -n file1 # comm -1 file1 file2 # comm -2 file1 file2 # comm -3 file1 file2 # diff file1 file2 # grep Aug /var/log/messages # grep ^Aug /var/log/messages # grep 0-9 /var/log/messages # grep Aug -R /var/log/* # paste file1 file2 # paste -d '+' file1 file2 # sdiff file1 file2 # sed 's/string1/string2/g' example.txt # sed '/^$/d' example.txt # sed '/ *#/d; /^$/d' example.txt # sed -e '1d' exampe.txt # sed -n '/string1/p' # sed -e 's/ *$//' example.txt # sed -e 's/string1//g' example.txt # sed -n '1,5p' example.txt # sed -n '5p;5q' example.txt # sed -e 's/00*/0/g' example.txt # sort file1 file2 # sort file1 file2 | uniq # sort file1 file2 | uniq -u # sort file1 file2 | uniq -d # echo 'word' | tr ' :lower: ' ' :upper: '
Character set and Format file conversionCommand Description # dos2unix filedos.txt fileunix.txt # recode ..HTML < page.txt > page.html # recode -l | more # unix2dos fileunix.txt filedos.txt
Filesystem AnalysisCommand Description # badblocks -v /dev/hda1 # dosfsck /dev/hda1 # e2fsck /dev/hda1 # e2fsck -j /dev/hda1 # fsck /dev/hda1 # fsck.ext2 /dev/hda1 # fsck.ext3 /dev/hda1 # fsck.vfat /dev/hda1 # fsck.msdos /dev/hda1
Format a FilesystemCommand Description # fdformat -n /dev/fd0 # mke2fs /dev/hda1 # mke2fs -j /dev/hda1 # mkfs /dev/hda1 # mkfs -t vfat 32 -F /dev/hda1 # mkswap /dev/hda3
BackupCommand Description # find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 # find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents # dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' # dd if=/dev/sda of=/tmp/file1 # dd if=/dev/hda of=/dev/fd0 bs=512 count=1 # dd if=/dev/fd0 of=/dev/hda bs=512 count=1 # dump -0aj -f /tmp/home0.bak /home # dump -1aj -f /tmp/home0.bak /home # restore -if /tmp/home0.bak # rsync -rogpav --delete /home /tmp # rsync -rogpav -e ssh --delete /home ip_address:/tmp # rsync -az -e ssh --delete ip_addr:/home/public /home/local # rsync -az -e ssh --delete /home/local ip_addr:/home/public # tar -Puf backup.tar /home/user # ( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' # ( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' # tar cf - . | (cd /tmp/backup ; tar xf - )
CDROMCommand Description # cd-paranoia -B # cd-paranoia -- # cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force # cdrecord -v dev=/dev/cdrom cd.iso # gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - # cdrecord --scanbus # dd if=/dev/hdc | md5sum # mkisofs /dev/cdrom > cd.iso # mkisofs /dev/cdrom | gzip > cd_iso.gz # mkisofs -J -allow-leading-dots -R -V # mount -o loop cd.iso /mnt/iso
Networking (LAN / WiFi)Command Description # dhclient eth0 # ethtool eth0 # host www.example.com # hostname # ifconfig eth0 # ifconfig eth0 192.168.1.1 netmask 255.255.255.0 # ifconfig eth0 promisc # ifdown eth0 # ifup eth0 # ip link show # iwconfig eth1 # iwlist scan # mii-tool eth0 # netstat -tup # netstat -tupl # netstat -rn # nslookup www.example.com # route -n # route add -net 0/0 gw IP_Gateway # route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 # route del 0/0 gw IP_gateway # echo "1" > /proc/sys/net/ipv4/ip_forward # tcpdump tcp port 80 # whois www.example.com
Microsoft Windows networks (samba)Command Description # mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share # nbtscan ip_addr # nmblookup -A ip_addr # smbclient -L ip_addr/hostname # smbget -Rr smb://ip_addr/share
IPTABLES (firewall)Command Description # iptables -t filter -L # iptables -t nat -L # iptables -t filter -F # iptables -t nat -F # iptables -t filter -X # iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT # iptables -t filter -A OUTPUT -p tcp --dport http -j DROP # iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT # iptables -t filter -A INPUT -j LOG --log-prefix # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # iptables -t nat -A PREROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22 -j DNAT --to-destination 10.0.0.2:22
Monitoring and debuggingCommand Description # free -m # kill -9 process_id # kill -1 process_id # last reboot # lsmod # lsof -p process_id # lsof /home/user1 # ps -eafw # ps -e -o pid,args --forest # pstree # smartctl -A /dev/hda # smartctl -i /dev/hda # strace -c ls >/dev/null # strace -f -e open ls >/dev/null # tail /var/log/dmesg # tail /var/log/messages # top # watch -n1 'cat /proc/interrupts'
Other useful commandsCommand Description # alias hh='history' # apropos ...keyword # chsh # chsh --list-shells # gpg -c file1 # gpg file1.gpg # ldd /usr/bin/ssh # ping # mkbootdisk --device /dev/fd0 `uname -r` # wget -r www.example.com # wget -c www.example.com/file.iso # echo 'wget -c www.example.com/files.iso' | at 09:00 # whatis ...keyword displays description of what a program does # who -a
Input searches:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


Raheel Farooq
Posted in: 
