Quick references to some frequently used Linux commands…

This list has been compiled over time as reference to some of the frequently used linux commands that I use. I hope it will help some new-comers ;)

  1. Schedule a queue to run at 9am on March 1st. Note: Ctrl-d to save and exit.
    $ at 9am March 1
  2. Schedule a queue to run after 5 minutes.
    $ at now +5 minutes
  3. Check any jobs pending to run, same as at -l .
    $ atq
  4. Empty out a file.
    $ cat /dev/null > /path/to/file
  5. Change directory, see also pushd and popd.
    $ cd
  6. List run level information for the service type.
    chkconfig --list <nameOfService>
  7. Change owner recursively.
    $ chown -R <username>:<groupname> /path/to/directory
  8. Change shell.
    $ chsh
  9. Scan recursively for viruses.
    clamscan -r
  10. Format input into multiple columns.
    mount | column -t
  11. Compare two files.
    cmp file1 file2
  12. Copy keeping the directory structure.
    $ cp --parent /source/path /destination/path
  13. Copy keeping the permissions of the user.
    $ cp -p <source> <destination>
  14. Copy recursive.
    $ cp -r <source> <destination>
  15. Copy without shell aliasing.
    $ cp <source> <destination>
  16. Force copy new data over old data.
    $ cp -a --reply=yes /path/to/new_data/* /path/to/old_data/
  17. List crontab for user.
    $ crontab -u <user> -l
  18. Check current date and time.
    $ date
  19. Set current date and time, may need to set the hardware clock to the system time too, `man hwclock`.
    $ date -s 'Wed May 28 11:35:00 EST 2003'
  20. Show disk free in human readable format.
    $ df -h
  21. Configure interface using DHCP protocol.
    $ dhclient eth0
  22. Find context differences between two files.
    $ diff -c <from-file> <to-file>
  23. Creating a patch file.
    $ diff -Naur oldDir/oldFile newDir/newFile > new_patchFile
  24. Kernel buffer
    $ dmesg
  25. Show disk used in human readable format.
    $ du -h /path/to/directory
  26. Find files larger than 10MB.
    $ find /path/to/file -size +10000k
  27. Find file permissions with setuids.
    find / ( -perm -4000 -o -perm -2000 ) -exec ls -ldb {} ;>> /tmp/suids
  28. Search for world writable files and directories.
    $ find / -perm -002
  29. Display information on free and used memory.
    $ free
  30. Grep on word boundaries.
    grep -w <word>
  31. Count the number of mathces – similar to “wc -l”.
    $ grep -c <match expression>
  32. Perform timings of device reads for benchmark and comparison purposes.
    $ hdparm -t /dev/hda1
  33. Set the hardware clock to the current system time.
    $ hwclock --systohc
  34. Print user identity.
    $ id <user>
  35. Configure network interface.
    $ ifconfig
  36. Add an additional ip to eth0.
    $ ifconfig eth0:x xxx.xxx.xxx.xxx
  37. Install loadable kernel module. You can also use `modprobe` to do the same.
    $ insmod
  38. Displays information about your system’s CPU and I/O.
    $ iostat [ interval [ count ] ]
  39. List iptables firewall rules in numeric format.
    $ iptables -L -n
  40. HangUP process so it will re-read the config file.
    $ killall -HUP <serviceName>
  41. Install the boot loader and increase verborsity.
    $ lilo -v -v
  42. Query the boot map.
    $ lilo -q
  43. One time boot to the named kernel.
    $ lilo -R <kernelName>
  44. Create symbolic link to the target file or directory.
    $ ln -s <target> <linkName>
  45. Configure dynamic linker run-time bindings
    $ ldconfig
  46. List the IPs bound via Ensim
    $ listaliases
  47. Quickly search for indexed files. Run `updatedb` to update the indexed database.
    $ locate
  48. List files.
    $ ls
  49. List directories.
    $ ls -d */
  50. List all files reverse sorted by modification time-stamp in human-readable format.
    $ ls -altrh
  51. List all files reverse sorted by file size in human-readable format.
    $ ls -alSrh
  52. List loaded kernel modules
    $ lsmod
  53. Create the access.db file database map for sendmail.
    $ makemap hash /etc/mail/access.db < /etc/mail/access
  54. Create/Make a new directory.
    $ mkdir
  55. Generate a random 128 character length password.
    $ mkpasswd -l 128
  56. Read in the contents of your mbox (or the specified file).
    $ mail -f /var/mail/nameOfFile
  57. Print the mail queue
    $ mailq
  58. $ mailstat /path/to/procmail/log
  59. Description of the hierarchy directory structure of the system
    $ man hier
  60. Check the MD5 message digest.
    $ md5sum
  61. Mount points check.
    $ mount
  62. Provide information about your systems’ processor.
    $ mpstat [ interval [ count ] ]
  63. $ ncftpget -R -u  -p  hostname /local_dir /remote_dir
  64. $ netstat -a | grep -i listen
  65. Will show you who is attached to what port.
    $ netstat -anpe
  66. $ netstat -n
  67. See which programs are listening on which port
    $ netstat -lnp
  68. Will show you what local TCP ports are open and what programs are running on them.
    $ netstat -lntpe
  69. Will show you what local UDP ports are open and what programs are running on them.
    $ netstat -lnupe
  70. Run a program with modified scheduling priority. (# range between -20 to +20, negative is higher prio
    rity)

    $ nice -n # [command to nice]
  71. Scan network
    $ nmap -v hostname/ip
  72. Query a list of the NTP peers known to the server as well as a summary of their state.
    # ntpq -p localhost
  73. merge lines of files
    paste file1 file2
  74. Patch and keep a backup
    $ patch -p# -b < patch_file
  75. $ ps -ecaux
  76. Turn off all quotas for users and groups, verbose mode
    $ quotaoff -augv
  77. Check quota for all users and groups interactively, do quotaoff first.
    $ quotacheck -augmiv
  78. Turn on all quotas for users and groups
    $ quotaon -augv
  79. Display the routing table in numeric.
    $ route -n
  80. Add host ip to route on a particular device.
    # route add -host xxx.xxx.xxx.xxx dev eth0:x
  81. Add network to route on a particular device.
    # route add -net 192.168.0.0 netmask 255.255.255.0 eth0
  82. $ rdate
  83. $ rm
  84. Remove kernel module
    $ rmmod <kernelModule>
  85. $ rpm
  86. Uninstall/erase package.
    $ rpm -e <package>
  87. Erase without dependency check.
    $ rpm -e --nodeps <package>
  88. List out installed rpms by date, latest on top.
    $ rpm -qa --last | less
  89. Rebuild rpm database.
    $ rpm --rebuilddb
  90. Find which package owns the file.
    $ rpm -qf /path/to/file
    $ rpm -q --whatprovides /path/to/file
  91. Verify package.
    $ rpm -V <package>

    or

    $ rpm -Vf /path/to/file
  92. Locate documentation for the package that owns the file.
    $ rpm -qdf /path/to/file
  93. Query information on package.
    $ rpm -qip <package.rpm>
  94. Query files installed by package.
    $ rpm -qlp <package.rpm>
  95. Gives list of files that will be installed/overwritten.
    $ rpm -ql <rpmname>
  96. Will show the scripts that will be executed.
    $ rpm -q --scripts <rpmname>
  97. Display system activity information
    $ sar
  98. Print a 0 padded sequence of numbers.
    $ seq -w 1 10
  99. Record eveything printed on your terminal screen.
    $ script -a <filename>

    Ctrl+D to exit out. `more <filename>` to view.

  100. Check the status of a service.
    $ service <name of service> status
  101. Restart after shutdown and force fsck (fsck may take a while).
    $ shutdown -rF now
  102. Split a file into pieces with numeric suffixes, so it can be burnt to cds.
    $ split -d -b 640k big_input_filename.gz piece_file_prefix.gz.

    To piece it back you can `cat piece_file_prefix.gz.* > original.gz`

  103. Determine if a network service binary is linked againt tcp wrapper, libwrap.a
    $ strings -f <binary file name> | grep hosts_access
  104. $ tar
  105. $ tar -cvzf fileName.tar.gz `find /file/path -mtime -1 ! -type d -print`
  106. $ tar -xvzpf fileName.tar.gz /path/to/file.txt
  107. $ tcpdump -i eth0 dst port 80 | more
  108. $ top
  109. View the full command line.
    $ top -c
  110. $ touch
  111. Similar to `which` – shows full path to the command.
    $ type <command>
  112. $ ulimit -a
  113. $ uname
  114. Update package profile with rhn
    $ up2date -p
  115. Install package via up2date.
    $ up2date -i <packageName>
  116. $ uptime
  117. $ usermod
  118. Utility reports virtual memory statistics
    $ vmstat [second interval] [no. of count]
  119. Show who is logged on and what they are doing.
    $ w
  120. Periodically watch output of a command in full screen
    $ watch '<command>'
  121. $ webalizer -c /path/to/webalizer.conf
  122. Recursive download of a url, converting links, no parent.
    $ wget -r -k -np <URL>
  123. Mirror, convert links, backup original, dynamic to html and output a “logFile”.
    $ wget -m -k -K -E <URL> -o [logFile]
  124. Locate the binary, source, and manual page files for a command.
    $ whereis <command>
  125. Shows the full path of command.
    $ which <command>
  126. Show who is logged on.
    $ who
  127. Yum package updates
      $ yum check-update           -- check to see what updates are needed
      $ yum info <package name>    -- show basic information about a package
      $ yum update <package name>  -- update particular package
  128. Control jobs:
      $ Ctrl-z   -- suspend foreground job
      $ jobs     -- list jobs
      $ bg       -- send job to background
      $ fg       -- bring job to foreground
Bookmark/Search this post with