Monday, 1 February 2016

Linux Basic Commands (Part-1)
Guys! I am going to start basic Linux How Tos. I would like to start these How Tos from basic linux commands reference guide, just a brief description of each command not much detail. The purpose of these How Tos is to get introduce the linux i.e Red Hat, CentOS and Fedora etc. to IT professionals who use these day to day and sometimes slips out of mind. This brief guide will help those get reference of those commands.
Directory listing
To list the directory contents and information about files (current directory by default) in linux you use command ls with many switches defined below.
1.  ls –l (use a long listing format)
2.  ls –h (human readable – print the size in human readable format i.e 1k, 234MB, 2G etc).
3.  ls –a (shows all - do not hide entries starting with)
4.  ls –r (shows reverse order while sorting 
5.  ls –t (sort files by modification time)
 
Note: ls commands have many more switches but most commonly used are mentioned here.

Disk usage
The du (Disk usage) is command used to check the information of disk usage of directories and files. The du command has also many parameters which can be used to get result in different formats. Most common are mentioned below;
1.  du /home/userdirectory (shows the disk usage summary of a user’s directory tree and each of its sub directories.
2.  du –h /home/userdirecotry (shows the size in human readable format)
3.  du –sh /home/userdirectory (shows the total disk usage size of a parituclar directory.
4.  du –a /home/userdirectory (shows the disk usage of all files and directories)

Mounting / un-mounting directories
The mount is used to check that currently mounted partitions on your machine;
1.  mount (currently mounted partitions on the machine)
2.  mount /dev/cdrom /mnt/cdrom (will mount the cdrom in mount point i.e /mnt/cdrom)
3.  mount –t nfs 192.168.1.1:/usr/directoryname /mnt/cdrom (will mount a NFS Share i.e /usr/directoryname from machine 192.168.1.1 to your local mount point /mnt/cdrom
4.  cat /etc/mtab (shows the mounted file system table)
5.  unmount /mn/cdrom(this command will unmount the particular device or directory)

File copying / moving / renaming / deletion / compression and decompression
Following commands will be used while we need to copy, move, rename, delete compress or decompress the files.
1.  cp –vr /home/userdirectory/* /mnt/dir1 (copies all files including subdirectories form /home/userdirectory to /mnt/dir1)
2.  mv /home/userdirectory/* /mnt/dir1 (copies all files including subdirectories form /home/userdirectory to /mnt/dir1)
3.  rm –fr /mnt/dir1/* (forcefully deletes all files including subdirectories in /mnt/dir1)
4.  tar –cvf /tmp/mytar.tar * (creates tar file in /tmp/mytar from the files in current directory)
5.  tar –xvf /tmp/mytar.tar (untar the file /tmp/mytar.tar in current directory.
Disk Checking and Formatting
Fdisk is text based utility used in linux distributions for the management of disk partitions. Using fdisk you can create new partitions, delete or change existing partitions on machine. You can create maximum 4 primary partitions and any number of logical partitions depending upon disk size. Following are the fdisk commands used;
1.  fdisk –l (used to view all available partitions on machine)
2.  fdisk –l /dev/sda (will show specific hard drive i.e sda)
3.  fdisk –s /dev/sda (will show the size of the partition i.e sda)
4.  e2fsck /dev/sda (perform disk check)

5.  e2fsck –p /dev/sda (perform disk check and automatically repair)

Part 2

No comments:

Post a Comment