Basic Git commands


Here is a list of some basic Git commands to get you going with Git.

Git task Notes Git commands
Configure the author name and email address to be used with your commits.

Note that Git strips some characters (for example trailing periods) from
git config –global “Name”

git config –global
Create a new local repository
git init
Check out a repository
Create a working copy of a local repository:
git clone /path/to/repository
For a remote server, use:
git clone username@host:/path/to/repository
Add files
Add one or more files to staging (index):
git add <filename>

git add *
Commit changes to head (but not yet to the remote repository):
git commit -m “Commit message”
Commit any files you’ve added with git add, and also commit any files you’ve changed since then:
git commit -a
Send changes to the master branch of your remote repository:
git push origin master
Status List the files you’ve changed and those you still need to add or commit:
git status
Connect to a remote repository
If you haven’t connected your local repository to a remote server, add the server to be able to push to it:
git remote add origin <server>
List all currently configured remote repositories: git remote -v
Create a new branch and switch to it:
git checkout -b <branchname>
Switch from one branch to another:
git checkout <branchname>
List all the branches in your repo, and also tell you what branch you’re currently in:
git branch
Delete the feature branch:
git branch -d <branchname>
Push the branch to your remote repository, so others can use it:
git push origin <branchname>
Push all branches to your remote repository:
git push –all origin
Delete a branch on your remote repository:
git push origin :<branchname>
Update from the remote repository
Fetch and merge changes on the remote server to your working directory:
git pull
To merge a different branch into your active branch:
git merge <branchname>
View all the merge conflicts: View the conflicts against the base file:

Preview changes, before merging:
git diff

git diff –base <filename>

git diff <sourcebranch> <targetbranch>
After you have manually resolved any conflicts, you mark the changed file:
git add <filename>
You can use tagging to mark a significant changeset, such as a release:
git tag 1.0.0 <commitID>
CommitId is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using:
git log
Push all tags to remote repository:
git push –tags origin
Undo local changes
If you mess up, you can replace the changes in your working tree with the last content in head:

Changes already added to the index, as well as new files, will be kept.
git checkout — <filename>
Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
git fetch origin

git reset –hard origin/master
Search the working directory for foo(): git grep “foo()”


is_script_stuck script to kill or notify in cPanel


In some rare cases, a long process may hang indefinitely and be difficult for system administrators to detect. The /bin/is_script_stuck script checks how long a script’s current PID has run, and can notify a WHM user or kill the process.

For example, if you experience problems with hung backup processes, you could use this script in a cron job to monitor backup processes.

Run the /bin/is_script_stuck script

To run the /bin/is_script_stuck script on the command line, use the following format:

/bin/is_script_stuck [options]

You can use the following options with this script:

--script The absolute path to the script that you wish to check.

Note:This option is required, unless you instead use the --help option.

--time The amount of time that the specified script can run before the /bin/is_script_stuck script determines that it is stuck.

You can append one of the following units of measure:

  • d — Days.
  • h — Hours.
  • m — Minutes.
  • s — Seconds.

If you do not append a unit of measure, the script treats this value as a number of seconds. For example, specify --time=60 for 60 seconds, or --time=4d for four days.

Note:This option is required, unless you instead use the --help option.

--notify The WHM username to which you wish to send a notification of the script’s results. --notify=root
--kill Use this option if you want the script to stop (kill) the specified script if it runs longer than the specified time. --kill
--help Print help information for the /bin/is_script_stuck script. --help

Reserved blocks in linux


Reserved blocks in linux

Reserved blocks are disk blocks reserved by the kernel for processes owned by privileged users to prevent operating system from a crash due to unavailability of storage space for critical processes. The default percentage of reserved block is 5 % of the total size of file system and can be increased or decreased based upon the requirement.

Example : We have 40GB in root and the situation reached 100%, all the non-privileged users processes wouldn’t able to login or write (because it’s running under nobody’) and the privileged user (root) has reserved block of 5% which will able to troubleshoot the disk space issue.

Using tune2fs command we can check the information.

root@:~# tune2fs -l /dev/md9 | grep Reserved

tune2fs 1.42.5 (29-Jul-2012)

Reserved block count:     0

Reserved blocks uid:      0 (user root)

Reserved blocks gid:      0 (group root)


root@~# dumpe2fs /dev/md9

The uid and gid confirm the Unix userid and Unix groupid of the user who will be allowed to tap into the reserved space.

Default block size of file system

root@linux:~# tune2fs -l /dev/sda2 | grep Block

Block count:              241966592

Block size:               4096

Blocks per group:         32768

To incerease or decrease the block size use the below command.

# tune2fs -m 0 /dev/md9

Understanding about superblock and how to recover it from a corrupted partition.


Understanding about superblock and how to recover it from a corrupted partition.

what is superblock?

Superblock is the metadata of the file system, it stores following information

  • Blocks
  • Number of free blocks
  • Inodes per block group
  • Blocks per block group
  • Number of times the file system was mounted since last fsck.
  • Mount time
  • UUID of the file system
  • Write time
  • File System State
  • The file system type
  • The operating system in which the file system was formatted

In linux it usually maintains multiple superblock copies for better redundancy to avoid data loss. From this superblock we can recover data without any loss. Below output will show how to check superblock in a partition, using this superblock we can recover.

root@linux:~# dumpe2fs  /dev/sda2 | grep superblock

  • dumpe2fs 1.42.9 (4-Feb-2014)
  •   Primary superblock at 0, Group descriptors at 1-58
  •   Backup superblock at 32768, Group descriptors at 32769-32826
  •   Backup superblock at 98304, Group descriptors at 98305-98362
  •   Backup superblock at 163840, Group descriptors at 163841-163898
  •   Backup superblock at 229376, Group descriptors at 229377-229434
  •   Backup superblock at 294912, Group descriptors at 294913-294970
  •   Backup superblock at 819200, Group descriptors at 819201-819258
  •   Backup superblock at 884736, Group descriptors at 884737-884794
  •   Backup superblock at 1605632, Group descriptors at 1605633-1605690
  •   Backup superblock at 2654208, Group descriptors at 2654209-2654266

  Here below command will recover the corrupted partition using superblock.

# fsck -b 32768 /dev/sda2

After that mount the partition and create a file.

Top output explained

Value Meaning
us user cpu time (or) % CPU time spent in user space
sy system cpu time (or) % CPU time spent in kernel space
ni user nice cpu time (or) % CPU time spent on low priority processes
id idle cpu time (or) % CPU time spent idle
wa io wait cpu time (or) % CPU time spent in wait (on disk)
hi hardware irq (or) % CPU time spent servicing/handling hardware interrupts
si software irq (or) % CPU time spent servicing/handling software interrupts
st steal time – – % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine


Fields Description
PID Process Id
USER The effective user name of the task’s owner
PR The priority of the task
NI The nice value of the task.  A negative nice value means higher priority, whereas a positive nice value means lower priority.  Zero in this field simply means priority will not be adjusted in determining a task’s dispatchability
%CPU The task’s share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
%MEM A task’s currently used share of available physical memory
TIME+ Total CPU time the task has used since it started
S The status of the task which can be one of:

‘D’ = uninterruptible sleep

‘R’ = running

‘S’ = sleeping

‘T’ = traced or stopped

‘Z’ = zombie

RES The non-swapped physical memory a task has used
SHR The amount of shared memory used by a task
Command Display the command line used to start a task or the name of the associated program

VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card’s RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.

RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.

SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.