uname -m Show machine processor architectureuname -r Show kernel version in usedmidecode -q Show hardware system components(SMBIOS / DMI) hdparm -i /dev/hda List a disk's architecture characteristicshdparm -tT /dev/sda Perform a test read operation on a diskarch Show machine processor architectureuname -m Show machine processor architectureuname -r Show kernel version in usedmidecode -q Show hardware system components - (SMBIOS / DMI)hdparm -i /dev/hda List a disk's architecture characteristicshdparm -tT /dev/sda Perform a test read operation on a diskcat /proc/cpuinfo Display CPU infocat /proc/interrupts Display interruptscat /proc/meminfo Verify memory usagecat /proc/swaps Show which swap is being usedcat /proc/version Display kernel versioncat /proc/net/dev Display network adapters and statisticscat /proc/mounts Display mounted filesystemslspci -tv List PCI deviceslsusb -tv Display USB devicesdate Display system datecal 2007 Display 2007 calendardate 041217002007.00 Set date and time - month day hour minute year.secondclock -w Save time modification to BIOS
2. Shutdown
shutdown -h now Shutdown system (1)init 0 Shutdown system (2)telinit 0 Shutdown system (3)shutdown -h hours:minutes & Schedule system shutdownshutdown -c Cancel scheduled system shutdownshutdown -r now Reboot (1)reboot Reboot (2)logout Logout
3. Files and Directories
cd /home Enter '/home' directorycd .. Go back one directory levelcd ../.. Go back two directory levelscd Go to home directorycd ~user1 Go to user1's home directorycd - Go back to previous directorypwd Show working directoryls View files in directoryls -F View files in directoryls -l Show detailed list of files and directoriesls -a Show hidden filesls *[0-9]* Show filenames and directory names containing numberstree Show tree structure of files and directories starting from root (1)lstree Show tree structure of files and directories starting from root (2)mkdir dir1 Create a directory named 'dir1'mkdir dir1 dir2 Create two directories simultaneouslymkdir -p /tmp/dir1/dir2 Create a directory treerm -f file1 Delete a file named 'file1'rmdir dir1 Delete a directory named 'dir1'rm -rf dir1 Delete a directory named 'dir1' and its contentsrm -rf dir1 dir2 Delete two directories and their contents simultaneouslymv dir1 new_dir Rename/move a directorycp file1 file2 Copy a filecp dir/* . Copy all files in a directory to current working directorycp -a /tmp/dir1 . Copy a directory to current working directorycp -a dir1 dir2 Copy a directoryln -s file1 lnk1 Create a symbolic link to a file or directoryln file1 lnk1 Create a hard link to a file or directorytouch -t 0712250000 file1 Modify a file or directory's timestamp - (YYMMDDhhmm)file file1 outputs the mime type of the file as texticonv -l List known encodingsiconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)
4. File Search
find / -name file1 Search for files and directories starting from '/' into root filesystemfind / -user user1 Search for files and directories belonging to user 'user1'find /home/user1 -name \*.bin Search for files ending with '.bin' in directory '/home/user1'find /usr/bin -type f -atime +100 Search for executable files not used in the last 100 daysfind /usr/bin -type f -mtime -10 Search for files created or modified within the last 10 daysfind / -name \*.rpm -exec chmod 755 '{}' \; Search for files ending with '.rpm' and define their permissionsfind / -xdev -name \*.rpm Search for files ending with '.rpm', ignoring removable devices like CD-ROMs, flash driveslocate \*.ps Find files ending with '.ps' - run 'updatedb' command firstwhereis halt Show location of a binary, source, or man pagewhich halt Show full path of a binary or executable file
5. Mount a Filesystem
mount /dev/hda2 /mnt/hda2 Mount a disk called hda2 - ensure directory '/mnt/hda2' existsumount /dev/hda2 Unmount a disk called hda2 - exit from mount point '/mnt/hda2' firstfuser -km /mnt/hda2 Force unmount when device is busyumount -n /mnt/hda2 Perform unmount operation without writing to /etc/mtab file - useful when filesystem is read-only or disk is fullmount /dev/fd0 /mnt/floppy Mount a floppy diskmount /dev/cdrom /mnt/cdrom Mount a cdrom or dvdrommount /dev/hdc /mnt/cdrecorder Mount a cdrw or dvdrommount /dev/hdb /mnt/cdrecorder Mount a cdrw or dvdrommount -o loop file.iso /mnt/cdrom Mount a file or ISO image filemount -t vfat /dev/hda5 /mnt/hda5 Mount a Windows FAT32 filesystemmount /dev/sda1 /mnt/usbdisk Mount a usb flash drive or storage devicemount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share Mount a windows network share
6. Disk Space
df -h Show list of mounted partitionsls -lSr |more List files and directories sorted by sizedu -sh dir1 Estimate disk space used by directory 'dir1'du -sk * | sort -rn Show size of files and directories sorted by capacityrpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n Show space used by installed rpm packages sorted by size (fedora, redhat systems)dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n Show space used by installed deb packages sorted by size (ubuntu, debian systems)
7. Users and Groups
groupadd group_name Create a new user groupgroupdel group_name Delete a user groupgroupmod -n new_group_name old_group_name Rename a user groupuseradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 Create a user belonging to "admin" groupuseradd user1 Create a new useruserdel -r user1 Delete a user ( '-r' removes home directory)usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 Modify user attributespasswd Change passwordpasswd user1 Change a user's password (root only)chage -E 2005-12-31 user1 Set user password expiration datepwck Check '/etc/passwd' file format, syntax, and existing usersgrpck Check '/etc/passwd' file format, syntax, and existing groupsnewgrp group_name Log into a new group to change default group for newly created files
8. File Permissions Use “+” to set permissions, use “-” to remove
ls -lh Show permissionsls /tmp | pr -T5 -W$COLUMNS Divide terminal into 5 columns for displaychmod ugo+rwx directory1 Set read (r), write (w), and execute (x) permissions for owner (u), group (g), and others (o) on directorychmod go-rwx directory1 Remove read, write, execute permissions for group (g) and others (o) on directorychown user1 file1 Change ownership of a filechown -R user1 directory1 Change ownership of a directory and all its contentschgrp group1 file1 Change group of a filechown user1:group1 file1 Change owner and group of a filefind / -perm -u+s List all files with SUID set in the systemchmod u+s /bin/file1 Set SUID bit on a binary file - user executing the file gets same permissions as ownerchmod u-s /bin/file1 Disable SUID bit on a binary filechmod g+s /home/public Set SGID bit on a directory - similar to SUID, but for directorieschmod g-s /home/public Disable SGID bit on a directorychmod o+t /home/public Set sticky bit on a file - only legitimate owner can delete the filechmod o-t /home/public Disable sticky bit on a directorychmod +x file_path Add execute permission for owner, group, and otherschmod -x file_path Remove execute permission for owner, group, and otherschmod u+x file_path Add execute permission for ownerchmod g+x file_path Add execute permission for groupchmod o+x file_path Add execute permission for otherschmod ug+x file_path Add execute permission for owner and groupchmod =wx file_path Add write and execute permissions for owner, group, and others; remove read permissionchmod ug=wx file_path Add write and execute permissions for owner and group; remove read permission
9. Special File Attributes Use “+” to set permissions, use “-” to remove
chattr +a file1 Allow file to be opened in append mode only for reading and writingchattr +c file1 Allow kernel to automatically compress/decompress this filechattr +d file1 dump program will ignore this file during filesystem backupchattr +i file1 Make file immutable, cannot be deleted, modified, renamed, or linkedchattr +s file1 Allow file to be securely deletedchattr +S file1 Make system immediately write modifications to disk after application writes to this filechattr +u file1 If file is deleted, system allows you to recover it laterlsattr Show special attributes
10. Packing and Compressing Files
bunzip2 file1.bz2 Decompress a file called 'file1.bz2'bzip2 file1 Compress a file called 'file1'gunzip file1.gz Decompress a file called 'file1.gz'gzip file1 Compress a file called 'file1'gzip -9 file1 Maximum compressionrar a file1.rar test_file Create an archive called 'file1.rar'rar a file1.rar file1 file2 dir1 Compress 'file1', 'file2' and directory 'dir1' simultaneouslyrar x file1.rar Extract rar archiveunrar x file1.rar Extract rar archivetar -cvf archive.tar file1 Create a non-compressed tarballtar -cvf archive.tar file1 file2 dir1 Create an archive containing 'file1', 'file2', and 'dir1'tar -tf archive.tar Show contents of an archivetar -xvf archive.tar Extract an archivetar -xvf archive.tar -C /tmp Extract archive to /tmp directorytar -cvfj archive.tar.bz2 dir1 Create a bzip2 compressed archivetar -xvfj archive.tar.bz2 Extract a bzip2 compressed archivetar -cvfz archive.tar.gz dir1 Create a gzip compressed archivetar -xvfz archive.tar.gz Extract a gzip compressed archivezip file1.zip file1 Create a zip compressed archivezip -r file1.zip file1 file2 dir1 Compress several files and directories into a zip archiveunzip file1.zip Extract a zip compressed archive
11. RPM Packages
rpm -ivh package.rpm Install an rpm packagerpm -ivh --nodeeps package.rpm Install an rpm package ignoring dependency warningsrpm -U package.rpm Update an rpm package without changing its configuration filesrpm -F package.rpm Update an rpm package that is definitely installedrpm -e package_name.rpm Remove an rpm packagerpm -qa Show all installed rpm packages in the systemrpm -qa | grep httpd Show all rpm packages containing "httpd" in their namerpm -qi package_name Get specific information about an installed packagerpm -qg "System Environment/Daemons" Show rpm packages of a componentrpm -ql package_name Show file list provided by an installed rpm packagerpm -qc package_name Show configuration file list provided by an installed rpm packagerpm -q package_name --whatrequires Show dependency list for an rpm packagerpm -q package_name --whatprovides Show size occupied by an rpm packagerpm -q package_name --scripts Show scripts executed during installation/removalrpm -q package_name --changelog Show modification history of an rpm packagerpm -qf /etc/httpd/conf/httpd.conf Confirm which rpm package provides the given filerpm -qp package.rpm -l Show file list provided by an uninstalled rpm packagerpm --import /media/cdrom/RPM-GPG-KEY Import public key digital certificaterpm --checksig package.rpm Verify integrity of an rpm packagerpm -qa gpg-pubkey Verify integrity of all installed rpm packagesrpm -V package_name Check file size, permissions, type, owner, group, MD5 check, and last modification timerpm -Va Check all installed rpm packages in the system - use with cautionrpm -Vp package.rpm Verify an rpm package is not yet installedrpm2cpio package.rpm | cpio --extract --make-directories *bin* Run executable files from an rpm packagerpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm Install a built package from an rpm sourcerpmbuild --rebuild package_name.src.rpm Build an rpm package from an rpm source
12. YUM Package Updater
yum install package_name Download and install an rpm packageyum localinstall package_name.rpm Install an rpm package using your own software repositories to resolve all dependenciesyum update package_name.rpm Update all installed rpm packages in the current systemyum update package_name Update an rpm packageyum remove package_name Remove an rpm packageyum list List all installed packages in the current systemyum search package_name Search for software packages in rpm repositoriesyum clean packages Clean rpm cache delete downloaded packagesyum clean headers Delete all header filesyum clean all Delete all cached packages and header files
13. deb Packages
dpkg -i package.deb Install/update a deb packagedpkg -r package_name Remove a deb package from the systemdpkg -l Show all installed deb packages in the systemdpkg -l | grep httpd Show all deb packages containing "httpd" in their namedpkg -s package_name Get information about a specific package installed in the systemdpkg -L package_name Show file list provided by an installed deb packagedpkg --contents package.deb Show file list provided by an uninstalled packagedpkg -S /bin/ping Confirm which deb package provides the given fileAPT Software Tools (Debian, Ubuntu and similar systems)apt-get install package_name Install/update a deb packageapt-cdrom install package_name Install/update a deb package from CDapt-get update Upgrade list of software packagesapt-get upgrade Upgrade all installed softwareapt-get remove package_name Remove a deb package from the systemapt-get check Confirm dependency software repositories are correctapt-get clean Clean cache from downloaded software packagesapt-cache search searched-package Return package names containing the search string
14. View File Contents
cat file1 View file contents from the first byte forwardtac file1 View a file in reverse starting from the last linemore file1 View contents of a long fileless file1 Similar to 'more' command, but allows reverse operations like forward operations in the filehead -2 file1 View first two lines of a filetail -2 file1 View last two lines of a filetail -f /var/log/messages Real-time view of content being added to a file
15. Text Processing
cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUTcat file1 | command( sed, grep, awk, grep, etc...) > result.txt Merge detailed description text of a file and write summary to a new filecat file1 | command( sed, grep, awk, grep, etc...) >> result.txt Merge detailed description text of a file and write summary to an existing filegrep Aug /var/log/messages Find keyword "Aug" in file '/var/log/messages'grep ^Aug /var/log/messages Find words starting with "Aug" in file '/var/log/messages'grep [0-9] /var/log/messages Select all lines containing numbers in file '/var/log/messages'grep Aug -R /var/log/* Search for string "Aug" in directory '/var/log' and subsequent directoriessed 's/stringa1/stringa2