Linux

Tips: More than 400 commands for GNU / Linux you should know: D

System Information

  1. arch: : show architecture of machine (1).
  2. uname -m: show architecture of machine (2).
  3. uname -r : show the version of the kernel used.
  4. dmidecode -q : show components (hardware) system.
  5. hdparm -i /dev/hda : show the characteristics of a hard disk.
  6. hdparm -tT /dev/sda : perform test reading on a hard drive.
  7. cat /proc/cpuinfo : show CPU information.
  8. cat /proc/interrupts : show interrupts.
  9. cat /proc/meminfo : check memory usage.
  10. cat /proc/swaps : show swap files.
  11. cat /proc/version : show version of the kernel.
  12. cat /proc/net/dev : network adapters and display statistics.
  13. cat /proc/mounts : show mounted file system.
  14. lspci -tv : show PCI devices.
  15. lsusb -tv : show USB devices.
  16. date : show the system date.
  17. cal 2016 : 2016 show calendar.
  18. cal 07 2016 : show the calendar for the month July 2016.
  19. date 041217002011.00 : place (state, adjust) the date and time.
  20. clock -w : save the date changes in the BIOS.

Shutdown (or Restart System Log out)

  1. shutdown -h now : Shut down system (1).
  2. init 0 : Shut down system (2).
  3. telinit 0 : Shut down system (3).
  4. halt : Shut down system (4).
  5. shutdown -h hours: minutes & : off planned system.
  6. shutdown -c : cancel a planned shutdown of the system.
  7. shutdown -r now : Restart (1).
  8. reboot : restart (2).
  9. logout : logout.

