Working on Linux – Commands / Shortcuts

which command

which – shows the full path of (shell) commands.

How to change Ownership?

Changing the owner of the file:

Changing the owner of the directory:

Changing the group of the file:

Changing the group of the directory:

Changing the owner and group of the directory simultaneously:

How to modify the permissions?

r = read – This is only found in the read field.
w = write – This is only found in the write field.
x = execute – This is only found in the execute field.
s = setuid – This is only found in the execute field.

‘u’ is used to modify the permissions of the user, ‘g’ is for the group and ‘o’ for others. ‘+’ is used to add the permissions and ‘-‘ is used to remove the permissions. ‘r’ denote for read access. ‘w’ denote for write access. ‘x’ denote for execute access.

sets the group ID bit on the file “myfile”.

More examples:

Octal codes:
Permissions may be granted using human readable assignments “rwx” or octal codes.

Description Abreviation Octal code
Read access r 4
Write(change) permission w 2
Execute script of binary executable x 1
Read and Execute rx 5
Read and Write rw 6
Read, Write and Execute rwx 7

Use of octal assignment does not add or remove permission, but assigns the permission explicitly.


Assign yourself full access to read and modify the file, allow members of the group to read it and do not allow any others access:

Assign execute status to a script with the same access as the previous example. (Without it, a script is like any other text file)

Users and Groups

How to add a new user?

This will add the user ‘mukesh’. This command is in the /usr/sbin/ directory.

This will set the password to the user ‘mukesh’. This command is also used to change the password of a user.

How to add the Group of Users?

The above command will add a group ‘developers’.

How to add users to the Group?

To add a new user(not already existing) ’sony’ to group ‘developers’ use following command:

The will command will show which group the user belongs to.

To add existing user ‘mony’ to ‘developers’ group use the following command:

Note: Users and Group entries can be found in the file /etc/passwd and /etc/group.


How to Copy?

Copy files:

Copy directory:

Copy to a remote system:

How to delete?

Deleting files

Deleting directories.

using -r option deletes the directory recursively.

How to make a file or directory?

To make a new file or to edit exiting file vi editor can be used.

This will open the file in vi editor if it already existing otherwise it will open a new file. If it is a new file use Esc and type :wq. This will save your new file. To open it again to edit you can use the above command again.

Make a new Directory.

How to Rename?

How to Run the script file?

Archiving and Unarchiving

Zipping a folder

Zipping files


Note: If the above command is not found, then it means that the package is not installed. Then try the below command:

How to extract gz file?

How to make gz file?

How to extract a tar.gz or .tgz file?


How to switch user?

su command is used to switch as the superuser that is root.
To switch to another user use -l option. e.g

When asked for password provide the respective password. When switching from superuser to a normal user, it will not ask for any password.

View the latest update from the file

How to know which are the processes currently running?

Suppose you want to see all the processes running related to ‘jboss’, you can you the following command:

This will show all the processes related to ‘jboss’ with process ids.

Now, how to kill any process?

You can use the following command if you know the process id (suppose the process id in this case is ‘24623’).

How to see the remaining Disk Space?

How can I find that my linux installation is 32-bit or 64-bit?

User the following command:

The above command will give clear detail about this.

Logout from GUI

How to Set Environment Variables in Linux?

Working with environment variables in linux.

Firewall in Linux

Firewall in linux is managed by the “iptables”.
So, how to start/stop firewall(iptables)?

Locating files.

What if your password is locked?

Suppose there is some policy set that if you give wrong password certain number of times. And suppose after that number of attempts your(login) password is locked. So how to unlock it? You can do this if you know the root password. Login with root and try following command:

Shutdown(halt) and Reboot

Init is the parent of all processes. Its primary role is to create processes from a script stored in the file /etc/inittab

Runlevel: A runlevel is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init for each of these runlevels are defined in the /etc/inittab file. Init can be in one of eight runlevels: 0-6 and S or s. Runlevels 0, 1, and 6 are reserved. Runlevel 0 is used to halt(shutdown) the system, runlevel 6 is used to reboot the system.

will halt the system.

will reboot the system.

How to execute a shell script e.g. /bash_profile/profile?

for example

How to run a shell script in background?

Screen log goes to nohup.out file.

Leave a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Fork me on GitHub