您的位置:首页 > 运维架构 > Linux

cheat sheet for linux and unix

2009-11-13 14:48 656 查看
A small Linux cheat sheet, introducing the very basic and very essential commands for surviving at the Linux CLI.

Moving around in the file system
CommandAction
pwd"Print working directory" - show what dir you're in.
lsList the contents of a dir.
ls -lList the contents of a dir and show additional info of the files.
ls -aList all files, including hidden files.
cdChange directory.
cd ..Go to the parent directory.
Examining files
CommandAction
fileDetermine the type of a file.
catConcatenate a file.
lessView text files and paginate them if needed.
Manipulating files and directories
CommandAction
cpCopy a file.
cp -iCopy a file and ask before overwriting.
cp -rCopy a directory with its contents.
mvMove or rename a file.
mv -iMove or rename a file and ask before overwriting.
rmRemove a file.
rm -rRemove a directory with its contents.
rm -iAsk before removing a file. Good to use with the -r option.
mkdirMake a directory.
rmdirRemove an empty directory.

rpm command cheat sheet for Linux

rpm is a powerful Package Manager for Red Hat, Suse and Fedora Linux. It can be used to build, install, query, verify, update, and remove/erase individual software packages. A Package consists of an archive of files, and package information, including name, version, and description:

SyntaxDescriptionExample(s)
rpm -ivh {rpm-file}Install the packagerpm -ivh mozilla-mail-1.7.5-17.i586.rpm
rpm -ivh --test mozilla-mail-1.7.5-17.i586.rpm
rpm -Uvh {rpm-file}Upgrade packagerpm -Uvh mozilla-mail-1.7.6-12.i586.rpm
rpm -Uvh --test mozilla-mail-1.7.6-12.i586.rpm
rpm -ev {package}Erase/remove/ an installed packagerpm -ev mozilla-mail
rpm -ev --nodeps {package}Erase/remove/ an installed package without checking for dependenciesrpm -ev --nodeps mozilla-mail
rpm -qaDisplay list all installed packagesrpm -qa
rpm -qa | less
rpm -qi {package}Display installed information along with package version and short descriptionrpm -qi mozilla-mail
rpm -qf {/path/to/file}Find out what package a file belongs to i.e. find what package owns the filerpm -qf /etc/passwd
rpm -qf /bin/bash
rpm -qc {pacakge-name}Display list of configuration file(s) for a packagerpm -qc httpd
rpm -qcf {/path/to/file}Display list of configuration files for a commandrpm -qcf /usr/X11R6/bin/xeyes
rpm -qa --lastDisplay list of all recently installed RPMsrpm -qa --last
rpm -qa --last | less
rpm -qpR {.rpm-file}
rpm -qR {package}
Find out what dependencies a rpm file hasrpm -qpR mediawiki-1.4rc1-4.i586.rpm
rpm -qR bash
{package} - Replace with actual package name

apt-get is the command-line tool for handling packages for Debian Linux which is use to:

Install/manage individual packages

Upgrade packages

Apply security patch(s)

Keep Debian system up to date

Download source .deb files

Front-end to many GUI and other utilities

Here is quick cheat sheet you will find handy while using apt-get at shell prompt:

SyntaxDescriptionExample(s)
apt-get install {package}Install the new package. If package is installed then try to upgrade to latest versionapt-get install zip
apt-get install lsof samba mysql-client
apt-get remove {package}Remove/Delete an installed package except configuration filesapt-get remove zip
apt-get --purge remove {package}Remove/Delete everything including configuration filesapt-get --purge remove mysql-server
apt-get update
apt-get upgrade
Resynchronize the package index files and Upgrade the Debian Linux system including security update (Internet access required)apt-get update
apt-get upgrade
apt-get update
apt-get dist-upgrade
Usually use to upgrade to Debian distribution. For example Woody to Sarge upgrade. 'dist-upgrade' in addition to performing the function of upgrade, also intelligently handles changing dependencies with new versions of packages; apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary. apt-get update
apt-get dist-upgrade
{package} - Replace with actual package name

dpkg is package manager for Debian Linux which is use to install/manage individual packages. Here is quick cheat sheet you will find handy while using dpkg at shell prompt:

SyntaxDescriptionExample
dpkg -i {.deb package}Install the packagedpkg -i zip_2.31-3_i386.deb
dpkg -i {.deb package}Upgrade package if it is installed else install a fresh copy of packagedpkg -i zip_2.31-3_i386.deb
dpkg -R {Directory-name}Install all packages recursively from directorydpkg -R /tmp/downloads
dpkg -r {package}Remove/Delete an installed package except configuration filesdpkg -r zip
dpkg -P {package}Remove/Delete everything including configuration filesdpkg -P apache-perl
dpkg -lList all installed packages, along with package version and short descriptiondpkg -l
dokg -l | less
dpkg -l '*apache*'
dpkg -l | grep -i 'sudo'
dpkg -l {package}List individual installed packages, along with package version and short descriptiondpkg -l apache-perl
dpkg -L {package}Find out files are provided by the installed package i.e. list where files were installeddpkg -L apache-perl
dpkg -L perl
dpkg -c {.Deb package}List files provided (or owned) by the package i.e. List all files inside debian .deb package file, very useful to find where files would be installeddpkg -c dc_1.06-19_i386.deb
dpkg -S {/path/to/file}Find what package owns the file i.e. find out what package does file belongdpkg -S /bin/netstat
dpkg -S /sbin/ippool
dpkg -p {package}Display details about package package group, version, maintainer, Architecture, display depends packages, description etcdpkg -p lsof
dpkg -s {package} | grep StatusFind out if Debian package is installed or not (status)dpkg -s lsof | grep Status
{package} - Replace with actual package name

Appendix C. DOS to Linux Cheat Sheet

Many Linux commands you type at a shell prompt are not that different from the commands you would type either in MS-DOS or in Windows (from the MS-DOS prompt). In fact, some commands are identical.

DOS and Linux Commands

What follows are some common commands used at the MS-DOS prompt in Windows 9x, and in Linux, as well as a basic example of how the command is used at the Linux shell prompt. Note that these commands usually have a number of options. To learn more about each command, read its associated man page (for example, type man ls at the shell prompt to read about the ls command).

Table C-1. Similar Commands

Command's PurposeMS-DOSLinuxBasic Linux Example
Copies filescopycpcp thisfile.txt /home/thisdirectory
Moves filesmovemvmv thisfile.txt /home/thisdirectory
Lists filesdirlsls
Clears screenclsclearclear
Closes prompt windowexitexitexit
Displays or sets datedatedatedate
Deletes filesdelrmrm thisfile.txt
"Echoes" output on the screenechoechoecho this message
Edits files with simple text editoreditpico[a]pico thisfile.txt
Compares the contents of filesfcdiffdiff file1 file2
Finds a string of text in a filefindgrepgrep this word or phrase thisfile.txt
Formats a floppyformat a: (if floppy's in A:)mke2fs (or mformat)/sbin/mke2fs /dev/fd0 (/dev/fd0 is the Linux equivalent of A:)
Displays command helpcommand /?man[c]man command
Creates a directorymkdirmkdirmkdir directory
Screens through a filemoreless[d]less thisfile.txt
Renames a filerenmvmv thisfile.txt thatfile.txt[e]
Shows your location in the file systemchdirpwdpwd
Changes directories with a specified path (absolute path)cd pathnamecd pathnamecd /directory/directory
Changes directories with a relative pathcd ..cd ..cd ..
Displays the timetimedatedate
Shows amount of RAM and usememfreeprocinfo
Notes:
a. Pico is a simple text editor; other editors you can use in place of [b]pico include emacs and vi.
b. This formats a disk for the DOS filesystem.
c. Or you can use info for some commands.
d. You can also another pager, called more, to scroll through a file a screen at at time.
e. The mv command serves double-duty, because it can both move a file and, if you want to rename a file in the same directory, you "move" that file to the same directory with a new name, as in this example.
http://www.cnbeta.com/articles/48871.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: