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 ;)
-
Schedule a queue to run at 9am on March 1st. Note: Ctrl-d to save and exit.
$ at 9am March 1Schedule a queue to run after 5 minutes.
$ at now +5 minutesCheck any jobs pending to run, same as at -l .
$ atqEmpty out a file.
$ cat /dev/null > /path/to/fileChange directory, see also pushd and popd.
$ cdList run level information for the service type.
chkconfig --list <nameOfService>Change owner recursively.
$ chown -R <username>:<groupname> /path/to/directoryChange shell.
$ chshScan recursively for viruses.
clamscan -rFormat input into multiple columns.
mount | column -tCompare two files.
cmp file1 file2Copy keeping the directory structure.
$ cp --parent /source/path /destination/pathCopy keeping the permissions of the user.
$ cp -p <source> <destination>Copy recursive.
$ cp -r <source> <destination>Copy without shell aliasing.
$ \cp <source> <destination>Force copy new data over old data.
$ cp -a --reply=yes /path/to/new_data/* /path/to/old_data/List crontab for user.
$ crontab -u <user> -lCheck current date and time.
$ dateSet 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'Show disk free in human readable format.
$ df -hConfigure interface using DHCP protocol.
$ dhclient eth0Find context differences between two files.
$ diff -c <from-file> <to-file>Creating a patch file.
$ diff -Naur oldDir/oldFile newDir/newFile > new_patchFileKernel buffer
$ dmesgShow disk used in human readable format.
$ du -h /path/to/directoryFind files larger than 10MB.
$ find /path/to/file -size +10000kFind file permissions with setuids.
find / \( -perm -4000 -o -perm -2000 \) -exec ls -ldb {} \;>> /tmp/suidsSearch for world writable files and directories.
$ find / -perm -002Display information on free and used memory.
$ freeGrep on word boundaries.
grep -w <word>Count the number of mathces - similar to "wc -l".
$ grep -c <match expression>Perform timings of device reads for benchmark and comparison purposes.
$ hdparm -t /dev/hda1Set the hardware clock to the current system time.
$ hwclock --systohcPrint user identity.
$ id <user>Configure network interface.
$ ifconfigAdd an additional ip to eth0.
$ ifconfig eth0:x xxx.xxx.xxx.xxxInstall loadable kernel module. You can also use `modprobe` to do the same.
$ insmodDisplays information about your system's CPU and I/O.
$ iostat [ interval [ count ] ]List iptables firewall rules in numeric format.
$ iptables -L -nHangUP process so it will re-read the config file.
$ killall -HUP <serviceName>Install the boot loader and increase verborsity.
$ lilo -v -vQuery the boot map.
$ lilo -qOne time boot to the named kernel.
$ lilo -R <kernelName>Create symbolic link to the target file or directory.
$ ln -s <target> <linkName>Configure dynamic linker run-time bindings
$ ldconfigList the IPs bound via Ensim
$ listaliasesQuickly search for indexed files. Run `updatedb` to update the indexed database.
$ locateList files.
$ lsList directories.
$ ls -d */List all files reverse sorted by modification time-stamp in human-readable format.
$ ls -altrhList all files reverse sorted by file size in human-readable format.
$ ls -alSrhList loaded kernel modules
$ lsmodCreate the access.db file database map for sendmail.
$ makemap hash /etc/mail/access.db < /etc/mail/accessCreate/Make a new directory.
$ mkdirGenerate a random 128 character length password.
$ mkpasswd -l 128Read in the contents of your mbox (or the specified file).
$ mail -f /var/mail/nameOfFilePrint the mail queue
$ mailq
$ mailstat /path/to/procmail/logDescription of the hierarchy directory structure of the system
$ man hierCheck the MD5 message digest.
$ md5sumMount points check.
$ mountProvide information about your systems' processor.
$ mpstat [ interval [ count ] ]
$ ncftpget -R -u-p hostname /local_dir /remote_dir
$ netstat -a | grep -i listenWill show you who is attached to what port.
$ netstat -anpe
$ netstat -nSee which programs are listening on which port
$ netstat -lnpWill show you what local TCP ports are open and what programs are running on them.
$ netstat -lntpeWill show you what local UDP ports are open and what programs are running on them.
$ netstat -lnupeRun a program with modified scheduling priority. (# range between -20 to +20, negative is higher prio
rity)
$ nice -n # [command to nice]Scan network
$ nmap -v hostname/ipQuery a list of the NTP peers known to the server as well as a summary of their state.
# ntpq -p localhostmerge lines of files
paste file1 file2Patch and keep a backup
$ patch -p# -b < patch_file
$ ps -ecauxTurn off all quotas for users and groups, verbose mode
$ quotaoff -augvCheck quota for all users and groups interactively, do quotaoff first.
$ quotacheck -augmivTurn on all quotas for users and groups
$ quotaon -augvDisplay the routing table in numeric.
$ route -nAdd host ip to route on a particular device.
# route add -host xxx.xxx.xxx.xxx dev eth0:xAdd network to route on a particular device.
# route add -net 192.168.0.0 netmask 255.255.255.0 eth0
$ rdate
$ rmRemove kernel module
$ rmmod <kernelModule>
$ rpmUninstall/erase package.
$ rpm -e <package>Erase without dependency check.
$ rpm -e --nodeps <package>List out installed rpms by date, latest on top.
$ rpm -qa --last | lessRebuild rpm database.
$ rpm --rebuilddbFind which package owns the file.
$ rpm -qf /path/to/file $ rpm -q --whatprovides /path/to/fileVerify package.
$ rpm -V <package>
or
$ rpm -Vf /path/to/fileLocate documentation for the package that owns the file.
$ rpm -qdf /path/to/fileQuery information on package.
$ rpm -qip <package.rpm>Query files installed by package.
$ rpm -qlp <package.rpm>Gives list of files that will be installed/overwritten.
$ rpm -ql <rpmname>Will show the scripts that will be executed.
$ rpm -q --scripts <rpmname>Display system activity information
$ sarPrint a 0 padded sequence of numbers.
$ seq -w 1 10Record eveything printed on your terminal screen.
$ script -a <filename>
Ctrl+D to exit out. `more <filename>` to view.
Check the status of a service.$ service <name of service> statusRestart after shutdown and force fsck (fsck may take a while).
$ shutdown -rF nowSplit 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`
Determine if a network service binary is linked againt tcp wrapper, libwrap.a$ strings -f <binary file name> | grep hosts_access
$ tar
$ tar -cvzf fileName.tar.gz `find /file/path -mtime -1 ! -type d -print`
$ tar -xvzpf fileName.tar.gz /path/to/file.txt
$ tcpdump -i eth0 dst port 80 | more
$ topView the full command line.
$ top -c
$ touchSimilar to `which` - shows full path to the command.
$ type <command>
$ ulimit -a
$ unameUpdate package profile with rhn
$ up2date -pInstall package via up2date.
$ up2date -i <packageName>
$ uptime
$ usermodUtility reports virtual memory statistics
$ vmstat [second interval] [no. of count]Show who is logged on and what they are doing.
$ wPeriodically watch output of a command in full screen
$ watch '<command>'
$ webalizer -c /path/to/webalizer.confRecursive download of a url, converting links, no parent.
$ wget -r -k -np <URL>Mirror, convert links, backup original, dynamic to html and output a "logFile".
$ wget -m -k -K -E <URL> -o [logFile]Locate the binary, source, and manual page files for a command.
$ whereis <command>Shows the full path of command.
$ which <command>Show who is logged on.
$ whoYum 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 packageControl jobs:
$ Ctrl-z -- suspend foreground job $ jobs -- list jobs $ bg -- send job to background $ fg -- bring job to foreground