Docstoc

Most Frequently used Basic Linux Commands

Document Sample
Most Frequently used Basic Linux Commands Powered By Docstoc
					 Command           Example
cat


           cat .bashrc
cd
           cd /home



           cd httpd


           cd ..


           cd ~


cp
           cp myfile yourfile



           cp -i myfile yourfile

           cp -i /data/myfile .


           cp -dpr srcdir destdir




dd

           dd if=/dev/hdb1
           of=/backup/
df

less

           less textfile
ln
           ln -s test symlink




locate
           slocate -u




           locate whereis
logout
ls
           ls

           ls -al


more

           more /etc/profile

           ls -al |more



mv
           mv -i myfile yourfile

           mv -i /data/myfile .

pwd
           more /etc/profile

shutdown
           shutdown -h now
           shutdown -r now

whereis

           whereis ls


Chown – change ownership of a file
# chown -R us base
Change the ownership of file base to the user us and make it recurs

chmod - change file access permissions
chmod 400 file - Read by owner
chmod 040 file - Read by group
chmod 004 file - Read by world

chmod 200 file - Write by owner
chmod 020 file - Write by group
chmod 002 file - Write by world

chmod 100 file - execute by owner
chmod 010 file - execute by group
chmod 001 file - execute by world
To combine these, just add the numbers together:
chmod 444 file - Allow read permission to owner and group and wo
chmod 777 file - Allow everyone to read, write, and execute file
Chkconfig
chkconfig --level 345 nscd off
chkconfig can also be used to configure a service to be started (or n




mkdir - make directories
Usage

mkdir [OPTION] DIRECTORY
Options
Create the DIRECTORY(ies), if they do not already exist.
 Mandatory arguments to long options are mandatory for short options too.
 -m, mode=MODE set permission mode (as in chmod), not rwxrwxrwx - umask
 -p, parents no error if existing, make parent directories as needed
 -v, verbose print a message for each created directory
 -help display this help and exit
 -version output version information and exit

cd - change directories
     Use cd to change directories. Type cd followed by the name of a directory t
     directory.Keep in mind that you are always in a directory and can navigate
                                  hierarchically above or below.

mv- change the name of a directory
Type mv followed by the current name of a directory and the new name of the d
 Ex: mv testdir newnamedir

pwd - print working directory
   will show you the full path to the directory you are currently in. This is very

 rmdir - Remove an existing directory
 rm -r
Removes directories and files within the directories recursively.

chown - change file owner and group
Usage

chown [OPTION] OWNER[:[GROUP]] FILE
chown [OPTION] :GROUP FILE
chown [OPTION] --reference=RFILE FILE
Options
Change the owner and/or group of each FILE to OWNER and/or GROUP. With --re
 -c, changes like verbose but report only when a change is made
 -dereference affect the referent of each symbolic link, rather than the symbolic
 -h, no-dereference affect each symbolic link instead of any referenced file (usefu
 -from=CURRENT_OWNER:CURRENT_GROUP
  change the owner and/or group of each file only if its current owner and/or gro
-no-preserve-root do not treat `/' specially (the default)
-preserve-root fail to operate recursively on `/'
-reference=RFILE use RFILE's owner and group rather than the specifying OWNE
-R, -recursive operate on files and directories recursively
-v, -verbose output a diagnostic for every file processed
The following options modify how a hierarchy is traversed when the -R option is
-H    if a command line argument is a symbolic link to a directory, traverse it
-L    traverse every symbolic link to a directory encountered
-P    do not traverse any symbolic links (default)

chmod - change file access permissions
Usage

chmod [-r] permissions filenames
     r Change the permission on files that are in the subdirectories of the directo
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.
Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody

ls - Short listing of directory contents
-a      list hidden files
-d      list the name of the current directory
-F      show directories with a trailing '/'
         executable files with a trailing '*'
-g      show group ownership of file in long listing
-i     print the inode number of each file
-l     long listing giving details about files and directories
-R      list all subdirectories encountered
-t     sort by time modified instead of name

cp - Copy files
cp myfile yourfile
  Copy the files "myfile" to the file "yourfile" in the current working directory. Th
cp -i myfile yourfile
With the "-i" option, if the file "yourfile" exists, you will be prompted before it is
cp -i /data/myfile
 Copy the file "/data/myfile" to the current working directory and name it "myfil
cp -dpr srcdir destdir
 Copy all files from the directory "srcdir" to the directory "destdir" preserving lin
ln - Creates a symbolic link to a file.
ln -s test symlink
  Creates a symbolic link named symlink that points to the file test Typing "ls -i

locate - A fast database driven file locator.
slocate -u


more - Allows file contents or piped output to be sent to the screen one page at
less - Opposite of the more command
 cat - Sends file contents to standard output. This is a way to list the contents o
whereis - Report all known instances of a command
wc - Print byte, word, and line counts
bg
     bg jobs Places the current job (or, by using the alternative form, the specifie
cal month year - Prints a calendar for the specified month of the specified year
cat files - Prints the contents of the specified files.
clear - Clears the terminal screen.
   cmp file1 file2 - Compares two files, reporting all discrepancies. Similar to the
   diff file1 file2 - Compares two files, reporting all discrepancies. Similar to the


fg
fg jobs - Brings the current job (or the specified jobs) to the foreground.
file files - Determines and prints a description of the type of each specified file.
find path -name pattern -print
 Searches the specified path for files with names matching the specified pattern
finger users - Prints descriptions of the specified users.
free - Displays the amount of used and free system memory.
ftp hostname


head files - Prints the first several lines of each specified file.
ispell files - Checks the spelling of the contents of the specified files.
kill process_ids
kill - signal process_ids
kill -l
Kills the specified processes, sends the specified processes the specified signal (
killall program
killall - signal program
  Kills all processes that are instances of the specified program or sends the spec


man title
man section title - Prints the specified man page.
 ping host - Sends an echo request via TCP/IP to the specified host. A response
reboot - Reboots the system (requires root privileges).
shutdown minutes
shutdown -r minutes
 Shuts down the system after the specified number of minutes elapses (requires
    sleep time - Causes the command interpreter to pause for the specified numb
   sort files - Sorts the specified files. The command has many useful arguments
    split file - Splits a file into several smaller files. The command has many argu
             sync - Completes all pending input/output operations (requires root pri
telnet host - Opens a login session on the specified host.
 top - Prints a display of system processes that's continually updated until the u


uptime - Prints the system uptime.
w - Prints the current system users.
wall - Prints a message to each user except those who've disabled message rece
                          Description
Sends file contents to standard output. This is a way to list
the contents of short files to the screen. It works well with
piping.
Sends the contents of the ".bashrc" file to the screen.
Change directory
Change the current working directory to /home. The '/'
indicates relative to root, and no matter what directory you
are in when you execute this command, the directory will be
changed to "/home".
Change the current working directory to httpd, relative to the
current location which is "/home". The full path of the new
working directory is "/home/httpd".

Move to the parent directory of the current directory. This
command will make the current working directory "/home.
Move to the user's home directory which is
"/home/username". The '~' indicates the users home
directory.
Copy files
Copy the files "myfile" to the file "yourfile" in the current
working directory. This command will create the file "yourfile"
if it doesn't exist. It will normally overwrite it without
warning if it exists.
With the "-i" option, if the file "yourfile" exists, you will be
prompted before it is overwritten.

Copy the file "/data/myfile" to the current working directory
and name it "myfile". Prompt before overwriting the file.
Copy all files from the directory "srcdir" to the directory
"destdir" preserving links (-p option), file attributes (-p
option), and copy recursively (-r option). With these options,
a directory and all it contents can be copied to another
directory.
Disk duplicate. The man page says this command is to
"Convert and copy a file", but although used by more
advanced users, it can be a very handy command. The "if"
means input file, "of" means output file.
Show the amount of disk space used on each mounted
filesystem.
Similar to the more command, but the user can page up and
down through the file. The example displays the contents of
textfile.
Creates a symbolic link to a file.

Creates a symbolic link named symlink that points to the file
test Typing "ls -i test symlink" will show the two files are
different with different inodes. Typing "ls -l test symlink" will
show that symlink points to the file test.
A fast database driven file locator.
          This command builds the slocate database. It will take
          several minutes to complete this command. This command
          must be used before searching for files, however cron runs
          this command periodically on most systems.
          Lists all files whose names contain the string "whereis".
          Logs the current user off the system.
          List files
          List files in the current working directory except those
          starting with . and only show the file name.
          List all files in the current working directory in long listing
          format showing permissions, ownership, size, and time and
          date stamp
          Allows file contents or piped output to be sent to the screen
          one page at a time.
          Lists the contents of the "/etc/profile" file to the screen one
          page at a time.

          Performs a directory listing of all files and pipes the output of
          the listing through more. If the directory listing is longer than
          a page, it will be listed one page at a time.
          Move or rename files
          Move the file from "myfile" to "yourfile". This effectively
          changes the name of "myfile" to "yourfile".
          Move the file from "myfile" from the directory "/data" to the
          current working directory.
          Show the name of the current working directory
          Lists the contents of the "/etc/profile" file to the screen one
          page at a time.
          Shuts the system down.
          Shuts the system down to halt immediately.

          Shuts the system down immediately and the system reboots.
          Show where the binary, source and manual page files are for
          a command
          Locates binaries and manual pages for the ls command.


wnership of a file

p of file base to the user us and make it recursive (-R)

 ess permissions
d by owner
d by group
d by world

 e by owner
 e by group
 e by world

 ute by owner
 ute by group
 ute by world
 t add the numbers together:
w read permission to owner and group and world
w everyone to read, write, and execute file


 sed to configure a service to be started (or not) in a specific




 ), if they do not already exist.
 ong options are mandatory for short options too.
mission mode (as in chmod), not rwxrwxrwx - umask
 sting, make parent directories as needed
age for each created directory

formation and exit



ectories. Type cd followed by the name of a directory to access that
 d that you are always in a directory and can navigate to directories
         hierarchically above or below.

f a directory
urrent name of a directory and the new name of the directory.



path to the directory you are currently in. This is very handy to use,

ting directory

les within the directories recursively.

ner and group


:[GROUP]] FILE

ce=RFILE FILE

 group of each FILE to OWNER and/or GROUP. With --reference, change
but report only when a change is made
 ferent of each symbolic link, rather than the symbolic link itself
 each symbolic link instead of any referenced file (useful only on systems
 :CURRENT_GROUP
  group of each file only if its current owner and/or group match those
 reat `/' specially (the default)
ate recursively on `/'
LE's owner and group rather than the specifying OWNER:GROUP values
 iles and directories recursively
nostic for every file processed
dify how a hierarchy is traversed when the -R option is also specified. If
 gument is a symbolic link to a directory, traverse it
olic link to a directory encountered
symbolic links (default)

 ess permissions



 ion on files that are in the subdirectories of the directory that you are




 as a program.

 ted by using Numeric Permissions:




ctory contents

 e current directory
  th a trailing '/'
  th a trailing '*'
 ship of file in long listing
mber of each file
  etails about files and directories
 es encountered
 ed instead of name



o the file "yourfile" in the current working directory. This command will

 file "yourfile" exists, you will be prompted before it is overwritten.

 e" to the current working directory and name it "myfile". Prompt before

 ectory "srcdir" to the directory "destdir" preserving links (-poption), file
 ink to a file.

named symlink that points to the file test Typing "ls -i test symlink" will

riven file locator.




s or piped output to be sent to the screen one page at a time
 e command
to standard output. This is a way to list the contents of short files to the
 n instances of a command
  line counts

rent job (or, by using the alternative form, the specified jobs) in the
 calendar for the specified month of the specified year.
nts of the specified files.

res two files, reporting all discrepancies. Similar to the diff command,
es two files, reporting all discrepancies. Similar to the cmp command,




 t job (or the specified jobs) to the foreground.
d prints a description of the type of each specified file.

th for files with names matching the specified pattern (usually enclosed
riptions of the specified users.
nt of used and free system memory.




t several lines of each specified file.
pelling of the contents of the specified files.



es, sends the specified processes the specified signal (given as a number


 e instances of the specified program or sends the specified signal to all




he specified man page.
o request via TCP/IP to the specified host. A response confirms that the
em (requires root privileges).


after the specified number of minutes elapses (requires root privileges).
e command interpreter to pause for the specified number of seconds.
ecified files. The command has many useful arguments; see the online
nto several smaller files. The command has many arguments; see the
s all pending input/output operations (requires root privileges).
 n session on the specified host.
ystem processes that's continually updated until the user presses the q




each user except those who've disabled message reception. Type Ctrl-D

				
DOCUMENT INFO
Shared By:
Stats:
views:39
posted:4/30/2012
language:
pages:12
Description: This is Most frequently used Linux commands for configuring any type of configuration