Files and Directories

  1. cd /home : enter the “home” directory.
  2. cd .. : go back one level.
  3. cd ../.. : back 2 levels.
  4. cd: go to the root directory.
  5. cd ~user : user to the directory.
  6. cd – : go (back) to the previous directory.
  7. pwd Display the working directory path.
  8. ls : view files in a directory.
  9. ls -F : see the files in a directory.
  10. ls -l : show details of files and folders in a directory.
  11. ls -a : show hidden files.
  12. ls *[0-9]*: Display files and folders that contain numbers.
  13. tree : show files and folders in a tree starting from root (1).
  14. lstree : show files and folders in a tree starting from root (2).
  15. mkdir dir1 : create a folder or directory called ‘dir1’.
  16. mkdir dir1 dir2 : create two folders or directories simultaneously (Create two directories at once).
  17. mkdir -p /tmp/dir1/dir2 : create a directory tree.
  18. rm -f file1 : delete the file called ‘file1’.
  19. rmdir dir1 : delete the folder called ‘dir1’.
  20. rm -Rf dir1 : delete a folder called ‘dir1’ with its contents recursively. (If you delete recursive I’m saying is with contents).
  21. rm -Rf dir1 dir2 : delete two folders (directories) with its contents recursively.
  22. mv dir1 NEW_DIR : rename or move a file or folder (directory).
  23. cp file1 : copy a file.
  24. cp file1 file2 : copy two files together.
  25. cp dir/*.  : Copy all files in a directory within the current working directory.
  26. cp -a /tmp/dir1. : copy a directory within the current working directory.
  27. cp -a dir1 : copy a directory.
  28. cp -a dir1 dir2 : copy two unison directory.
  29. ln -s file1 LNK1 : create a symbolic link to the file or directory.
  30. ln file1 LNK1 : create a physical link to file or directory.
  31. touch -t 0712250000 file1 : change the actual time (time of creation) of a file or directory.
  32. file file1 : output (screen dump) mime type of text file.
  33. iconv -l : lists of known encrypted.
  34. iconv -f fromEncoding -t toEncoding inputFile > outputFile : creates a new form of assuming the input file is encoded in fromEncoding and turning to ToEncoding.
  35. find . -maxdepth 1 -name *.jpg -print -exec convert ”{}” -resize 80×60 “thumbs/{}” \; : group resized files in the current directory and send them to directories in thumbnail view (requires convert from ImageMagick).

Finding Files

  1. find / -name file1 : search file and directory from the root system.
  2. find / -user user1 : search files and directories owned by the user ‘user1’.
  3. find /home/user1 -name \ *.bin : search for files with the extension ‘. bin ‘in the directory’ / home / user1 ‘.
  4. find /usr/bin -type f -atime +100: search binary files are not used in the last 100 days.
  5. find /usr/bin -type f -mtime -10: search created or changed within the last 10 days files.
  6. find / -name \*.rpm -exec chmod 755 ‘{}’ \; : search files with ‘.rpm’ extension and modify permits.
  7. find / -xdev -name \*.rpm: Find files with ‘.rpm’ extension ignoring removable devices such as cdrom, pen-drive, etc. …
  8. locate \*.ps: find files with the extension ‘.ps’ first executed with the command ‘updatedb’.
  9. whereis halt : show the location of a binary file, or source of help. In this case asks where the ‘halt’ command is.
  10. which halt: show the full path (full path) to a binary / executable.

Mounting a filesystem

  1. mount /dev/hda2 /mnt/hda2 : mount a disk called hda2. Verify the existence of the ‘/ mnt / hda2’ directory first; if not, you create it.
  2. umount /dev/hda2 : remove a disc called hda2. Out first from point ‘/ mnt / hda2.
  3. fuser -km /mnt/hda2 : Force removal when the device is busy.
  4. umount -n /mnt/hda2 : running disassembly without reading the file / etc / mtab.Useful when the file is read-only or the hard disk is full.
  5. mount /dev/fd0 /mnt/floppy : mount a floppy disk (floppy).
  6. mount /dev/cdrom /mnt/cdrom : mount a cdrom / dvdrom.
  7. mount /dev/hdc /mnt/cdrecorder : writing a rewritable CD or dvdrom.
  8. mount /dev/hdb /mnt/cdrecorder :writing a rewritable / dvdrom cd (dvd).
  9. mount -o loop file.iso /mnt/cdrom : mount a file or iso image.
  10. mount -t vfat /dev/hda5 /mnt/hda5 : mount a FAT32 file system.
  11. mount /dev/sda1 /mnt/usbdisk : mount a usb pen-drive or a memory (without specifying the type of filesystem).

Disk Space

  1. df -h : display a list of mounted partitions.
  2. -lSr ls | more : show the size of the files and directories sorted by size.
  3. du -sh dir1: To estimate space used by directory ‘dir1’.
  4. du -sk * | sort -rn : show the size of the files and directories sorted by size.
  5. rpm -q -a –qf ‘%10{SIZE}t%{NAME}n’ | sort -k1,1n: show space used by rpm packages installed organized by size (Fedora, RedHat and others).
  6. dpkg-query -W -f=’${Installed-Size;10}t${Package}n’ | sort -k1,1n : show the space used by the installed packages, organized by size (Ubuntu, Debian and others).

Users and Groups

  1. groupadd groupname : create a new group.
  2. groupdel groupname : delete a group.
  3. groupmod -n newname oldname: : rename a group.
  4. useradd -c “Name Surname” -g admin -d /home/user1 -s /bin/bash user1: Create a new user belonging to the group “admin”.
  5. useradd user1 : create a new user.
  6. userdel -r user1 : delete a user (‘-r’ eliminates home directory).
  7. usermod -c “User FTP” -g system -d /ftp/user1 -s /bin/nologin user1:: change user attributes.
  8. passwd : Change password.
  9. passwd user1 : change the password of a user (root only).
  10. chage -E 2011-12-31 user1 : placing a deadline for the password. In this case it says that the key expires on December 31, 2011.
  11. pwck : check the correct syntax of the file format ‘/ etc / passwd’ and the existence of users.
  12. grpck : check the correct syntax and format of the file ‘/ etc / group’ and the existence of groups.
  13. newgrp group_name : registers a new group to change default group of newly created files.

File permissions (Use “+” to set permissions and “-” to remove)

  1. ls -lh: Show permissions.: divide the terminal in 5 columns.
  2. ls /tmp | pr -T5 -W$COLUMNS: place readable ®, write (w) and execute (x) the owner (u) group (g) and others (o) on the ‘directory1’ directory.
  3. chmod ugo+rwx directory1: ® remove read permission, write (w) and (x) implementation group (g) and others (o) on the ‘directory1’ directory.
  4. chmod go-rwx directory1: change the owner of a file.
  5. chown user1 file1: change the owner of a directory and all files and directories contained inside.
  6. chown -R user1 directory1: Change group of files.
  7. chgrp group1 file1:change user and group ownership of a file.
  8. chown user1:group1 file1: display all files with SUID system configured.
  9. chmod u+s /bin/file1: set the SUID bit on a binary file. The user running this file takes the same privileges as the owner.
  10. chmod u-s /bin/file1:disable SUID bit on a binary file.
  11. chmod g+s /home/public: placing a SGID bit on a directory -similar to SUID but directory
  12. chmod g-s /home/public: disable SGID bit on a directory.
  13. chmod o+t /home/public: place a bit STIKY in a directory. It allows file deletion only to legitimate owners.
  14. chmod o-t /home/public:  disable STIKY bit in a directory.

Special Attributes on files (Use “+” to set permissions and “-” to remove)

  1. chattr +a file1 : you enter by opening a file only append mode.
  2. chattr +c file1 : allows a file is compressed / decompressed automatically.
  3. chattr +d file1 : ensures that the program ignore delete files during backup.
  4. chattr +i file1 : converts the file into invariable, so that can not be removed, altered, renamed or linked.
  5. chattr +s file1 : allows a file to be deleted safely.
  6. chattr +S file1 : ensures that a file is modified, the changes are written in synchronous mode as with sync.
  7. chattr +u file1 allows you to recover the contents of a file even if it is canceled.
  8. lsattr : show special attributes.

Archives and compressed files

  1. bunzip2 file1.bz2 : decompressed in file called ‘file1.bz2’.
  2. bzip2 file1 : compress a file called ‘file1’.
  3. gunzip file1.gz : unzip a file called ‘file1.gz’.
  4. gzip file1 : compress a file called ‘file1’.
  5. gzip -9 file1 : compress with maximum compression.
  6. rar a file1.rar test_file : create a zip file called ‘file1.rar’.
  7. rar a file1.rar file1 file2 dir1 : compress ‘file1’, ‘file2’ and ‘dir1’ simultaneously.
  8. rar x file1.rar : unpack rar file.
  9. unrar x file1.rar : unpack rar file.
  10. tar -cvf archive.tar file1 : create an uncompressed tarball.
  11. tar -cvf archive.tar file1 file2 dir1: create a file containing ‘file1’, ‘file2’ y’dir1 ‘.
  12. tar -tf archive.tar : display the contents of a file.
  13. tar -xvf archive.tar : extract a tarball.
  14. tar -xvf archive.tar -C / tmp : extract a tarball into / tmp.
  15. tar -cvfj archive.tar.bz2 dir1 : create a tarball compressed into bzip2.
  16. tar -xvfj archive.tar.bz2 : decompress a bzip2 compressed tar file
  17. tar -cvfz archive.tar.gz dir1: create a gzip compressed tarball.
  18. tar -xvfz archive.tar.gz: decompress a gzip compressed tar archive.
  19. zip file1.zip file1: create a compressed zip file.
  20. zip -r file1.zip file1 file2 dir1 : compress in zip several files and directories simultaneously.
  21. unzip file1.zip : unzip a zip file.

RPMs (Red Hat, Fedora and the like)

  1. rpm -ivh package.rpm : install an rpm package.
  2. rpm -ivh -nodeeps package.rpm : install a rpm package ignoring dependencies requests.
  3. rpm -U package.rpm : upgrade a rpm package without changing configuration files.
  4. rpm -F package.rpm : upgrade a rpm only if the package is installed.
  5. rpm -e package_name.rpm : remove a rpm package.
  6. rpm -qa : show all rpm packages installed on the system.
  7. rpm -qa | grep httpd : show all rpm packages with the name “httpd”.
  8. rpm -qi package_name: : information on a specific package installed.
  9. rpm -qg “System Environment/Daemons” : Show rpm packages of a group software.
  10. rpm -ql package_name : show list of files given by a rpm package installed.
  11. rpm -qc package_name: show list of configuration files for a given rpm package installed.
  12. rpm -q package_name –whatrequires : show list of dependencies required for a rpm package.
  13. rpm -q package_name -whatprovides :show capacity provided by a rpm package.
  14. rpm -q package_name -scripts : show started during installation / removal scripts.
  15. rpm -q package_name -changelog : show history of revisions of a rpm package.
  16. rpm -qf  /etc/httpd/conf/httpd.conf : verify which rpm package belongs to a given file.
  17. rpm -qp package.rpm -l: show list of files given by a rpm package not yet been installed.
  18. rpm –import /media/cdrom/RPM-GPG-KEY : Import the digital signature of the public key.
  19. rpm –checksig package.rpm: verify the integrity of a rpm package.
  20. rpm -qa gpg-pubkey : verify integrity of all rpm packages installed.
  21. rpm -V package_name:  check the file size, licenses, type, owner, group, MD5 sum check and last modification.
  22. rpm -Va : check all rpm packages installed on the system. Use with caution.
  23. rpm -Vp package.rpm : verify a rpm package not yet installed.
  24. rpm2cpio package.rpm | cpio –extract –make-directories *bin*: extracting executable file from a rpm package.
  25. rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm: install a package built from a rpm source.
  26. rpmbuild –rebuild package_name.src.rpm: build a rpm package from a rpm source.

YUM packages updater (Red Hat, Fedora and the like)

  1. yum install package_name : download and install a rpm package.
  2. yum localinstall package_name.rpm : this will install an RPM, and try to resolve all the dependencies for you using your repositories.
  3. yum update package_name.rpm  : update all rpm packages installed on the system.
  4. yum update package_name : modernize / upgrade a rpm package.
  5. yum remove package_name : remove a rpm package.
  6. yum list : list all packages installed on the system.
  7. yum search package_name : Find a package on rpm repository.
  8. yum clean packages : rpm clean a cache erasing downloaded packages.
  9. yum clean headers : remove all header files that the system uses to resolve dependency.
  10. yum clean all : remove from the cache packages and header files.

Deb packages (Debian, Ubuntu and derivatives)

  1. dpkg -i package.deb  : install / upgrade a deb package.
  2. dpkg -r package_name : remove a deb package from the system.
  3. dpkg -l : show all deb packages installed on the system.
  4. dpkg -l | grep httpd : show all deb packages with the name “httpd”
  5. dpkg -S package_name : information on a specific package installed on the system.
  6. dpkg -L package_name : Display list of files given by a package installed on the system.
  7. dpkg -contents package.deb : show list of files given by a package not yet installed.
  8. dpkg -S /bin/ping : verify which package belongs to a given file.

APT packages updater (Debian, Ubuntu and derivatives)

  1. apt-get install package_name : install / upgrade a deb package.
  2. apt-cdrom install package_name : install / upgrade a deb package from cdrom.
  3. apt-get update : update the list of packages.
  4. apt-get upgrade : update all installed packages.
  5. apt-get remove package_name : remove a deb package from the system.
  6. apt-get check : verify correct resolution of dependencies.
  7. apt-get clean : clean up cache from packages downloaded.
  8. apt-cache search searched-package : returns list of packages which corresponds to the series “wanted packages.”

View the contents of a file

  1. cat file1 : view the contents of a row starting from the first file.
  2. tac file1 : view the contents of a line starting from the last file.
  3. more file1 : view content over a file.
  4. less file1 : I like commando ‘more’ but allows the movement to save the file and backward movement.
  5. head -2 file1: : see the first two lines of a file.
  6. tail -2 file1  : see the last two lines of a file.
  7. tail -f /var/log/messages : see in real time what has been added to the file.

Text manipulation

  1. cat file1 file2 .. | command <> file1_in.txt_or_file1_out.txt : general syntax for text manipulation using PIPE, STDIN and STDOUT.
  2. cat file1 | command( sed, grep, awk, grep, etc…) > result.txt : general syntax to manipulate a text file and write the result to a new file.
  3. cat file1 | command( sed, grep, awk, grep, etc…) » result.txt : general syntax to manipulate a text file and add the result to an existing file.
  4. grep Aug /var/log/messages : search words “Aug” in the file “/ var / log / messages’.
  5. grep ^Aug /var/log/messages : find words that begin with “Aug” on file “/ var / log / messages’
  6. grep [0-9] /var/log/messages : select all lines in the file “/ var / log / messages’ that contain numbers.
  7. grep Aug -R /var/log/*: search string “Aug” in the directory “/ var / log ‘and under.
  8. sed ‘s/stringa1/stringa2/g’ example.txt : relocate “string1” with “string2” in sample.txt
  9. sed ‘/^$/d’ example.txt: : remove all blank lines from the sample.txt
  10. sed ‘/ *#/d; /^$/d’ example.txt: remove comments and blank lines sample.txt
  11. echo ‘esempio’ | tr ‘[:lower:]’ ‘[:upper:]’: Convert lowercase to uppercase.
  12. sed -e ‘1d’ result.txt: Delete the first line of the file sample.txt
  13. sed -n ‘/stringa1/p’: display only lines that contain the word “string1”.

Set character and file conversion

  1. dos2unix filedos.txt fileunix.txt: converting a text file format from MSDOS to UNIX.
  2. dos2unix filedos.txt fileunix.txt:: convert a text file format from UNIX to MSDOS.
  3. dos2unix filedos.txt fileunix.txt: convert a text file in html.
  4. recode -l | more: show all available format conversions.

Filesystem Analysis

  1. badblocks -v /dev/hda1 : Check for bad blocks on disk hda1.
  2. fsck /de /hda1 : repair / check integrity of the Linux file system disk hda1.
  3. fsck.ext2 /dev/hda1 : repair / check integrity EXT2 file system disk hda1.
  4. e2fsck /dev/hda1 : repair / check integrity EXT2 file system disk hda1.
  5. e2fsck -j /dev/hda1 : repair / check integrity EXT 3 file system disk hda1.
  6. fsck.ext3 /dev/hda1 : repair / check integrity EXT 3 file system disk hda1.
  7. fsck.vfat /dev/hda1 : repair / check integrity of the FAT file system disk hda1.
  8. fsck.msdos /dev/hda1 : repair / check integrity of a file system disk hda1 two.
  9. dosfsck /dev/hda1 : repair / check integrity of a file system disk hda1 two.

Format a Filesystem

  1. mkfs /dev/hda1 : create a Linux file system type on hda1 partition.
  2. mke2fs /dev/hda1 : create a file system Linux hda1 ext 2 type.
  3. mke2fs -j /dev/hda1 : create a file of Linux ext3 (journal) on hda1 type system partition.
  4. mkfs -t vfat 32 -F /dev/hda1 : create a FAT32 file system hda1.
  5. fdformat -n /dev/fd0 :  format a floopy disk.
  6. mkswap /dev/hda3 : create a swap file system.

Working with SWAP

  1. mkswap /dev/hda3 : create swap file system.
  2. swapon /dev/hda3 : activating a new swap partition.
  3. swapon /dev/hda2 /dev/hdb3 : activate two swap partitions.

Saved (Backup)

  1. dump -0aj -f /tmp/home0.bak /home : do a full save of ‘/ home’ directory.
  2. dump -1aj -f /tmp/home0.bak /home: do an incremental save the ‘/ home’ directory.
  3. restore -if /tmp/home0.bak : restoring a saved interactively.
  4. rsync -rogpav –delete /home /tmp : synchronization between directories.
  5. rsync -rogpav -e ssh –delete /home ip_address:/tmp: tunnel rsync through SSH.
  6. rsync -az -e ssh –delete ip_addr:/home/public /home/local: synchronize a local directory with a remote directory via ssh and compression.
  7. rsync -az -e ssh –delete /home/local ip_addr:/home/public: synchronize a remote directory with a local directory via ssh and compression.
  8. dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr ‘dd of=hda.gz’ : making a round of a hard disk on remote host via ssh.
  9. dd if=/dev/sda of=/tmp/file1 : save the contents of a hard disk in a file. (In this case the hard drive is “sda” and the file “file1”).
  10. tar -Puf backup.tar /home/user: make an incremental saves from ‘/ home / user’ directory.
  11. ( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr ‘cd /home/share/ && tar x -p’: copy the contents of a directory on remote directory via ssh.
  12. ( tar c /home ) | ssh -C user@ip_addr ‘cd /home/backup-home && tar x -p’: copy a local directory on remote directory via ssh.
  13. tar cf – . | (cd /tmp/backup ; tar xf – ) : local copy preserving the licenses and links from one directory to another.
  14. find /home/user1 -name ‘*.txt’ | xargs cp -av –target-directory=/home/backup/ –parents: find and copy all files with the extension ‘.txt’ from one directory to another.
  15. find /var/log -name ‘*.log’ | tar cv –files-from=- | bzip2 > log.tar.bz2 : find all files with extension ‘.log’ and make an bzip file.
  16. dd if=/dev/hda of=/dev/fd0 bs=512 count=1: : make a copy of MBR (Master Boot Record) to a floppy disk.
  17. dd if=/dev/fd0 of=/dev/hda bs=512 count=1 : restore the copy of the MBR (Master Boot Record) stored in a floppy.

CD ROM

  1. cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force : clean or erase a rewritable CD.
  2. mkisofs /dev/cdrom > cd.iso : create an iso image of cdrom on disk.
  3. mkisofs /dev/cdrom | gzip > cd_iso.gz : create a compressed iso image of cdrom on disk.
  4. mkisofs -J -allow-leading-dots -R -V “Label CD” -iso-level 4 -o ./cd.iso data_cd:  create an iso image of a directory.
  5. cdrecord -v dev=/dev/cdrom cd.iso : burn an ISO image.
  6. gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom –: burn a compressed iso image.
  7. mount -o loop cd.iso /mnt/iso : mounting an ISO image.
  8. cd-paranoia -B : take songs from a CD to wav files.
  9. cd-paranoia – “-3” : take the first 3 songs from a CD to wav files.
  10. cdrecord -scanbus : scan bus to identify the channel scsi.
  11. dd if=/dev/hdc | md5sum : md5sum for operating a device such as a CD.

Working with the network ( LAN and Wi-Fi)

  1. ifconfig eth0 : show the configuration of an Ethernet card.
  2. ifup eth0 : activate a ‘eth0’ interface.
  3. ifdown eth0 : disable a ‘eth0’ interface.
  4. ifconfig eth0 192.168.1.1 netmask 255.255.255.0 : configuring an IP address.
  5. ifconfig eth0 promisc : set ‘eth0’en common mode for packets (sniffing).
  6. dhclient eth0 : activate the ‘eth0’ interface in DHCP mode.
  7. route -n : show route table.
  8. route add -net 0/0 gw IP_Gateway : set default entry.
  9. route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1: static route configured to search the ‘net 192.168.0.0/16’.
  10. route del 0/0 gw IP_gateway: remove static route.
  11. echo “1” > /proc/sys/net/ipv4/ip_forward: enable ip route.
  12. hostname : display the name of the host system.
  13. host www.example.com : find the hostname to resolve name to ip (1) direction.
  14. nslookup www.example.com : find the hostname to resolve name to ip direccióm and vice versa (2).
  15. ip link show : Show link status of all interfaces.
  16. mii-tool eth0 : Show link status of ‘eth0’.
  17. ethtool eth0 : display statistics for network card ‘eth0’.
  18. netstat -tup : display all active connections and their PID network.
  19. netstat -tupl : show all network services listening on the system and their PID.
  20. tcpdump tcp port 80 : show all traffic HTTP .
  21. iwlist scan : show wireless networks.
  22. iwconfig eth1 : show the configuration of a wireless network card.
  23. whois www.example.com : search in Whois database.

Microsoft Windows networks (SAMBA)

  1. nbtscan ip_addr : bios name resolution network.
  2. nmblookup -A ip_addr : bios name resolution network.
  3. smbclient -L ip_addr/hostname : show remote shares of a windows host.

IP tables (firewall)

  1. iptables -t filter -L : show all chains of the filter table.
  2. iptables -t nat -L : show all chains of nat table.
  3. iptables -t filter -F : clear all the rules of the filter table.
  4. iptables -t nat -F : clear all the rules of the nat table.
  5. iptables -t filter -X : delete any string created by the user.
  6. iptables -t filter -A INPUT -p tcp –dport telnet -j ACCEPT : telnet connections allow ent.
  7. iptables -t filter -A OUTPUT -p tcp –dport http -j DROP : block connections HTTP to exit.
  8. iptables -t filter -A FORWARD -p tcp –dport pop3 -j ACCEPT : allow connectionsPOP to a front chain.
  9. iptables -t filter -A INPUT -j LOG –log-prefix “DROP INPUT” : recording an input string.
  10. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE : configure a PAT (Port Address Translation) on eth0, hiding forced departure packages.
  11. 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 : redirect packets from one host to another.

Monitoring and debugging

  1. top : display linux tasks using most cpu.
  2. ps -eafw : displays Linux tasks.
  3. ps -e -o pid, args -forest : displays Linux tasks in a hierarchical mode.
  4. pstree : displaying a tree system processes.
  5. kill -9PROCESS_ID : force the closure of the process and finish it.
  6. kill -1 PROCESS_ID: force a process to reload configuration.
  7. lsof -p $$ : display a list of files opened by processes.
  8. lsof /home/user1 : displays a list of open files in a given path system.
  9. strace -c ls >/dev/null: : display system calls made ​​and received by a process.
  10. strace -f -e open ls >/dev/null : show calls to the library.
  11. watch -n1 ‘cat /proc/interrupts’: show interruptions in real time.
  12. last reboot : reboot show history.
  13. lsmod : show kernel loaded.
  14. free -m : displays the status of RAM in megabytes.
  15. smartctl -A / dev / hda : monitoring reliability of a hard disk through SMART.
  16. smartctl -i / dev / hda : check if SMART is active on a hard drive.
  17. tail / var / log / dmesg : show events inherent to the process of loading the kernel.
  18. tail / var / log / messages : display system events.

Other useful commands

  1. apropos …keyword : display a list of commands that pertain to keywords of a program; They are useful when you know what your program does.
  2. ping man : display the manual pages online; for example, a ping command, use ‘-k’ option to find any related command.
  3. whatis …keyword : shows the description of what the program does.
  4. mkbootdisk -device /dev/fd0 ‘uname -r` : create a bootable floppy.
  5. gpg -c file1 : encrypt a file with GNU security guard.
  6. gpg file1.gpg  : decrypt a file with GNU Security Guard.
  7. wget -r www.example.com : download an entire website.
  8. wget -c www.example.com/file.iso : download a file with the ability to stop the download and resume later.
  9. echo ‘wget -c www.example.com/files.iso ‘| at 9:00 : Start download at any time.In this case it start at 9 am.
  10. ldd / usr / bin / ssh : show shared libraries required by ssh program.
  11. alias hh=’history’ : place an alias for a -hh = History commando.
  12. chsh : change the Shell command.
  13. chsh -list-shells : an appropriate command to know if you have to remote into another terminal.
  14. who -a : show who is registered, and print time of the last import system, dead processes, system registration processes, active processes produced by init, current performance and recent changes to the system clock.
If you liked this article, help us by sharing !!

Leave a Reply