Linux Commands Reference,Tip: Use Ctrl+F to quickly search for Linux commands (click on titles to collapse or expand)
| Command | Description |
|---|---|
| arch | Display machine's processor architecture (1) |
| uname -m | Display machine's processor architecture (2) |
| uname -r | Display current kernel version |
| dmidecode -q | Display hardware system components - (SMBIOS / DMI) |
| hdparm -i /dev/hda | List architecture features of a disk |
| hdparm -tT /dev/sda | Perform test read operations on the disk |
| cat /proc/cpuinfo | Display CPU information |
| cat /proc/interrupts | Display interrupts |
| cat /proc/meminfo | Check memory usage |
| cat /proc/swaps | Show which swap partitions are in use |
| cat /proc/version | Display kernel version |
| cat /proc/net/dev | Show network adapters and statistics |
| cat /proc/mounts | Display mounted file systems |
| lspci -tv | List PCI devices |
| lsusb -tv | Show USB devices |
| date | Show system date |
| cal 2007 | Display calendar for year 2007 |
| date 041217002007.00 | Set date and time - monthdayhourminuteyear.second |
| clock -w | Save time changes to BIOS |
| Command | Description |
|---|---|
| shutdown -h now | Shutdown the system |
| init 0 | Shutdown the system |
| telinit 0 | Shutdown the system |
| shutdown -h hours:minutes & | Shutdown the system at scheduled time |
| shutdown -c | Cancel scheduled shutdown |
| shutdown -r now | Reboot |
| reboot | Reboot |
| logout | Logout |
| Command | Description |
|---|---|
| cd /home | Go to '/home' directory |
| cd .. | Go back to the previous directory |
| cd ../.. | Go back two levels |
| cd | Go to personal home directory |
| cd ~user1 | Go to user1's home directory |
| cd - | Go back to the last directory |
| pwd | Display working directory |
| ls | List files in directory |
| ls -F | List files in directory with type indicators |
| ls -l | Display detailed file and directory information |
| ls -a | Show hidden files |
| ls *[0-9]* | Show filenames and directories containing numbers |
| tree | Display tree structure of files and directories from root |
| lstree | Display tree structure of files and directories from root |
| mkdir dir1 | Create a directory called 'dir1' |
| mkdir dir1 dir2 | Create two directories at the same time |
| mkdir -p /tmp/dir1/dir2 | Create a directory tree |
| rm -f file1 | Delete a file called 'file1' |
| rmdir dir1 | Delete a directory called 'dir1' |
| rm -rf dir1 | Delete a directory called 'dir1' and its contents |
| rm -rf dir1 dir2 | Delete two directories and their contents |
| mv dir1 new_dir | Rename/move a directory |
| cp file1 file2 | Copy a file |
| cp dir/* . | Copy all files from a directory to current working directory |
| cp -a /tmp/dir1 . | Copy a directory to current working directory |
| cp -a dir1 dir2 | Copy a directory |
| ln -s file1 lnk1 | Create a soft link to a file or directory |
| ln file1 lnk1 | Create a physical link to a file or directory |
| touch -t 0712250000 file1 | Modify the timestamp of a file or directory - (YYMMDDhhmm) |
| iconv -l | List known encodings |
| iconv -f fromEncoding -t toEncoding inputFile > outputFile | Change the encoding of characters |
| find . -maxdepth 1 -name *.jpg -print -exec convert | Batch resize files in the current directory and send them to a thumbnail directory (requires convert from ImageMagick) |
| Command | Description |
|---|---|
| find / -name file1 | Search for files and directories starting from '/' |
| find / -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 that haven't been used in the past 100 days |
| find /usr/bin -type f -mtime -10 | Search for files created or modified within the last 10 days |
| find / -name \*.rpm -exec chmod 755 '{}' \; | Search for files ending with '.rpm' and set their permissions |
| find / -xdev -name \*.rpm | Search for files ending with '.rpm', ignoring removable devices like CD-ROMs and flash drives |
| locate \*.ps | Find files ending with '.ps' - run 'updatedb' command first |
| whereis halt | Show the location of a binary, source, or manual page |
| which halt | Show the full path of a binary or executable |
| Command | Description |
|---|---|
| mount /dev/hda2 /mnt/hda2 | Mount a drive called hda2 - ensure directory '/mnt/hda2' exists |
| umount /dev/hda2 | Unmount a drive called hda2 - exit from mount point '/mnt/hda2' first |
| fuser -km /mnt/hda2 | Force unmount when device is busy |
| umount -n /mnt/hda2 | Perform unmount without writing to /etc/mtab file - useful when file is read-only or disk is full |
| mount /dev/fd0 /mnt/floppy | Mount a floppy disk |
| mount /dev/cdrom /mnt/cdrom | Mount a CD-ROM or DVD-ROM |
| mount /dev/hdc /mnt/cdrecorder | Mount a CD-RW or DVD-ROM |
| mount /dev/hdb /mnt/cdrecorder | Mount a CD-RW or DVD-ROM |
| mount -o loop file.iso /mnt/cdrom | Mount a file or ISO image |
| mount -t vfat /dev/hda5 /mnt/hda5 | Mount a Windows FAT32 file system |
| mount /dev/sda1 /mnt/usbdisk | Mount a USB flash drive or thumb drive |
| mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share | Mount a Windows network share |
| Command | Description |
|---|---|
| df -h | Display a list of mounted partitions |
| ls -lSr |more | List files and directories sorted by size |
| du -sh dir1 | Estimate disk space used by directory 'dir1' |
| du -sk * | sort -rn | Display files and directories sorted by size |
| rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n | Display installed rpm packages sorted by size (fedora, redhat systems) |
| dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n | Display installed deb packages sorted by size (ubuntu, debian systems) |
| Command | Description |
|---|---|
| groupadd group_name | Create a new user group |
| groupdel group_name | Delete a user group |
| groupmod -n new_group_name old_group_name | Rename a user group |
| useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 | Create a user belonging to the "admin" group |
| useradd user1 | Create a new user |
| userdel -r user1 | Delete a user ( '-r' removes home directory) |
| usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 | Modify user attributes |
| passwd | Change password |
| passwd user1 | Change a user's password (root only) |
| chage -E 2020-12-31 user1 | Set expiration date for user password |
| pwck | Check '/etc/passwd' file format and syntax, and verify users |
| grpck | Check '/etc/group' file format and syntax, and verify groups |
| newgrp group_name | Log in to a new group to change default group for newly created files |
| Command | Description |
|---|---|
| ls -lh | Display permissions |
| ls /tmp | pr -T5 -W$COLUMNS | Display terminal in 5 columns |
| chmod ugo+rwx directory1 | Set read (r), write (w), and execute (x) permissions for user (u), group (g), and others (o) on directory |
| chmod go-rwx directory1 | Remove read, write, and execute permissions for group (g) and others (o) on directory |
| chown user1 file1 | Change owner of a file |
| chown -R user1 directory1 | Change owner of a directory and all files within it |
| chgrp group1 file1 | Change group of a file |
| chown user1:group1 file1 | Change both owner and group of a file |
| find / -perm -u+s | List all files with SUID bit set in the system |
| chmod u+s /bin/file1 | Set SUID bit on a binary file - user running the file gets owner's permissions |
| chmod u-s /bin/file1 | Disable SUID bit on a binary file |
| chmod g+s /home/public | Set the SGID bit on a directory - similar to SUID but for directories |
| chmod g-s /home/public | Disable the SGID bit on a directory |
| chmod o+t /home/public | Set the STICKY bit on a file - only allows the legitimate owner to delete the file |
| chmod o-t /home/public | Disable the STICKY bit on a directory |
| Command | Description |
|---|---|
| chattr +a file1 | Allow the file to be read and written only in append mode |
| chattr +c file1 | Allow the file to be automatically compressed/decompressed by the kernel |
| chattr +d file1 | The dump program will ignore this file during filesystem backup |
| chattr +i file1 | Make the file immutable, cannot be deleted, modified, renamed or linked |
| chattr +s file1 | Allow the file to be securely deleted |
| chattr +S file1 | Once an application writes to this file, the system immediately writes the changes to disk |
| chattr +u file1 | If the file is deleted, the system allows you to recover the deleted file later |
| lsattr | Display special attributes |
| Command | Description |
|---|---|
| bunzip2 file1.bz2 | Decompress a file named 'file1.bz2' |
| bzip2 file1 | Compress a file named 'file1' |
| gunzip file1.gz | Decompress a file named 'file1.gz' |
| gzip file1 | Compress a file named 'file1' |
| gzip -9 file1 | Maximum compression |
| rar a file1.rar test_file | Create a package named 'file1.rar' |
| rar a file1.rar file1 file2 dir1 | Compress 'file1', 'file2' and directory 'dir1' simultaneously |
| rar x file1.rar | Extract a rar package |
| unrar x file1.rar | Extract a rar package |
| tar -cvf archive.tar file1 | Create an uncompressed tarball |
| tar -cvf archive.tar file1 file2 dir1 | Create an archive containing 'file1', 'file2' and 'dir1' |
| tar -tf archive.tar | List the contents of a package |
| tar -xvf archive.tar | Extract a package |
| tar -xvf archive.tar -C /tmp | Extract the package to the /tmp directory |
| tar -cvfj archive.tar.bz2 dir1 | Create a bzip2 format compressed package |
| tar -jxvf archive.tar.bz2 | Extract a bzip2 format compressed package |
| tar -cvfz archive.tar.gz dir1 | Create a gzip format compressed package |
| tar -zxvf archive.tar.gz | Extract a gzip format compressed package |
| zip file1.zip file1 | Create a zip format compressed package |
| zip -r file1.zip file1 file2 dir1 | Compress multiple files and directories into a single zip format package |
| unzip file1.zip | Extract a zip format compressed package |
| Command | Description |
|---|---|
| rpm -ivh package.rpm | Install an rpm package |
| rpm -ivh --nodeeps package.rpm | Install an rpm package ignoring dependency warnings |
| rpm -U package.rpm | Update an rpm package without changing its configuration files |
| rpm -F package.rpm | Update an rpm package that is definitely already installed |
| rpm -e package_name.rpm | Remove an rpm package |
| rpm -qa | Display all rpm packages installed on the system |
| rpm -qa | grep httpd | Display all rpm packages with names containing "httpd" |
| rpm -qi package_name | Get detailed information about an installed package |
| rpm -qg "System Environment/Daemons" | Display rpm packages for a component |
| rpm -ql package_name | Display list of files provided by an installed rpm package |
| rpm -qc package_name | Display list of configuration files provided by an installed rpm package |
| rpm -q package_name --whatrequires | Display list of dependencies for an rpm package |
| rpm -q package_name --whatprovides | Display the size occupied by an rpm package |
| rpm -q package_name --scripts | Display scripts executed during installation/removal |
| rpm -q package_name --changelog | Display modification history of an rpm package |
| rpm -qf /etc/httpd/conf/httpd.conf | Determine which rpm package provides a given file |
| rpm -qp package.rpm -l | Display list of files provided by an uninstalled rpm package |
| rpm --import /media/cdrom/RPM-GPG-KEY | Import a public key certificate |
| rpm --checksig package.rpm | Verify the integrity of an rpm package |
| rpm -qa gpg-pubkey | Verify the integrity of all installed rpm packages |
| rpm -V package_name | Check file size, permissions, type, owner, group, MD5 checksum, and last modification time |
| rpm -Va | Check all installed rpm packages on the system - use with caution |
| rpm -Vp package.rpm | Verify an rpm package before installation |
| rpm2cpio package.rpm | cpio --extract --make-directories *bin* | Extract executable files from an rpm package |
| rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm | Install a built package from rpm sources |
| rpmbuild --rebuild package_name.src.rpm | Build an rpm package from rpm sources |
| Command | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yum install package_name | Download and install an rpm package | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yum localinstall package_name.rpm | Install an rpm package, using your own software repository to resolve all dependencies | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yum update package_name.rpm | Update all installed rpm packages on the current system | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yum update package_name | Update an rpm package | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yum remove package_name | Remove an rpm package | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yum list | List all packages installed on the current system | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yum search package_name | Search for packages in the rpm repository | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yum clean packages |
| Command | Description |
|---|---|
| dpkg -i package.deb | Install/update a deb package |
| dpkg -r package_name | Remove a deb package from the system |
| dpkg -l | Display all deb packages installed on the system |
| dpkg -l | grep httpd | Display all deb packages with names containing "httpd" |
| dpkg -s package_name | Get information about a specific package installed on the system |
| dpkg -L package_name | Display list of files provided by a deb package installed on the system |
| dpkg --contents package.deb | Display list of files provided by an uninstalled package |
| dpkg -S /bin/ping | Determine which deb package provides a given file |
| Command | Description |
|---|---|
| apt-get install package_name | Install/update a deb package |
| apt-cdrom install package_name | Install/update a deb package from CD-ROM |
| apt-get update | Update the list of packages |
| apt-get upgrade | Upgrade all installed software |
| apt-get remove package_name | Remove a deb package from the system |
| apt-get check | Verify that the dependency repositories are correct |
| apt-get clean | Clean cache from downloaded packages |
| apt-cache search searched-package | Return package names containing the search string |
| Command | Description |
|---|---|
| cat file1 | View file content from the first byte forward |
| tac file1 | View file content from the last line backward |
| more file1 | View content of a long file |
| less file1 | Similar to 'more' command, but allows backward navigation as well as forward |
| head -2 file1 | View first two lines of a file |
| tail -2 file1 | View last two lines of a file |
| tail -f /var/log/messages | Real-time view of content being added to a file |
| Command | Description |
|---|---|
| cat file1 | command( sed, grep, awk, grep, etc...) > result.txt | Combine detailed description text of a file and write the summary to a new file |
| cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt | Combine detailed description text of a file and append the summary to an existing file |
| grep Aug /var/log/messages | Search for keyword "Aug" in file '/var/log/messages' |
| grep ^Aug /var/log/messages | Search for words starting with "Aug" in file '/var/log/messages' |
| grep [0-9] /var/log/messages | Select all lines containing numbers in '/var/log/messages' file |
| grep Aug -R /var/log/* | Search for string "Aug" in directory '/var/log' and subsequent directories |
| sed 's/stringa1/stringa2/g' example.txt | Replace "string1" with "string2" in example.txt file |
| sed '/^$/d' example.txt | Remove all blank lines from example.txt file |
| sed '/ *#/d; /^$/d' example.txt | Remove all comments and blank lines from example.txt file |
| echo 'esempio' | tr '[:lower:]' '[:upper:]' | Combine contents of upper and lower cells |
| sed -e '1d' result.txt | Exclude the first line from example.txt file |
| sed -n '/stringa1/p' | View only lines containing the word "string1" |
| sed -e 's/ *$//' example.txt | Remove trailing whitespace characters from each line |
| sed -e 's/stringa1//g' example.txt | Remove only the word "string1" from the document while preserving the rest |
| sed -n '1,5p;5q' example.txt | View content from line 1 to line 5 |
| sed -n '5p;5q' example.txt | View line 5 |
| sed -e 's/00*/0/g' example.txt | Replace multiple zeros with a single zero |
| cat -n file1 | Number the lines of a file |
| cat example.txt | awk 'NR%2==1' | Remove all even-numbered lines from example.txt file |
| echo a b c | awk '{print $1}' | View the first column of a line |
| echo a b c | awk '{print $1,$3}' | View the first and third columns of a line |
| paste file1 file2 | Merge contents of two files or columns |
| paste -d '+' file1 file2 | Merge contents of two files or columns, separated by '+' |
| sort file1 file2 | Sort contents of two files |
| sort file1 file2 | uniq | Get the union of two files (keep only one copy of duplicate lines) |
| sort file1 file2 | uniq -u | Remove intersection, keep other lines |
| sort file1 file2 | uniq -d | Get the intersection of two files (keep only lines present in both files) |
| comm -1 file1 file2 | Compare two files and delete content only in 'file1' |
| comm -2 file1 file2 | Compare two files and delete content only in 'file2' |
| comm -3 file1 file2 | Compare two files and delete content common to both files |
| Command | Description |
|---|---|
| dos2unix filedos.txt fileunix.txt | Convert a text file format from MSDOS to UNIX |
| unix2dos fileunix.txt filedos.txt | Convert a text file format from UNIX to MSDOS |
| recode ..HTML < page.txt > page.html | Convert a text file to HTML |
| recode -l | more | Display all allowed conversion formats |
| Command | Description |
|---|---|
| badblocks -v /dev/hda1 | Check for bad blocks on disk hda1 |
| fsck /dev/hda1 | Repair/check integrity of Linux file system on hda1 disk |
| fsck.ext2 /dev/hda1 | Repair/check integrity of ext2 file system on hda1 disk |
| e2fsck /dev/hda1 | Repair/check integrity of ext2 file system on hda1 disk |
| e2fsck -j /dev/hda1 | Repair/check integrity of ext3 file system on hda1 disk |
| fsck.ext3 /dev/hda1 | Repair/check integrity of ext3 file system on hda1 disk |
| fsck.vfat /dev/hda1 | Repair/check integrity of FAT file system on hda1 disk |
| fsck.msdos /dev/hda1 | Repair/check integrity of DOS file system on hda1 disk |
| dosfsck /dev/hda1 | Repair/check integrity of DOS file system on hda1 disk |
| Command | Description |
|---|---|
| mkfs /dev/hda1 | Create a file system on hda1 partition |
| mke2fs /dev/hda1 | Create a Linux ext2 file system on hda1 partition |
| mke2fs -j /dev/hda1 | Create a Linux ext3 (journaled) file system on hda1 partition |
| mkfs -t vfat 32 -F /dev/hda1 | Create a FAT32 file system |
| fdformat -n /dev/fd0 | Format a floppy disk |
| mkswap /dev/hda3 | Create a swap file system |
| Command | Description |
|---|---|
| mkswap /dev/hda3 | Create a swap file system |
| swapon /dev/hda3 | Enable a new swap file system |
| swapon /dev/hda2 /dev/hdb3 | Enable two swap partitions |
| Command | Description |
|---|---|
| dump -0aj -f /tmp/home0.bak /home | Create a full backup of the '/home' directory |
| dump -1aj -f /tmp/home0.bak /home | Create an interactive backup of the '/home' directory |
| restore -if /tmp/home0.bak | Restore an interactive backup |
| rsync -rogpav --delete /home /tmp | Synchronize directories between two sides |
| rsync -rogpav -e ssh --delete /home ip_address:/tmp | Rsync over SSH channel |
| rsync -az -e ssh --delete ip_addr:/home/public /home/local | Synchronize a remote directory to local directory with SSH and compression |
| rsync -az -e ssh --delete /home/local ip_addr:/home/public | Synchronize local directory to remote directory with SSH and compression |
| dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' | Perform a backup of local disk to remote host over SSH |
| dd if=/dev/sda of=/tmp/file1 | Backup disk content to a file |
| tar -Puf backup.tar /home/user | Perform an incremental backup of '/home/user' directory |
| ( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' | Copy directory content to remote directory over SSH |
| ( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' | Copy a local directory to remote directory over SSH |
| tar cf - . | (cd /tmp/backup ; tar xf - ) | Locally copy a directory to another location, preserving permissions and links |
| find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents | Find and copy all files ending with '.txt' from one directory to another |
| find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 | Find all files ending with '.log' and create a bzip package |
| dd if=/dev/hda of=/dev/fd0 bs=512 count=1 | Copy MBR (Master Boot Record) content to floppy disk |
| dd if=/dev/fd0 of=/dev/hda bs=512 count=1 | Restore MBR content from backup saved to floppy disk |
| Command | Description |
|---|---|
| cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force | Erase content of a rewritable CD |
| mkisofs /dev/cdrom > cd.iso | Create an ISO image file of a CD on disk |
| mkisofs /dev/cdrom | gzip > cd_iso.gz | Create a compressed ISO image file of a CD on disk |
| mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd | Create an ISO image file of a directory |
| cdrecord -v dev=/dev/cdrom cd.iso | Burn an ISO image file |
| gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - | Burn a compressed ISO image file |
| mount -o loop cd.iso /mnt/iso | Mount an ISO image file |
| cd-paranoia -B | Extract audio tracks from a CD to wav files |
| cd-paranoia -- "-3" | Extract audio tracks from a CD to wav files (with parameter -3) |
| cdrecord --scanbus | Scan bus to identify SCSI channels |
| dd if=/dev/hdc | md5sum | Verify md5sum of a device, such as a CD |
| Command | Description |
|---|---|
| dhclient eth0 | Enable 'eth0' network device in DHCP mode |
| ethtool eth0 | Display traffic statistics for network card 'eth0' |
| host www.example.com | Look up hostname to resolve name and IP address and aliases |
| hostname | Display hostname |
| ifconfig eth0 | Display configuration of an Ethernet card |
| ifconfig eth0 192.168.1.1 netmask 255.255.255.0 | Configure IP address |
| ifconfig eth0 promisc | Set 'eth0' to promiscuous mode for packet sniffing |
| ifdown eth0 | Disable 'eth0' network device |
| ifup eth0 | Enable 'eth0' network device |
| ip link show | Display connection status of all network devices |
| iwconfig eth1 | Display configuration of a wireless network card |
| iwlist scan | Display wireless networks |
| mii-tool eth0 | Display connection status of 'eth0' |
| netstat -tup | Display all active network connections and their PIDs |
| netstat -tup1 | Display all listening network services and their PIDs |
| netstat -rn | Display routing table, similar to "route -n" command |
| nslookup www.example.com | Look up hostname to resolve name and IP address and aliases |
| route -n | Display routing table |
| route add -net 0/0 gw IP Gateway | Configure default gateway |
| route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 | Configure static route to network '192.168.0.0/16' |
| route del 0/0 gw IP gateway | Delete static route |
| echo "1"> /proc/sys/net/ipv4/ip_foward | Enable IP forwarding |
| tcpdump tcp port 80 | Display all HTTP traffic |
| whois www.example.com | Look up in Whois database |
| Command | Description |
|---|---|
| mount -t smbfs -o username=user,password=pass //WinClient/share/mnt/share | Mount a Windows network share |
| nbtscan ip addr | NetBIOS name resolution |
| nmblookup -A ip addr | NetBIOS name resolution |
| smbclient -L ip addr/hostname | Display remote shares of a Windows host |
| smbget -Rr smb://ip addr/share | Download files from a Windows host via SMB like wget |
| Command | Description |
|---|---|
| iptables -t filter -L | Display all chains of filter table |
| iptables -t nat -L | Display all chains of nat table |
| iptables -t filter -F | Flush all rules in filter table |
| iptables -t nat -F | Flush all rules in nat table |
| iptables -t filter -X | Delete all user-created chains |
| iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT | Allow telnet access |
| iptables -t filter -A OUTPUT -p tcp --dport telnet -j DROP | Block telnet access |
| iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT | Allow POP3 connections on forward chain |
| iptables -t filter -A INPUT -j LOG --log-prefix | Log all dropped packets in chain |
| iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | Set up PAT (Port Address Translation) to masquerade outgoing packets on eth0 |
| iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22-j DNAT --to-destination 10.0.0.2:22 | Redirect packets destined for a host to another host |
| Command | Description |
|---|---|
| free -m | List RAM status in megabytes |
| kill -9 process id | Forcefully terminate a process |
| kill -1 process id | Force a process to reload its configuration |
| last reboot | Display reboot history |
| lsmod | List loaded kernel modules |
| lsof -p process id | List files opened by a process |
| lsof /home/user1 | List files opened in the given system path |
| ps -eafw | List Linux tasks |
| ps -e -o pid,args --forest | List Linux tasks in a hierarchical way |
| pstress | Display processes in a tree diagram |
| smartctl -A /dev/hda | Monitor hard drive reliability with SMART enabled |
| smartctl -i /dev/hda | Check if SMART is enabled on a hard drive |
| strace -c ls >/dev/null | List system calls made and received by a process |
| strace -f -e open ls >/dev/null | List library calls |
| tail /var/log/dmesg | Display internal events during kernel boot process |
| tail /var/log/messages | Display system events |
| top | List Linux tasks using most CPU resources |
| watch -nl 'cat /proc/interrupts' | List real-time interrupts |
| Command | Description |
|---|---|
| alias hh='history' | Create an alias for the history command |
| apropos ...keyword | List command list including program keywords, especially useful when you know what a program does but can't remember the command |
| chsh | Change shell command |
| chsh --list-shells | Useful command to know if you have to connect remotely to another machine |
| gpg -c filel | Encrypt a file with GNU Privacy Guard |
| gpg filel.gpg | Decrypt a file with GNU Privacy Guard |
Links: Developer Tools