h1

Quick references to some frequently used Linux commands

July 2, 2006
  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. Compare two files.
    cmp file1 file2
  11. Copy keeping the directory structure.
    $ cp --parent /source/path /destination/path
  12. Copy keeping the permissions of the user.
    $ cp -p <source> <destination>
  13. Copy recursive.
    $ cp -r <source> <destination>
  14. Copy without shell aliasing.
    $ \cp <source> <destination>
  15. List crontab for user.
    $ crontab -u <user> -l
  16. Check current date and time.
    $ date
  17. 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'
  18. Show disk free in human readable format.
    $ df -h
  19. Configure interface using DHCP protocol.
    $ dhclient eth0
  20. Find context differences between two files.
    $ diff -c <from-file> <to-file>
  21. Creating a patch file.
    $ diff -Naur oldDir/oldFile newDir/newFile > new_patchFile
  22. Kernel buffer
    $ dmesg
  23. Show disk used in human readable format.
    $ du -h /path/to/directory
  24. Find files larger than 10MB.
    $ find /path/to/file -size +10000k
  25. Find file permissions with setuids.
    find / \( -perm -4000 -o -perm -2000 \) -exec ls -ldb {} \;>> /tmp/suids
  26. Search for world writable files and directories.
    $ find / -perm -002
  27. Display information on free and used memory.
    $ free
  28. Grep on word boundaries.
    grep -w <word>
  29. Count the number of mathces – similar to “wc -l”.
    $ grep -c <match expression>
  30. Perform timings of device reads for benchmark and comparison purposes.
    $ hdparm -t /dev/hda1
  31. Set the hardware clock to the current system time.
    $ hwclock --systohc
  32. Configure network interface.
    $ ifconfig
  33. Add an additional ip to eth0.
    $ ifconfig eth0:x xxx.xxx.xxx.xxx
  34. Install loadable kernel module. You can also use `modprobe` to do the same.
    $ insmod
  35. Displays information about your system’s CPU and I/O.
    $ iostat [ interval [ count ] ]
  36. List iptables firewall rules in numeric format.
    $ iptables -L -n
  37. HangUP process so it will re-read the config file.
    $ killall -HUP <serviceName>
  38. Install the boot loader and increase verborsity.
    $ lilo -v -v
  39. Query the boot map.
    $ lilo -q
  40. One time boot to the named kernel.
    $ lilo -R <kernelName>
  41. Create symbolic link to the target file or directory.
    $ ln -s <target> <linkName>
  42. Configure dynamic linker run-time bindings
    $ ldconfig
  43. List the IPs bound via Ensim
    $ listaliases
  44. Quickly search for indexed files. Run `updatedb` to update the indexed database.
    $ locate
  45. List files.
    $ ls
  46. List loaded kernel modules
    $ lsmod
  47. Create the access.db file database map for sendmail.
    $ makemap hash /etc/mail/access.db < /etc/mail/access
  48. Create/Make a new directory.
    $ mkdir
  49. Generate a random 128 character length password.
    $ mkpasswd -l 128
  50. Read in the contents of your mbox (or the specified file).
    $ mail -f /var/mail/nameOfFile
  51. Print the mail queue
    $ mailq
  52. $ mailstat /path/to/procmail/log
  53. Description of the hierarchy directory structure of the system
    $ man hier
  54. Check the MD5 message digest.
    $ md5sum 
  55. Mount points check.
    $ mount
  56. Provide information about your systems’ processor.
    $ mpstat [ interval [ count ] ]
  57. $ ncftpget -R -u  -p
    hostname /local_dir /remote_dir
  58. $ netstat -a | grep -i listen
  59. Will show you who is attached to what port.
    $ netstat -anpe
  60. $ netstat -n
  61. See which programs are listening on which port
    $ netstat -lnp
  62. Will show you what local TCP ports are open and what programs are running on them.
    $ netstat -lntpe
  63. Will show you what local UDP ports are open and what programs are running on them.
    $ netstat -lnupe
  64. Run a program with modified scheduling priority. (# range between -20 to +20, negative is higher prio
    rity)

    $ nice -n # [command to nice]
  65. Scan network
    $ nmap -v hostname/ip
  66. Patch and keep a backup
    $ patch -p# -b < patch_file
  67. $ ps -ecaux
  68. Turn off all quotas for users and groups, verbose mode
    $ quotaoff -augv
  69. Check quota for all users and groups interactively, do quotaoff first.
    $ quotacheck -augmiv
  70. Turn on all quotas for users and groups
    $ quotaon -augv
  71. Add host ip to route on a particular device.
    $ route add -host xxx.xxx.xxx.xxx dev eth0:x
  72. $ rdate
  73. $ rm
  74. Remove kernel module
    $ rmmod <kernelModule>
  75. Display the routing table in numeric.
    $ route -n
  76. $ rpm
  77. Uninstall/erase package.
    $ rpm -e <package>
  78. Erase without dependency check.
    $ rpm -e --nodeps <package>
  79. List out installed rpms by date, latest on top.
    $ rpm -qa --last | less
  80. Rebuild rpm database.
    $ rpm --rebuilddb
  81. Find which package owns the file.
    $ rpm -qf /path/to/file
    
    $ rpm -q --whatprovides /path/to/file
  82. Verify package.
    $ rpm -V <package>

    or

    $ rpm -Vf /path/to/file
  83. Locate documentation for the package that owns the file.
    $ rpm -qdf /path/to/file
  84. Query information on package.
    $ rpm -qip <package.rpm>
  85. Query files installed by package.
    $ rpm -qlp <package.rpm>
  86. Gives list of files that will be installed/overwritten.
    $ rpm -ql <rpmname>
  87. Will show the scripts that will be executed.
    $ rpm -q --scripts <rpmname>
  88. Display system activity information
    $ sar
  89. Print a 0 padded sequence of numbers.
    $ seq -w 1 10
  90. Record eveything printed on your terminal screen.
    $ script -a <filename>

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

  91. Check the status of a service.
    $ service <name of service> status
  92. Restart after shutdown and force fsck (fsck may take a while).
    $ shutdown -rF now
  93. 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`

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

2 comments

  1. Nice collection of commands
    A computer user must read


    • i agree with you



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: