cheat sheet for linux and unix

 

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
Command Action
pwd "Print working directory" - show what dir you're in.
ls List the contents of a dir.
ls -l List the contents of a dir and show additional info of the files.
ls -a List all files, including hidden files.
cd Change directory.
cd .. Go to the parent directory.
Examining files
Command Action
file Determine the type of a file.
cat Concatenate a file.
less View text files and paginate them if needed.
Manipulating files and directories
Command Action
cp Copy a file.
cp -i Copy a file and ask before overwriting.
cp -r Copy a directory with its contents.
mv Move or rename a file.
mv -i Move or rename a file and ask before overwriting.
rm Remove a file.
rm -r Remove a directory with its contents.
rm -i Ask before removing a file. Good to use with the -r option.
mkdir Make a directory.
rmdir Remove 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:

Syntax Description Example(s)
rpm -ivh {rpm-file} Install the package rpm -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 package rpm -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 package rpm -ev mozilla-mail
rpm -ev --nodeps {package} Erase/remove/ an installed package without checking for dependencies rpm -ev --nodeps mozilla-mail
rpm -qa Display list all installed packages rpm -qa
rpm -qa | less
rpm -qi {package} Display installed information along with package version and short description rpm -qi mozilla-mail
rpm -qf {/path/to/file} Find out what package a file belongs to i.e. find what package owns the file rpm -qf /etc/passwd
rpm -qf /bin/bash
rpm -qc {pacakge-name} Display list of configuration file(s) for a package rpm -qc httpd
rpm -qcf {/path/to/file} Display list of configuration files for a command rpm -qcf /usr/X11R6/bin/xeyes
rpm -qa --last Display list of all recently installed RPMs rpm -qa --last
rpm -qa --last | less
rpm -qpR {.rpm-file}
rpm -qR {package}
Find out what dependencies a rpm file has rpm -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:

Syntax Description Example(s)
apt-get install {package} Install the new package. If package is installed then try to upgrade to latest version apt-get install zip
apt-get install lsof samba mysql-client
apt-get remove {package} Remove/Delete an installed package except configuration files apt-get remove zip
apt-get --purge remove {package} Remove/Delete everything including configuration files apt-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:

Syntax Description Example
dpkg -i {.deb package} Install the package dpkg -i zip_2.31-3_i386.deb
dpkg -i {.deb package} Upgrade package if it is installed else install a fresh copy of package dpkg -i zip_2.31-3_i386.deb
dpkg -R {Directory-name} Install all packages recursively from directory dpkg -R /tmp/downloads
dpkg -r {package} Remove/Delete an installed package except configuration files dpkg -r zip
dpkg -P {package} Remove/Delete everything including configuration files dpkg -P apache-perl
dpkg -l List all installed packages, along with package version and short description dpkg -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 description dpkg -l apache-perl
dpkg -L {package} Find out files are provided by the installed package i.e. list where files were installed dpkg -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 installed dpkg -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 belong dpkg -S /bin/netstat
dpkg -S /sbin/ippool
dpkg -p {package} Display details about package package group, version, maintainer, Architecture, display depends packages, description etc dpkg -p lsof
dpkg -s {package} | grep Status Find 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 files copy cp cp thisfile.txt /home/thisdirectory
Moves files move mv mv thisfile.txt /home/thisdirectory
Lists files dir ls ls
Clears screen cls clear clear
Closes prompt window exit exit exit
Displays or sets date date date date
Deletes files del rm rm thisfile.txt
"Echoes" output on the screen echo echo echo this message
Edits files with simple text editor edit pico[a] pico thisfile.txt
Compares the contents of files fc diff diff file1 file2
Finds a string of text in a file find grep grep this word or phrase thisfile.txt
Formats a floppy format a: (if floppy's in A:) mke2fs (or mformat[b]) /sbin/mke2fs /dev/fd0 (/dev/fd0 is the Linux equivalent of A:)
Displays command help command /? man[c] man command
Creates a directory mkdir mkdir mkdir directory
Screens through a file more less[d] less thisfile.txt
Renames a file ren mv mv thisfile.txt thatfile.txt[e]
Shows your location in the file system chdir pwd pwd
Changes directories with a specified path (absolute path) cd pathname cd pathname cd /directory/directory
Changes directories with a relative path cd .. cd .. cd ..
Displays the time time date date
Shows amount of RAM and use mem free procinfo
Notes:
a. Pico is a simple text editor; other editors you can use in place of 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章