Saturday, May 09, 2009

0003 SOME BASIC COMMANDS OF REDHAT LINUX

Linux have large command pool. Still here are some linux command useful for beginners with small description. Being this is written for beigners he command listed here may have some more uses than explained in this post, for more information you can get the help of relative commands using man or info commands.
  1. TO CLEAR THE SCREEN

    #clear

  2. TO CHECK DIRECTORY LISTINGS OR CONTENTS OF DIRECTORY.
    #ls
    bin boot dev etc home lib lost+found media mnt opt proc root sbin selinux srv sys tmp usr var

    To check long (detailed) directory listings
    #ls -l
    total 112

    drwxr-xr-x 2 root root 4096 2009-05-04 09:26 bin
    drwxr-xr-x 5 root root 4096 2009-04-15 11:46 boot
    drwxr-xr-x 14 root root 4880 2009-05-09 19:49 dev
    drwxr-xr-x 131 root root 12288 2009-05-09 21:10 etc

  3. CREATIN NEW EMPTY FILE.
    #touch FILE_NAME

    e.g.
    #touch my_file.txt

    Above command will create a new empty file called "my_file.txt" if it does not exist. If it exists already it will just change the time stamp of the existing file.

  4. CREATING A NEW FILE WITH SOME CONTENT

    #cat > FILE_NAME

    e.g.
    #cat > my_file.txt

    after firing the command you have to enter the data in the file. After finishing entering the data in the file you have to press d to save the contents of the file.

  5. READING THE CONTENT OF EXISTING FILE

    #cat FILE_NAME

    e.g.

    #cat my_fiel.txt

    After firing this command, contents of the "my_file.txt" will be displayed and controlls will be returned to command prompt. If the contets of the file is too long to read on single screen then you can use command as follws.

    #cat my_file.txt | less
    or
    #less my_file.txt

    After firing the above command you can scrolle the output using up/down arrow keys. After finishing reading the file to quit you can press "q" to quit.

  6. CREATING NEW DIRECTORY.

    To create the new directory the command is

    #mkdir NEW_DIR_NAME

    e.g. say you need to create a directory named "data"

    #mkdir data

    To print a message for each created directory
    # mkdir -v data


    To create a new directory with user dedined permissions
    # mkdir -m=MODE
    e.g.
    To create a directory say "videos" with user defined permissions "777"
    #mkdir -m=777 videos

  7. CHANGING THE DIRECTORY

    #cd DIR_NAME

    e.g.
    To enter in the directory say "videos"
    #cd videos

    To exit from the directory i.e. to enter in parent directory
    #cd ..

    To switch to home directory immediately
    #cd ~

    To switch to previous directory immediately
    #cd -

  8. DELETING OR REMOVING EXISTING FILE OR DIRECTORY.

    To remove/delete the existing file

    #rm FILE_NAME

    e.g. to remove a existing file say "my_file.txt"
    #rm my_file.txt

    To remove/delete existing directory
    #rm -rf
    e.g. say you want to remove a existing directory "videos"
    #rm -rf videos

  9. COPING CONTENTS OF EXISTING FILE/DIRECTORY IN NEW FILE/DIRECTORY.

    To copy contents of file "file1" to file "file2"
    #cp file1 file2

    To copy all the contents of directory "videos" to directory "vsongs"
    #cp -Rv videos vsongs


  10. RENAMING A FILE/DIRECTORY.

    To change the name of the file "file1" to new name "file1"
    #rename file file1

    to change th name of the directory "videos" to "video_song"
    #mv video video_song


  11. CHANGING THE PERMISSIONS OF FILE/DIRECTORY
    #chmod MODE FILE_NAME

    e.g. To change the permissions of the file "my_file.txt" to 777
    #chmod 777 mt_file.txt

    To change permission of a directory named "video" with its all subdirectories and files to new permissions say 446
    #chmod -R 446 video

  12. CHANGING THE USER OWNERSHIP OF THE FILE/DIRECTORY.

    #chown NEW_OWNER FILE_NAME


    e.g. To change owner of a file named "my_file.txt" to new owner (user) say "denis"
    #chown dnis my_file.txt

    e.g. To change owner of a directory named "video" to new owner (user) say "denis"
    #chown dnis video

    e.g. To change owner of a directory named "video" with its all subdirectories and files to new owner (user) say "denis"
    #chown -R dnis video


  13. CHANGING THE GROUP OWNERSHIP OF THE FILE/DIRECTORY.

    #chgrp NEW_GROUP FILE_NAME

    e.g. To change group group of a file named "my_file.txt" to new group say "denis"
    # chgrp dnis my_file.txt

    e.g. To change group of a directory named "video" to new group say "denis"
    #chgrp dnis video

    e.g. To change group of a directory named "video" with its all subdirectories and files to new group say "denis"
    #chgrp -R dnis video

  14. CHECKING FILE SYSTEMS DISK USES
    # df -h


  15. GETTING REPORT OF DISK USES.
    #du -h


  16. GETTING CURRENT WORKING DIRECTORY.
    #pwd

  17. CREATING A SYMBOLIC LINK
    To creates a symbolic link named symlink that points to the file test

    #ln -s FILE_NAME SYMBOLIC_LINK_NAME

    e.g
    #ln -s test symlink

    Typing "ls -i test symlink" will show the two files are different with different inodes. Typing "ls -l test symlink" will show that.

  18. GETTING WHICH USEERS ARE LOGGED IN.
    #who

  19. LOCATING BINARIES AND MANUAL PAGES FOR COMMANDS

    To locate binaries and manual pages for the "ls" command.

    #locate ls

  20. SHUTTING DOWN THE COMPUTER

    To shuts the system down to halt immediately.
    #shutdown -h now

    To shut the system down immediately and the system reboots.
    #shutdown -r now

    To reboot the system in 10 minutes and send the message to all users.
    #shutdown -r +10 "Rebooting in 10 minutes"

    To shut the system down and do a reboot at 1:00 in the afternoon.
    #shutdown -r 13:00

  21. LOGGING OUT FROM THE TERMINAL

    #logout

    or press CTRL+D

  22. CHECKING/SETTING DATE AND TIME

    To check date and time of the system
    #date

    list the time and date in the below format:

    DATE: 02/08/01
    TIME:16:44:55

    #date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'

    To sate date and time of the systm
    #date -s "11/20/2003 12:48:00"

  23. SETTING ALIASES

    Alias allows you to have a small more familiar command or name to execute a long string of commans.

    #alias ALIAS_NAME 'LONG_COMMAND'

    e.g. The follofing command will create a alias named "shutt" to command "shutdown -r now".

    #alias shutt 'shutdown -r now'

  24. TO DISPLAY THE ARCHITECTURE OF THE PROCESSOR

    #arch

  25. CHECKING CALENDER ON COMMAND LINE

    To check calendar for the current month and the year.
    #cal

    To check calendar for the specific month and the year say December of 2000.
    #cal 12 2000

    To display prev/current/next month calender.
    #cal -3

    To display a calendar for the current year.
    #cal -y

  26. DNS LOOKUP

    To get IP of the hostname
    #dig www.gooogle.com

    To get hostname of the IP addresses
    #dig -x 192.168.1.1

No comments: